## Setting up .local names on your LAN ## 1. Prerequisites / network side For mDNS to work you need: 1. **All machines on the same L2 segment** — you said it's one /24, so you're fine. (mDNS does not cross routers; if you ever split the network into VLANs you'll need a reflector.) 2. **Multicast allowed**: - Switch: enable **IGMP snooping** so `224.0.0.251` (mDNS group) reaches all ports in the VLAN. - Router: make sure it isn't filtering **UDP 5353** or the group **224.0.0.251** on the LAN interface. Most home routers don't; managed switches with "multicast filtering" / "IGMP snooping in proxy mode" can — double-check. 3. **Each machine has a static IP** in the /24 (or DHCP reservation) so the name → IP mapping stays stable. This is strongly recommended for `.local` to be reliable. 4. **No firewall blocking UDP 5353 inbound** on the machines you want discoverable. ## 2. Pick a name for each machine Rules: lowercase, no spaces, 1–63 chars, no leading/trailing hyphen, unique on the LAN. Example set: | Role | Hostname | Static IP | |---|---|---| | Workstation A | `box-a` | 192.168.178.10 | | Workstation B | `box-b` | 192.168.178.11 | | NAS | `nas` | 192.168.178.20 | | Server / build | `build` | 192.168.178.30 | ## 3. Per-machine configuration (any distro) ### a) Set the hostname ```bash # pick one name, e.g. box-a sudo hostnamectl set-hostname box-a # verify hostname ``` (On distros without `hostnamectl`: edit `/etc/hostname` and reboot.) ### b) Install the mDNS responder (Avahi) and name resolution glue ```bash # Debian / Ubuntu sudo apt update sudo apt install -y avahi-daemon avahi-discover avahi-utils nss-mdns # Fedora / RHEL sudo dnf install -y avahi avahi-tools # Arch sudo pacman -S avahi ``` `nss-mdns` is the part that makes `getent hosts box-a.local`, `ping box-a.local`, `ssh box-a.local`, `curl http://box-a.local` all "just work" without any DNS configuration. ### c) Enable the services ```bash sudo systemctl enable --now avahi-daemon # On systemd distros also make sure systemd-resolved is running (it is by default): systemctl status systemd-resolved sudo systemctl enable --now systemd-resolved ``` ### d) Make sure the local resolver chain can reach mDNS `/etc/nsswitch.conf` — the `hosts:` line must contain `mdns4_minimal [NOTFOUND=return]` **before** `dns`. On most distros the default already looks like this: ``` hosts: files mdns4_minimal [NOTFOUND=return] dns ``` If your file is missing `mdns4_minimal`, add it (order matters — keep it before `dns`). On Debian/Ubuntu, `/etc/resolv.conf` is usually a symlink to `systemd-resolved`'s stub at `127.0.0.53` — that's fine, leave it. ### e) Firewall (only if you have one) ```bash # UFW sudo ufw allow in on eth0 to any port 5353 udp sudo ufw allow in on eth0 to any port 5353 tcp # for DNS-SD browsing, optional # firewalld sudo firewall-cmd --permanent --add-service={mdns,avahi} sudo firewall-cmd --reload ``` ### f) (Recommended) Add the name to `/etc/hosts` too This gives you a fallback if mDNS is ever down: ```bash echo "192.168.178.10 box-a.box-a box-a" | sudo tee -a /etc/hosts ``` (Not strictly necessary — mDNS + `nss-mdns` already cover it — but it's cheap insurance.) ## 4. Verify on every machine ```bash # 1) Is Avahi running and advertising our name? systemctl status avahi-daemon avahi-browse -a -r # should list your own name plus neighbours # 2) Can we resolve by name? getent hosts box-a.local # should return 192.168.178.10 ping -c 2 box-a.local # should work # 3) Can we reach a service by name? curl -I http://box-a.local:80 ssh box-a.local ``` Do the same from **every other machine** on the LAN — if `ping box-a.local` works from each of them, you're done. ## 5. One-liner cheat sheet (run on each box) ```bash sudo hostnamectl set-hostname <name> sudo apt install -y avahi-daemon avahi-discover avahi-utils nss-mdns # dnf/pacman equivalent sudo systemctl enable --now avahi-daemon grep -q 'mdns4_minimal' /etc/nsswitch.conf || sudo sed -i 's/^hosts:.*/hosts:\tfiles mdns4_minimal [NOTFOUND=return] dns/' /etc/nsswitch.conf avahi-browse -a -r ``` ## Common gotchas - **Name collision on the LAN** — two machines with the same hostname both advertise and one wins. Keep names unique; if you clone a VM, change the hostname *before* booting the clone. - **SELinux / AppArmor** — rarely an issue on modern distros, but if `avahi-browse` shows nothing, check `journalctl -u avahi-daemon`. - **NetworkManager** may reset `/etc/resolv.conf` on reconnect. On systemd systems use `systemd-resolved` (default) rather than NetworkManager's own resolver; mDNS still works through `nss-mdns` regardless. - **VPN / WireGuard active** — mDNS packets have TTL=1, so they only reach the local segment. A VPN tunnel won't see `box-a.local`. If you need remote access to `.local` names, use a VPN that forwards DNS (e.g., WireGuard + a `dnsmasq` at the gateway) — that's the "alternative" approach I mentioned. - **Some distros ship Avahi with `disallow-local-interfaces=yes`** (rare, mostly in containers). Check `/etc/avahi/avahi-daemon.conf` if nothing gets advertised. That's it — after doing steps 3a–3f on every machine, every Linux box on 192.168.178.0/24 will resolve `name.local` for every other box, no central DNS server needed.