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:
Aaron D. Lee
2026-01-24 00:35:56 -05:00
parent 48784c97fe
commit 3f05afdc67

View File

@@ -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=""