How to display ip on a remove vm before login

Source: taken from (http://offbytwo.com/2008/05/09/show-ip-address-of-vm-as-console-pre-login-message.html)

TL;DR Install with one the following lines (choose either slurdge.org, github.com or gitlab.com) as root. Feel free to checkout the source.

wget https://gitlab.com/snippets/1660984/raw -O - | sh
wget https://gist.githubusercontent.com/slurdge/1fe64837f751101015137c7d2b93ff77/raw/install_ip_prompt.sh -O - | sh
wget https://www.slurdge.org/assets/2017/05/install-ip-prompt.sh -O - | sh

This is mainly useful when you boot up a WM with a remote console and want to switch to ssh for connection.

First, create a script in /usr/local/bin/get-ip-address with the following contents:

/sbin/ifconfig | grep "inet addr" | grep -v "127.0.0.1" | awk '{ print $2 }' | awk -F: '{ print $2 }'

Then add the following script to /etc/network/if-up.d/show-ip-address with the following contents:

#!/bin/sh
if [ "$METHOD" = loopback ]; then
    exit 0
fi

# Only run from ifup.
if [ "$MODE" != start ]; then
    exit 0
fi

cp /etc/issue-standard /etc/issue
echo "IP Address: " >> /etc/issue
/usr/local/bin/get-ip-address >> /etc/issue
echo "" >> /etc/issue

You need to copy your standard issue to a copy and fix rights:

sudo cp /etc/issue /etc/issue-standard
sudo chmod +x /usr/local/bin/get-ip-address
sudo chmod +x /etc/network/if-up.d/show-ip-address

it will give you a simple prompt like this one:

Example of IP display

That’s all folks!