Ssh – How to make the linux machine broadcast its IP address dynamically

dhcpipnetworkingssh

My linux desktop machine is running Kubuntu 16.04 Desktop LTS (Debian based linux); running a the KDE Plasma Desktop. To connect to the LAN I've simply configured the WiFi GUI (cable is not an option due to building), pointed it to the router and filled the password. Works just fine without problems.

However, the IP address allocated to my machine is handed via the DHCP server running on the router. Currently it's 192.168.0.34 but from day to day it changes depending on if I've switched off my machine, the router gets power cycled etc.

There are some options in the router under 'DHCP Reservation' which allows me to reserve a fixed IP address based on the MAC address of my WiFi card.

I have a MacBook and I like to SSH to the Linux machine so I can work anywhere in the house and garden. Usually I alter the /etc/hosts file on the MacBook and make an association mylinuxbox 192.168.0.34.

Without using DHCP Reservation, I would have to continuously change the /etc/hosts file to match the current DHCP Allocated IP Address.

Is there a way for the Linux machine to broadcast its IP address on the LAN?

If so, how is this done and is this a secure and acceptable practice?

Would fixing the IP on the router using DHCP Reservation be a better solution?

Best Answer

You can try to install Avahi, which is the Linux implementation of Zeroconf (known as Bonjour in Apple Mac/iOS environments), and set it to advertise your host as <hostname>.local.

All it takes is to install the following packages:

sudo apt-get install avahi-daemon avahi-dnsconfd avahi-discover avahi-utils libnss-mdns

You can find more details at https://askubuntu.com/questions/460371/trouble-using-ssh-and-avahi

Related Question