我有一个可笑的问题。
我只想允许 1 位用户访问互联网。设置 IPTABLES,我可以 ping 允许的用户,但所有 DNS 流量都被阻止。
然而添加 root 用户可以“解决”这个问题。这是怎么回事?!
Chain OUTPUT (policy ACCEPT)
num target prot opt source destination
1 LOG all -- anywhere anywhere LOG level debug prefix "iptables denied output: "
2 ACCEPT udp -- anywhere anywhere udp dpt:domain
3 ACCEPT tcp -- anywhere anywhere tcp dpt:domain
4 ACCEPT all -- anywhere anywhere owner UID match test
5 DROP all -- anywhere anywhere
test@test-VirtualBox:~$ ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_seq=1 ttl=58 time=5.05 ms
64 bytes from 8.8.8.8: icmp_seq=2 ttl=58 time=5.25 ms
^C
--- 8.8.8.8 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 5.059/5.158/5.258/0.122 ms
test@test-VirtualBox:~$ ping stackexchange.com
ping: unknown host stackexchange.com
test@test-VirtualBox:~$
日志
Feb 7 14:38:14 test-VirtualBox kernel: [14848.267387] iptables denied output: IN= OUT=lo SRC=127.0.0.1 DST=127.0.1.1 LEN=50 TOS=0x00 PREC=0x00 TTL=64 ID=2588 DF PROTO=UDP SPT=33317 DPT=53 LEN=30
Feb 7 14:38:14 test-VirtualBox kernel: [14848.267535] iptables denied output: IN= OUT=enp0s3 SRC=10.0.0.119 DST=8.8.8.8 LEN=50 TOS=0x00 PREC=0x00 TTL=64 ID=39417 DF PROTO=UDP SPT=36975 DPT=53 LEN=30
Feb 7 14:38:14 test-VirtualBox kernel: [14848.314265] iptables denied output: IN= OUT=lo SRC=127.0.1.1 DST=127.0.0.1 LEN=120 TOS=0x00 PREC=0x00 TTL=64 ID=56633 DF PROTO=UDP SPT=53 DPT=33317 LEN=100
Feb 7 14:38:19 test-VirtualBox kernel: [14853.273968] iptables denied output: IN= OUT=lo SRC=127.0.0.1 DST=127.0.1.1 LEN=50 TOS=0x00 PREC=0x00 TTL=64 ID=3453 DF PROTO=UDP SPT=33317 DPT=53 LEN=30
Feb 7 14:38:19 test-VirtualBox kernel: [14853.274099] iptables denied output: IN= OUT=enp0s3 SRC=10.0.0.119 DST=8.8.8.8 LEN=50 TOS=0x00 PREC=0x00 TTL=64 ID=40515 DF PROTO=UDP SPT=36975 DPT=53 LEN=30
Feb 7 14:38:19 test-VirtualBox kernel: [14853.280184] iptables denied output: IN= OUT=lo SRC=127.0.1.1 DST=127.0.0.1 LEN=120 TOS=0x00 PREC=0x00 TTL=64 ID=57565 DF PROTO=UDP SPT=53 DPT=33317 LEN=100
答案1
可能您已经安装了解析器。此类解析器有助于缓存所有用户的 DNS 查询,并且由 root(或“nobody”)运行。
检查您使用的是哪个解析器(例如,在现代发行版中,解析器包含在 systemd 中,以前常见的解析器是 lwresd(来自 bind)。