Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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've got a couple of linux virtual machines with bridged interfaces, and I'd like the IP address of the machine to show up after the machine boot (in the login, where it usually shows the release and kernel).

From what I can tell the message is picked up from /etc/issues, but I'm not sure how and when to write to it.

share|improve this question
up vote 10 down vote accepted

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).

share|improve this answer
Slightly more Linuxy to say ip address show eth0 | awk '/inet / {print $2}' | cut -d/ -f1 – Sorpigal Dec 6 '10 at 18:01
I'm not sure how that's more linuxy, but yes, that works too. – larsks Dec 7 '10 at 16:33
@larks: It's more linuxy because on linux ip is the tool you're supposed to use for this sort of thing. ifconfig is technically just for compatibility. – Sorpigal Dec 17 '10 at 18:03

This script will add/remove IP addresses to/from the /etc/issue file as needed:

PREFIX="Local IP addresses:"
IPADDRS=$(hostname -I | tr " " "\n" | grep -v "^$" | sort -t . -k 1,1n -k 2,2n -k 3,3n -k 4,4n | tr "\n" " ")

perl -i -p -0777 -e "s/^$PREFIX[^\n]*\n\n//m; s/$/\n$PREFIX $IPADDRS\n/ if length('$IPADDRS')>6" /etc/issue

If you're using a Debian-based distro, it's best to place the script at these locations:


This way the scripts are executed everytime an interface comes up or goes down. Placing it in /etc/rc.d/rc.local has the disadvantage of beeing executed only one time during bootup.

share|improve this answer
For anyone searching, in Red Hat/CentOS/etc this script would be /sbin/if{up,down}-local. (If it exists, it's called by /etc/sysconfig/network-scripts/ip{up,down}-post.) – Aaron Copley Mar 18 '15 at 15:15
@powpow: Why "Local IP addresses"? --all-ip-addresses outputs also "public" IP addresses. Maybe something like "IP addresses of all external interfaces of this host:" makes more sense. – ypid Nov 11 '15 at 22:07

you can write it once. unfortunately there's no getty escape sequence to show the ip address of eth0 but there's an escape sequence you can use in /etc/issue to show the hostname: \n

you can always statically set the ip of the machine in /etc/issue by writing it directly into the file. beware that the file /etc/ is used for remote logins so you may want to edit that as well.

anyway, after working in the terminal window you will loose the initial screen and the ip/host address information with it. best way is to set the hostname in the prompt (most linux distros do) using \h or \H or again, statically setting the ip address you know is set on the host in the PS1 variable you can set PS1 variable in /etc/profile on most linux distros.

share|improve this answer
This is just to know what IP to connect to after booting the vm, so setting it up as larsks says is enough :) – Bruno Lopes Dec 6 '10 at 15:56

Many thanks to @larsks for getting started. I found that I had trouble with the script completing before it was needed so my issue file was always blank. So I added a 1 second pause and looped. I'm not really a bash scripter, so if there is a better way to do this please let me know. I added a COUNT to make sure it didn't loop forever.



while [ $COUNT -lt 10 ]
  echo $COUNT

  COUNT=$((COUNT + 1))
  IP=`ifconfig eth0 | awk '/inet addr/ {print $2}' | cut -f2 -d: `
  if [ -n "$IP" ]; then
  sleep 1

echo "IP: " $IP | cat > /etc/issue

I placed this script in /etc/network/if-up.d/.

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.