When managing multiple Linux VMs with bridged networking, seeing the IP address directly in the login prompt can save valuable troubleshooting time. The standard /etc/issue file typically shows only static system information, but we can make it dynamic.
This file contains system identification text displayed before login. It supports escape sequences (\n, \d) but more importantly, can execute commands through backticks or $(command) syntax.
Edit /etc/issue with root privileges:
sudo nano /etc/issue
Add this template (for Debian/Ubuntu systems):
Welcome to \n \l
eth0 IP: $(ip -4 addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}')
Kernel \r on \m (\s)
For systems using NetworkManager, create a cron job or systemd service to update the file periodically:
#!/bin/bash
echo "eth0 IP: $(hostname -I | awk '{print $1}')" > /tmp/ip.tmp
cat /etc/issue.base /tmp/ip.tmp > /etc/issue
To survive reboots, add this to /etc/rc.local (before exit 0):
ip addr show eth0 | grep inet | awk '{ print $2 }' | cut -d/ -f1 > /etc/issue.ip
cat /etc/issue.template /etc/issue.ip > /etc/issue
- Test with
agetty --show-issuebefore rebooting - Ensure network is up before displaying IP (consider
network-online.target) - For multiple interfaces, modify the grep pattern:
grep -w "inet"
When administering Linux servers (particularly VMs), seeing the current IP address directly in the login banner can save significant troubleshooting time. The standard /etc/issue displays static system information, but we need dynamic IP injection.
The login banner text is generated from /etc/issue and processed through agetty. Special escape sequences like \n and \d are expanded during display. We'll leverage this with command substitution.
Edit /etc/issue with dynamic content using ifconfig or ip commands:
\S
Kernel \r on an \m
eth0 IP: $(ip -4 -br addr show eth0 | awk '{print $3}' | cut -d'/' -f1)
For systems using NetworkManager, consider this more robust version:
#!/bin/sh
if [ -f /etc/issue.dynamic ]; then
rm /etc/issue.dynamic
fi
{
echo "\S"
echo "Kernel \r on \m"
echo ""
ip -br -4 addr show eth0 | awk '{print "Network: "$3}'
} >> /etc/issue.dynamic
cp /etc/issue.dynamic /etc/issue
Create a service to update the file on network changes:
# /etc/systemd/system/update-issue.service [Unit] Description=Update /etc/issue with IP information After=network.target [Service] Type=oneshot ExecStart=/usr/local/bin/update-issue.sh # /etc/systemd/system/update-issue.path [Path] PathChanged=/run/systemd/netif/leases/ [Install] WantedBy=multi-user.target
- Test with
agetty --show-issue - Ensure scripts have execute permissions
- Verify network interface name matches your system (
ip link show) - Check for SELinux/AppArmor restrictions on
/etc/issuemodifications