DNS 查找本地主机时出现网络错误

DNS 查找本地主机时出现网络错误

我在 FreeBSD 的监狱中运行 Unbound 上的递归 DNS 服务器,并使用 pf 作为防火墙。drill @xxx.xxx.xxx.xxx example.com在本地计算机上运行(其中 xxx.xxx.xxx.xxx 是服务器 IP)可成功查找。

但是,如果我在服务器本身上尝试相同操作,无论是在监狱还是主机中......

# drill @localhost example.com
Error: error sending query: Could not send or receive, because of network error
# drill @xxx.xxx.xxx.xxx example.com
Error: error sending query: Could not send or receive, because of network error
# drill @127.0.0.1 example.com
Error: error sending query: Could not send or receive, because of network error
# drill @10.0.0.1 example.com
Error: error sending query: Could not send or receive, because of network error

pass quick on lo0 all我的 pf.conf 中有

以下是我的相关 ifconfig:

lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
    options=600003<RXCSUM,TXCSUM,RXCSUM_IPV6,TXCSUM_IPV6>
    inet6 ::1 prefixlen 128
    inet6 fe80::1%lo0 prefixlen 64 scopeid 0x3
    inet 127.0.0.1 netmask 0xff000000
    nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
lo1: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
    options=600003<RXCSUM,TXCSUM,RXCSUM_IPV6,TXCSUM_IPV6>
    inet 10.0.0.1 netmask 0xffffff00
    nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>

DNS jail 在 10.0.0.1 下运行

我的一些想法:Unbound 肯定配置正确。接口已经是 0.0.0.0,我有 10.0.0.0/16 和 127.0.0.0/8(当然还有我本地机器的 IP)的访问控制规则。此外,如果出现任何错误,尝试钻取将导致简单的“拒绝”。所以我认为这与 pf 有关?我可能忽略了一些小而明显的问题,但我不知道是什么。

我希望# drill @localhost example.com在服务器上取得成功,这样我就可以用 127.0.0.1 替换我的 resolv.conf 名称服务器

编辑:我用 netcat 做了一些测试,执行# nc -4 -vv localhost 53时会超时。但是使用 udp 作为协议# nc -4 -w 10 -vv -u localhost 53则不会。运行# pfctl -vnf /etc/pf.conf,以下是两次重定向到 jail 的情况:

rdr pass on vtnet0 inet proto udp from any to any port = domain -> 10.0.0.1 port 53
rdr pass on vtnet0 inet proto tcp from any to any port = domain -> 10.0.0.1 port 53

答案1

在对 pf 规则进行更多测试之后,我短暂地让所有流量通过,并意识到错误在于当我pass quick on lo0 all在 pf.conf 中时,jail 正在 lo1 下运行。

我已添加pass quick on lo1 all并且现在可工作。

还要注意,在 jail 内部,你应该查询 jail IP,而不是 localhost。因此,在 jails resolv.conf 中:

nameserver 10.0.0.1

相关内容