当我通过 ufw 拒绝时,为什么 nc 扫描能够成功连接到端口 53?
我注意到端口 53 正在监听:
$ sudo ss -tulpne
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port
udp UNCONN 0 0 0.0.0.0:5353 0.0.0.0: users:(("avahi-daemon",pid=514,fd=12)) uid:115 ino:18620 sk:1 <->
udp UNCONN 0 0 127.0.0.53%lo:53 0.0.0.0: users:(("systemd-resolve",pid=356,fd=12)) uid:102 ino:15766 sk:2 <->
udp UNCONN 0 0 10.0.2.15%ens3:68 0.0.0.0: users:(("NetworkManager",pid=538,fd=19)) ino:21287 sk:3 <->
udp UNCONN 0 0 0.0.0.0:51675 0.0.0.0: users:(("avahi-daemon",pid=514,fd=14)) uid:115 ino:18622 sk:4 <->
udp UNCONN 0 0 0.0.0.0:631 0.0.0.0: users:(("cups-browsed",pid=571,fd=7)) ino:18922 sk:5 <->
udp UNCONN 0 0 0.0.0.0:43745 0.0.0.0: users:(("systemd-timesyn",pid=355,fd=16)) uid:100 ino:41918 sk:6 <->
udp UNCONN 0 0 [::]:5353 [::]: users:(("avahi-daemon",pid=514,fd=13)) uid:115 ino:18621 sk:7 v6only:1 <->
udp UNCONN 0 0 [::]:38831 [::]: users:(("avahi-daemon",pid=514,fd=15)) uid:115 ino:18623 sk:8 v6only:1 <->
tcp LISTEN 0 128 127.0.0.53%lo:53 0.0.0.0: users:(("systemd-resolve",pid=356,fd=13)) uid:102 ino:15767 sk:9 <->
tcp LISTEN 0 5 127.0.0.1:631 0.0.0.0: users:(("cupsd",pid=487,fd=7)) ino:18380 sk:a <->
tcp LISTEN 0 5 [::1]:631 [::]:* users:(("cupsd",pid=487,fd=6)) ino:18379 sk:b v6only:1 <->
所以我通过ufw关闭了那个端口:
$ sudo ufw deny 53
$ sudo ufw status verbose
Status: active Logging: on (low) Default: deny (incoming), allow (outgoing), disabled (routed) New profiles: skip
To Action From
53 DENY IN Anywhere
53 (v6) DENY IN Anywhere (v6)
当我进行 nc 扫描时,我看到与端口的连接成功:
$ sudo nc -zv 127.0.0.53 50-53
nc: connect to 127.0.0.53 port 50 (tcp) failed: Connection refused
nc: connect to 127.0.0.53 port 51 (tcp) failed: Connection refused
nc: connect to 127.0.0.53 port 52 (tcp) failed: Connection refused
Connection to 127.0.0.53 53 port [tcp/domain] succeeded!
我希望防火墙阻止此连接
为什么防火墙不阻止连接?请帮助我纠正我的想法
旁注:我知道 dnsmasqd 使用端口 53,并且有很多充分的理由保持端口开放。但在这个问题中,我只关心通过防火墙有效关闭端口。我也知道我可以通过编辑 /etc/systemd/resolved.conf 来阻止这个端口监听
ufw 不会阻止任何本地主机连接。这些总是被允许的。