Fix MOTD IP detection to use default route
Use `ip route get 1` to query the kernel for the source IP of the default route instead of `hostname -i`, which returns 127.0.0.1 when /etc/hosts isn't configured for the hostname. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -116,7 +116,7 @@ show_motd() {
|
|||||||
echo "${DF_GREY}╒${hline}╕${DF_NC}"
|
echo "${DF_GREY}╒${hline}╕${DF_NC}"
|
||||||
|
|
||||||
local h_left="✦ ${username}@${hostname} "
|
local h_left="✦ ${username}@${hostname} "
|
||||||
local h_center=$(hostname -i 2>/dev/null | awk -F" " '{print $1}')
|
local h_center=$(ip route get 1 2>/dev/null | awk '{print $7; exit}' || hostname -i 2>/dev/null | awk '{print $1}')
|
||||||
local h_right="${datetime}"
|
local h_right="${datetime}"
|
||||||
local h_pad=$(((inner - ${#h_left} - ${#h_center} - ${#h_right}) / 2))
|
local h_pad=$(((inner - ${#h_left} - ${#h_center} - ${#h_right}) / 2))
|
||||||
local h_spaces=""
|
local h_spaces=""
|
||||||
|
|||||||
Reference in New Issue
Block a user