
我有一個應用程式正在偵聽連接埠 20514:
$ sudo netstat -tulpn
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
udp 0 0 192.168.100.213:20514 0.0.0.0:* 3629/python3
我可以使用 tcpdump 看到進入我的電腦的資料包
$ sudo tcpdump -i enp0s25 -n -N udp port 20514
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on enp0s25, link-type EN10MB (Ethernet), capture size 262144 bytes
15:54:56.832307 IP 172.18.248.3.514 > 192.168.100.213.20514: SYSLOG user.critical, length: 111
iptables(此時)允許一切。請注意,它不會報告任何與 172.18.248.0/28 的規則相符的資料包,儘管我們在上面看到了一個資料包。在任何類型轉換中,-P INPUT 都是接受的
$ sudo iptables -L -v
Chain INPUT (policy ACCEPT 134 packets, 79373 bytes)
pkts bytes target prot opt in out source destination
0 0 ACCEPT tcp -- any any 192.168.100.0/24 anywhere tcp dpt:ssh
4745 282K ACCEPT tcp -- any any 10.8.0.0/24 anywhere tcp dpt:ssh
0 0 ACCEPT all -- any any 172.18.248.0/28 anywhere
Chain FORWARD (policy DROP 0 packets, 0 bytes)
pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 533 packets, 89933 bytes)
pkts bytes target prot opt in out source destination
Chain DOCKER (0 references)
pkts bytes target prot opt in out source destination
Chain DOCKER-ISOLATION-STAGE-1 (0 references)
pkts bytes target prot opt in out source destination
Chain DOCKER-ISOLATION-STAGE-2 (0 references)
pkts bytes target prot opt in out source destination
Chain DOCKER-USER (0 references)
pkts bytes target prot opt in out source destination
Chain LOGACCEPT (0 references)
pkts bytes target prot opt in out source destination
0 0 LOG all -- any any anywhere anywhere LOG level info prefix "INPUT:ACCEPT:"
0 0 ACCEPT all -- any any anywhere anywhere
因此,資料包似乎在進入介面後但在到達防火牆之前被阻止。
我還可以在哪裡查看為什麼進入我的電腦的資料包無法到達應用程式?
答案1
事實證明,問題在於 Docker 正在與與資料包來源位址重疊的網路建立介面。
儘管我已經清除了 docker 在 IPtables 中製定的所有規則,但我最終還是不得不更改 /etc/docker/daemon.json 以在不同的 IP 範圍啟動網路。然後我刪除了所有容器並刪除了 Docker 創建的所有網路。可能有一種破壞性較小的方法來完成刪除 docker 網路接口,但我沒有執著於任何東西。
之後資料包就通過了。所以看來是網路介面本身造成了乾擾。