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 addrExample output:
lo UNKNOWN 127.0.0.1/8
enp3s0 UP 192.168.1.42/24
wlan0 UP 192.168.1.57/24Read 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.
hostnameThen from the connecting device, append .local to that name.
ssh your-user@hostname.localThis 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-daemonIf 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-daemonPin 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 enp3s0Then 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.
ssh your-user@192.168.1.42