将 dnsmasq DNS 绑定到本地主机 (127.0.0.1)

D.K*_*.K. 4 domain-name-system linux internal-dns linux-networking dnsmasq

我想问一个关于配置dnsmasq DNS服务器的问题。我知道诸如“listen-address”之类的配置选项。但即使我将此选项设置为“listen-address=127.0.0.1”,dnsmasq 仍然在内部 127.0.0.1:53 和外部 192.168.xx:53 端打开端口。

所以我想问一下是否可以配置 dnsmasq 以便它只为本地主机(127.0.0.1)打开端口 53,例如 MySQL 数据库是可能的。

# Configuration file for dnsmasq.

port=53
proxy-dnssec
no-resolv
no-poll
server=127.0.0.1#[some port here]
server=127.0.0.1#[some another port here]
listen-address=127.0.0.1
no-hosts
Run Code Online (Sandbox Code Playgroud)

小智 11

我必须在配置文件中添加“绑定接口”,以便接口和监听地址达到预期效果。例如:

listen-address=127.0.0.1
interface=lo
bind-interfaces
Run Code Online (Sandbox Code Playgroud)

这将产生仅在本地主机上侦听的预期效果。我遇到了问题,因为我在服务器的公共 ip 上运行公共 dns(仅解析我自己的域),但我也想在 localhost 上运行 dnsmasq。因此,如果我删除“绑定接口”,我将收到“dnsmasq:无法为端口 53 创建侦听套接字:地址已在使用中”,因为它尝试侦听公共 IP。


Rya*_*hin 4

是的,你可以这么做

\n\n

dnsmasq 手册页对--interface参数进行了如下说明:

\n\n
 -i, --interface=<interface name>\n          Listen only on the specified interface(s). Dnsmasq automatically adds the loopback (local) interface to the list of interfaces  to  use\n          when  the  --interface option  is used. If no --interface or --listen-address options are given dnsmasq listens on all available inter\xe2\x80\x90\n          faces except any given in --except-interface options. IP alias interfaces (eg "eth1:0") cannot be used with  --interface  or  --except-\n          interface  options,  use  --listen-address  instead.  A  simple  wildcard, consisting of a trailing \'*\', can be used in --interface and\n          --except-interface options.\n
Run Code Online (Sandbox Code Playgroud)\n\n

在大多数系统上,默认情况下接口名称为 localhost/127.0.0.1 lo

\n\n

你可以像这样把它放在你的配置文件中

\n\n
interface=lo\n
Run Code Online (Sandbox Code Playgroud)\n\n

或者像这样在命令行上指定它

\n\n
dnsmasq --interface=lo\n
Run Code Online (Sandbox Code Playgroud)\n