Ctrl K

Reach a Local Host by Name over SSH

Stop chasing a changing DHCP IP: reach a Linux host on the local network by a stable .local mDNS name or a DHCP reservation, and pick the right interface.

A LAN IP handed out by DHCP can change on the next lease, so an SSH target that worked yesterday may point nowhere today. Instead of looking the address up every time, connect by a stable name. This note covers picking the right interface, connecting by the .local mDNS name, and pinning the IP with a router DHCP reservation. To find the current IP in the first place, see the linked note below.

Pick the right interface

When a host has both Wi-Fi and Ethernet, confirm which interface is on the network you connect over. The brief view is the quickest read.

ip -brief -4 addr

Example output:

lo               UNKNOWN        127.0.0.1/8
enp3s0           UP             192.168.1.42/24
wlan0            UP             192.168.1.57/24

Read the lines:

  • lo is loopback, never the SSH target.
  • en* / eth* is wired Ethernet, wl* / wlan* is Wi-Fi.
  • UP means the interface is active. Pick the one that is UP on the network you connect over.

Connect by the .local name

An mDNS name resolves on the LAN without any router or DNS setup and survives IP changes, so it is the simplest stable target. Check the hostname on the target host.

hostname

Then from the connecting device, append .local to that name.

This resolves through Avahi over mDNS. The IP behind the name can change and the command still works.

Confirm mDNS is running

The .local name only resolves if the Avahi daemon is running on the target host.

systemctl status avahi-daemon

If it is not installed, install and enable it, or use the DHCP reservation route below instead.

# Debian / Ubuntu
sudo apt install avahi-daemon
sudo systemctl enable --now avahi-daemon

Pin the IP with a DHCP reservation

A DHCP reservation binds the host MAC address to a fixed IP on the router, so the same machine always gets the same lease. This works without mDNS and keeps a plain IP target stable. Find the MAC of the active interface on the target host.

ip -brief link show enp3s0

Then in the router admin page, add a reservation mapping that MAC to the IP you want. After that, the IP is stable and can go straight into an SSH host alias.

See also