Monday, April 29, 2024
 Popular · Latest · Hot · Upcoming
66
rated 0 times [  66] [ 0]  / answers: 1 / hits: 113689  / 2 Years ago, fri, december 10, 2021, 10:35:40

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?


More From » ssh

 Answers
5

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.


[#40655] Friday, December 10, 2021, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
egantfis

Total Points: 406
Total Questions: 108
Total Answers: 108

Location: Austria
Member since Thu, Jan 7, 2021
3 Years ago
;