Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have had a couple of occasions where I was unable to remember the IP address for a given system but was, at the time, able to connect using the hostname. As an example, just now I wanted to set up port forwarding on my router and couldn't remember the IP for the target system.

I am wondering if it is possible to add the system's IP address to the welcome message that gets displayed on an SSH connection.

The default welcome message that I am trying to modify, in case that term is ambiguous, is"

Linux [hostname] 2.6.35-32-generic #64-Ubuntu SMP Tue Jan 3 00:47:07 UTC 2012 x86_64 GNU/Linux

Ubuntu 10.10

Welcome to Ubuntu!
    * Documentation:  https://help.ubuntu.com/

Somewhere in there I think I'd like to add the IP address of the system I just logged in to. Any suggestions? Other than trading in my brain for a newer model with more RAM?

share|improve this question
add comment

1 Answer 1

up vote 21 down vote accepted

The message you refer to is the "motd", or "Message of the Day". It's contained in /etc/motd.

This is generated by update-motd, documentation for which is here:

https://wiki.ubuntu.com/UpdateMotd#Design

See this related question:

How do I edit the ssh motd?

To directly answer your question, you could add a file called /etc/update-motd.d/50-ip-address with this content:

#!/bin/bash
ifconfig |grep "inet addr"

This will very simplistically add all the configured internet addresses on your system to the motd file.

The motd is updated "at each login" (as per man update-motd). You can play with the number as the first part of the script's name to decide the order in which the IP address will appear.

As the files in /etc/update-motd.d are simply shell scripts, you can write something as simple or as complicated as you want.

share|improve this answer
    
It won't let me vote you up yet, but your answer looks like it should do what I was hoping. I'll try it out tomorrow. Cheers! –  miststlkr Jan 31 '12 at 6:05
    
Tested and confirmed. Brilliant! That gave far more info than I need but, as you said, it is a bash script so I'll have plenty to tinker with now to get it exactly where I want it. That is, after all, half of the fun of running linux! –  miststlkr Feb 1 '12 at 0:47
add comment

Your Answer

 
discard

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.