Skip to content

Reach a Local Host by Name over SSH

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.

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.

Terminal window
ip -brief -4 addr

Example output:

Terminal window
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.

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.

Terminal window
hostname

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

Terminal window
ssh your-user@hostname.local

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

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

Terminal window
systemctl status avahi-daemon

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

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

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.

Terminal window
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.

Terminal window
ssh your-user@192.168.1.42