Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I work with a lot of virtual machines. For testing and preproduction set up.

I would like the login promt or header to display the ip address of the machine. That way when I start it up I can see what IP I will be ssh into. Our network works uses a DHCP. So it can change between boot up.

$ cat /etc/issue
Ubuntu 11.04 \n \l

Which comes up as

Ubuntu 11.04 [hostname] tty[x]

I want it to come up as

Ubuntu 11.04 [hostname] tty[x] ip

I was think about writing an init / upstart script. Is there a better way.

share|improve this question
up vote 3 down vote accepted

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 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/ is used for remote logins so you may want to edit that as well.

share|improve this answer
Why would someone need to look at the IP address of a remote system after having connected to that system? (that's on the question of modifying the /etc/ – Alexander Shcheblikin Mar 7 '14 at 21:06
If you have one hundred servers, and your .ssh/config is configured to distinguish them by hostname, I believe it would be handy to know it's IP address for administration purposes. It's just one of the use cases.. – Andrejs Cainikovs Mar 10 '14 at 8:20
The IP address can be just looked up with host. However, I'd agree that some complex NAT configurations might make a simple lookup not that useful. – Alexander Shcheblikin Mar 10 '14 at 12:05

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

$ cat /etc/dhcp/dhclient.d/

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() {

issue_restore() {

with an issue "template" like this:

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


Remember to chmod +x cat /etc/dhcp/dhclient.d/

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.