Skip to content

mDNS 配置

This guide explains how to install and configure mDNS (Multicast DNS) using Avahi on various Linux distributions. This allows you to access devices using .local hostnames (e.g., myserver.local).

Terminal window
sudo apk add avahi dbus
sudo rc-update add avahi-daemon
sudo service avahi-daemon start
  1. Install Packages:

    Terminal window
    sudo yum install avahi avahi-tools nss-mdns
  2. Enable Service:

    Terminal window
    sudo systemctl start avahi-daemon
    sudo systemctl enable avahi-daemon
  3. Configure Name Resolution:

    Edit /etc/nsswitch.conf and find the hosts: line. Change it from:

    hosts: files dns

    to:

    hosts: files mdns_minimal [NOTFOUND=return] dns
  4. Configure Firewall:

    Allow mDNS traffic through the firewall:

    Terminal window
    sudo firewall-cmd --permanent --add-service=mdns
    sudo firewall-cmd --reload

Ubuntu usually comes with Avahi installed. If not:

Terminal window
sudo apt update
sudo apt install avahi-daemon
  1. Install Package:

    Terminal window
    sudo pacman -S avahi
  2. Enable Service:

    Terminal window
    sudo systemctl enable --now avahi-daemon.service