modify login prompt or header (/etc/issue) to display ip address of the machine

On CentOS 7 and Debian 8 (and maybe other as well), just append the following line to /etc/issue

My IP address: \4

and that will resolve to the machine's IPv4 address. If you have multiple network interfaces and you want to pick one specific, you can specify it with

My IP address: \4{eth0}

For CentOS 5 with a DHCP leased IP, you can use this script:

$ cat /etc/dhcp/dhclient.d/issue.sh
#!/bin/bash

update_issue() {
    awk -v \
        r="$(ip -o addr | awk '/inet [1-9]+/ { print $2 " " $4 }')" \
        '{ gsub(/%INTERFACES%/,r) }1' \
        /etc/issue.template > /etc/issue
}

issue_config() {
    update_issue
}

issue_restore() {
    update_issue
}

with an issue "template" like this:

$ cat /etc/issue.template
CentOS release 6.5 (Final)
Kernel \r on an \m

%INTERFACES%

Remember to

chmod +x /etc/dhcp/dhclient.d/issue.sh

The awk command to get the current IP and replace them in the /etc/issue.template file should be portable to modern Linux distros.


Getty does not know machine's ip addresses. But this question was already asked at serverfault. Here's the accepted answer:

It's just a text file...you write to it the same way you'd send text to a file with any other shell script. Something like this would replace /etc/issue with just your ip address:

ifconfig eth0 | awk '/inet addr/ {print $2}' | cut -f2 -d: > /etc/issue

Obviously you can make this arbitrarily more complex, depending on what information you want in your /etc/issue file.

You can write to this file in your local equivalent of /etc/rc.d/rc.local (which typically executes after all the other startup scripts).

Also, beware that the file /etc/issue.net is used for remote logins so you may want to edit that as well.

Tags:

Linux

Ip

Prompt