dnsmasq:无法为端口 53 创建侦听套接字:地址已在使用中

Rav*_*ina 9 network-manager networking dns dnsmasq systemd-resolved

我正在尝试配置dnsmasq为与 一起工作NetworkManager,问题是当我尝试运行它失败的服务时:

dnsmasq: failed to create listening socket for port 53: Address already in use
Run Code Online (Sandbox Code Playgroud)

但是没有任何东西在听127.0.0.1:53

sudo ss -alpn sport = 53 src 127.0.0.1
Run Code Online (Sandbox Code Playgroud)

上面的命令没有输出!

这是我的/etc/dnsmasq.conf样子:

$ grep '^[^#]' /etc/dnsmasq.conf 
Run Code Online (Sandbox Code Playgroud)

no-resolv
server=8.8.8.8#53
listen-address=127.0.0.1
cache-size=50
Run Code Online (Sandbox Code Playgroud)

如果我bind-interfaces/etc/dnsmasq.conf.

为什么要启用此功能?评论指出:

大约唯一需要它的时候是在同一台机器上运行另一个名称服务器。

所以我认为这个问题可能来自systemd-resolved.service并且肯定是这样。停止后:

sudo systemctl stop systemd-resolved.service
Run Code Online (Sandbox Code Playgroud)

现在dnsmasq在没有bind-interfaces启用选项的情况下工作正常。


我正在运行 Ubuntu 18.04.1。
使用安装debootstrap,我的默认渲染器NetworkManager工作正常。


我的问题是:

  1. 为什么我必须启用bind-interfaces
  2. 只是禁用systemd-resolved服务可以吗?如果是我应该如何dnsmasq控制/etc/resolv.conf
  3. 更重要的是,为什么当端口没有监听时我会收到那条奇怪的错误消息53

use*_*.dz 2

默认情况下,Dnsmasq 尝试在所有接口上绑定端口。其中--bind-interfaces只有在配置中声明的接口。

\n

man dnsmasq

\n
-z, --bind-interfaces\n    On systems which support it, dnsmasq binds the wildcard address,\n    even when it is listening on only some interfaces. It then\n    discards requests that it shouldn\'t reply to. This has the\n    advantage of working even when interfaces come and go and change\n    address. This option forces dnsmasq to really bind only the\n    interfaces it is listening on. About the only time when this is\n    useful is when running another nameserver (or another instance\n    of dnsmasq) on the same machine. Setting this option also\n    enables multiple instances of dnsmasq which provide DHCP service\n    to run in the same machine.\n\n--bind-dynamic\n    Enable a network mode which is a hybrid between\n    --bind-interfaces and the default. Dnsmasq binds the address of\n    individual interfaces, allowing multiple dnsmasq instances, but\n    if new interfaces or addresses appear, it automatically listens\n    on those (subject to any access-control configuration). This\n    makes dynamically created interfaces work in the same way as the\n    default. Implementing this option requires non-standard\n    networking APIs and it is only available under Linux. On other\n    platforms it falls-back to --bind-interfaces mode. \n
Run Code Online (Sandbox Code Playgroud)\n

类似案例:

\n\n

更多高级相关主题:

\n\n


小智 0

这是我的工作示例。我记得我遇到了同样的问题,因为我的“buster”启用了 systemd-resolved.service。然而自从我上次使用它已经有一段时间了,但是下面的配置里面没有什么特别的:

# disables dnsmasq reading any other files like /etc/resolv.conf for nameservers
no-resolv

# Interface to bind to
interface=br0

# Specify starting_range,end_range,lease_time
dhcp-range=192.168.2.181,192.168.2.230,72h 

# dns addresses to send to the clients
server=8.8.8.8
server=8.8.4.4
dhcp-option=option:ntp-server,162.159.200.123,90.187.99.165
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助

此致

萨沙