2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

LinuxでmDNSを無効化する方法【Avahi/systemd】

2
Last updated at Posted at 2024-04-22

この記事で解決できること

LinuxでmDNS(マルチキャストDNS)を無効化し、ファイアウォールログから5353ポートの不要な通信を排除できます。
ターミナルでの手動手順とAnsible Playbookの両方を紹介します。

DNSサーバを運用しているオンプレミス環境では、mDNSは不要なケースが多いです。mDNSが有効だと5353ポートへの通信がファイアウォールログを埋め尽くし、本来注目すべき通信の解析が困難になります。

Avahiデーモンを停止・無効化する

Avahi(mDNSの実装)のサービスとソケットの両方を停止・無効化・マスクします。

ターミナルで実行する場合

sudo systemctl stop avahi-daemon.socket
sudo systemctl disable avahi-daemon.socket
sudo systemctl mask avahi-daemon.socket
sudo systemctl stop avahi-daemon
sudo systemctl disable avahi-daemon
sudo systemctl mask avahi-daemon

Ansibleで実行する場合

- name: disable avahi-daemon
  systemd:
    name: avahi-daemon
    state: stopped
    enabled: false
    daemon_reload: yes
    masked: true
  become: true

- name: disable avahi-daemon.socket
  systemd:
    name: avahi-daemon.socket
    state: stopped
    enabled: false
    daemon_reload: yes
    masked: true
  become: true

systemd-resolvedのmDNS機能を無効化する

Avahiを無効化しても5353ポートの通信が止まらない場合があります。
原因はsystemd-resolvedが独自にmDNS機能を持っているためです。
Arch Linuxなどではこちらも無効化が必要です。

resolved.confをターミナルで編集する場合

echo "MulticastDNS=no" >> /etc/systemd/resolved.conf
sudo systemctl restart systemd-resolved

resolved.confをAnsibleで管理する場合

tasks/main.yml
- name: Set up resolved.conf
  template:
    src: templates/resolved.conf.j2
    dest: "/etc/systemd/resolved.conf"
    owner: "root"
    group: "root"
    mode: 0644
  become: true
  notify: restart systemd-resolved
templates/resolved.conf.j2
[Resolve]
MulticastDNS=no
handlers/main.yml
- name: restart systemd-resolved
  systemd:
   name: systemd-resolved
   state: restarted
   daemon_reload: yes
  become: true

まとめ

  • mDNSを無効化するにはAvahiデーモンsystemd-resolvedのmDNS機能の両方を停止する
  • Avahiだけ止めても、systemd-resolvedがmDNS通信を発信し続ける場合がある
  • systemctl mask でサービスをマスクすると、手動・自動を問わず起動を防止できる
2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?