dnsmasq:无法为端口 53 创建监听套接字:地址已被使用

dnsmasq:无法为端口 53 创建监听套接字:地址已被使用

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

dnsmasq: failed to create listening socket for port 53: Address already in use

然而什么都没有监听127.0.0.1:53

sudo ss -alpn sport = 53 src 127.0.0.1

上述命令没有输出!

以下是我的/etc/dnsmasq.conf样子:

$ grep '^[^#]' /etc/dnsmasq.conf 

no-resolv
server=8.8.8.8#53
listen-address=127.0.0.1
cache-size=50

bind-interfaces如果我启用 ,该问题就可以得到解决/etc/dnsmasq.conf

我为什么要启用这个功能?评论指出:

唯一可能需要此功能的情况是在同一台机器上运行另一个名称服务器时。

所以我想问题可能出在这里systemd-resolved.service并且肯定是的。停止它之后:

sudo systemctl stop systemd-resolved.service

现在dnsmasq可以正常工作,无需bind-interfaces启用选项。


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


我的问题是:

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

答案1

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

man dnsmasq

-z, --bind-interfaces
    On systems which support it, dnsmasq binds the wildcard address,
    even when it is listening on only some interfaces. It then
    discards requests that it shouldn't reply to. This has the
    advantage of working even when interfaces come and go and change
    address. This option forces dnsmasq to really bind only the
    interfaces it is listening on. About the only time when this is
    useful is when running another nameserver (or another instance
    of dnsmasq) on the same machine. Setting this option also
    enables multiple instances of dnsmasq which provide DHCP service
    to run in the same machine.

--bind-dynamic
    Enable a network mode which is a hybrid between
    --bind-interfaces and the default. Dnsmasq binds the address of
    individual interfaces, allowing multiple dnsmasq instances, but
    if new interfaces or addresses appear, it automatically listens
    on those (subject to any access-control configuration). This
    makes dynamically created interfaces work in the same way as the
    default. Implementing this option requires non-standard
    networking APIs and it is only available under Linux. On other
    platforms it falls-back to --bind-interfaces mode. 

类似案例:

更多高级相关主题:

答案2

这是我的工作示例。我记得我遇到过同样的问题,因为我的“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

希望这可以帮助

此致

莎莎

相关内容