21 Feb 2015

Linux, display local IP before login prompt

I might need to ship one of my applications to a customer as a VM. This application is a web app, so in order to use the application they’ll need to run the VM and just point their browser to the VM IP address.

I’d like to show the local IP address without login in the VM first.

It turns out that the file I’m looking for is /etc/issue (there’s another one for remote logins called /etc/issue.net, but I don’t think I need this).

Whatever you put in this file, it will be displayed before the login prompt.

Now we just need to update this file every time the system starts. For that I added this code to /etc/rc.local:

    #!/bin/sh -e

    IP=$(hostname -I)
    echo "Hey, navigate to http://$IP to use my awesome app!" > /etc/issue