linux – 传入的数据包没有命中iptables INPUT链

前端之家收集整理的这篇文章主要介绍了linux – 传入的数据包没有命中iptables INPUT链前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在docker容器中运行VPN客户端.我正在尝试通过端口8080从主机连接到在docker容器中运行的Web服务器.当我尝试连接时,我通过tcpdump在端口8080上看到我的传入数据包,但Web服务器从未看到它.
我已经为数据包的所有可能状态转换添加了iptables’-j LOG’规则,试图追踪它.我看到的数据包是:

>表’raw’,链PREROUTING
>表’mangle’,链PREROUTING
> table’nat’,链条PREROUTING

然后……没什么.在一小段延迟之后,数据包被重新发送,我看到新数据包通过PREROUTING.没有任何东西出现在剪辑INPUT或mangle FORWARD链上 – 据我所知,这是不可能的 – 它必须击中其中一个.
有没有办法让数据包通过PREROUTING,但不能点击INPUT或FORWARD?
我的iptables如下:

  1. root@87ff7ad8e4f9:/# iptables -t raw -L
  2. Chain PREROUTING (policy ACCEPT)
  3. target prot opt source destination
  4. NFLOG tcp -- anywhere anywhere tcp spt:http-alt nflog-prefix "raw pre-route Src incoming packet"
  5. NFLOG tcp -- anywhere anywhere tcp dpt:http-alt nflog-prefix "raw pre-route Dest incoming packet"
  6.  
  7. Chain OUTPUT (policy ACCEPT)
  8. target prot opt source destination
  9. NFLOG tcp -- anywhere anywhere tcp dpt:http-alt nflog-prefix "Dest outgoing packet"
  10. NFLOG tcp -- anywhere anywhere tcp spt:http-alt nflog-prefix "Src outgoing packet"
  11. root@87ff7ad8e4f9:/# iptables -t mangle -L
  12. Chain PREROUTING (policy ACCEPT)
  13. target prot opt source destination
  14. NFLOG tcp -- anywhere anywhere tcp dpt:http-alt nflog-prefix "mangle PREROUTING Dest incoming packet"
  15.  
  16. Chain INPUT (policy ACCEPT)
  17. target prot opt source destination
  18. NFLOG all -- anywhere anywhere nflog-prefix "mangle INPUT Dest incoming packet any2"
  19.  
  20. Chain FORWARD (policy ACCEPT)
  21. target prot opt source destination
  22. NFLOG all -- anywhere anywhere nflog-prefix "mangle FORWARD Dest incoming packet any"
  23.  
  24. Chain OUTPUT (policy ACCEPT)
  25. target prot opt source destination
  26. MARK tcp -- anywhere anywhere tcp spt:http-alt MARK set 0x1
  27. MARK tcp -- anywhere anywhere tcp dpt:http-alt MARK set 0x1
  28. NFLOG tcp -- anywhere anywhere tcp spt:http-alt nflog-prefix "MARK set 0x1"
  29. NFLOG tcp -- anywhere anywhere tcp dpt:http-alt nflog-prefix "Dest MARK set 0x1"
  30.  
  31. Chain POSTROUTING (policy ACCEPT)
  32. target prot opt source destination
  33. root@87ff7ad8e4f9:/# iptables -t nat -L
  34. Chain PREROUTING (policy ACCEPT)
  35. target prot opt source destination
  36. NFLOG tcp -- anywhere anywhere tcp dpt:http-alt nflog-prefix "nat PREROUTING Dest incoming packet"
  37.  
  38. Chain INPUT (policy ACCEPT)
  39. target prot opt source destination
  40. NFLOG tcp -- anywhere anywhere tcp dpt:http-alt nflog-prefix "nat INPUT Dest incoming packet"
  41.  
  42. Chain OUTPUT (policy ACCEPT)
  43. target prot opt source destination
  44.  
  45. Chain POSTROUTING (policy ACCEPT)
  46. target prot opt source destination
  47. root@87ff7ad8e4f9:/# iptables -t filter -L
  48. Chain INPUT (policy ACCEPT)
  49. target prot opt source destination
  50. NFLOG tcp -- anywhere anywhere nflog-prefix "connection made"
  51. NFLOG tcp -- anywhere anywhere tcp dpt:http-alt nflog-prefix "filter INPUT Dest incoming packet"
  52.  
  53. Chain FORWARD (policy ACCEPT)
  54. target prot opt source destination
  55.  
  56. Chain OUTPUT (policy ACCEPT)
  57. target prot opt source destination
  58. ACCEPT all -- anywhere anywhere ctstate RELATED,ESTABLISHED
  59. ACCEPT all -- anywhere anywhere
  60. ACCEPT all -- anywhere anywhere
  61. ACCEPT all -- anywhere anywhere
  62. ACCEPT all -- anywhere 172.17.0.0/16
  63. ACCEPT udp -- anywhere anywhere udp dpt:domain
  64. ACCEPT tcp -- anywhere anywhere owner GID match vpn
  65. ACCEPT udp -- anywhere anywhere owner GID match vpn
  66. DROP all -- anywhere anywhere

我的系统日志显示

  1. Oct 4 07:22:56 87ff7ad8e4f9 raw pre-route Dest incoming packet IN=eth0 OUT= MAC=02:42:ac:11:00:02:02:42:2e:2c:fd:2e:08:00 SRC=76.167.254.196 DST=172.17.0.2 LEN=60 TOS=00 PREC=0x00 TTL=63 ID=39119 DF PROTO=TCP SPT=46644 DPT=8080 SEQ=4027056663 ACK=0 WINDOW=29200 SYN URGP=0 MARK=0
  2. Oct 4 07:22:56 87ff7ad8e4f9 mangle PREROUTING Dest incoming packet IN=eth0 OUT= MAC=02:42:ac:11:00:02:02:42:2e:2c:fd:2e:08:00 SRC=76.167.254.196 DST=172.17.0.2 LEN=60 TOS=00 PREC=0x00 TTL=63 ID=39119 DF PROTO=TCP SPT=46644 DPT=8080 SEQ=4027056663 ACK=0 WINDOW=29200 SYN URGP=0 MARK=0
  3. Oct 4 07:22:56 87ff7ad8e4f9 nat PREROUTING Dest incoming packet IN=eth0 OUT= MAC=02:42:ac:11:00:02:02:42:2e:2c:fd:2e:08:00 SRC=76.167.254.196 DST=172.17.0.2 LEN=60 TOS=00 PREC=0x00 TTL=63 ID=39119 DF PROTO=TCP SPT=46644 DPT=8080 SEQ=4027056663 ACK=0 WINDOW=29200 SYN URGP=0 MARK=0
  4. Oct 4 07:22:57 87ff7ad8e4f9 raw pre-route Dest incoming packet IN=eth0 OUT= MAC=02:42:ac:11:00:02:02:42:2e:2c:fd:2e:08:00 SRC=76.167.254.196 DST=172.17.0.2 LEN=60 TOS=00 PREC=0x00 TTL=63 ID=39120 DF PROTO=TCP SPT=46644 DPT=8080 SEQ=4027056663 ACK=0 WINDOW=29200 SYN URGP=0 MARK=0
  5. Oct 4 07:22:57 87ff7ad8e4f9 mangle PREROUTING Dest incoming packet IN=eth0 OUT= MAC=02:42:ac:11:00:02:02:42:2e:2c:fd:2e:08:00 SRC=76.167.254.196 DST=172.17.0.2 LEN=60 TOS=00 PREC=0x00 TTL=63 ID=39120 DF PROTO=TCP SPT=46644 DPT=8080 SEQ=4027056663 ACK=0 WINDOW=29200 SYN URGP=0 MARK=0
  6. Oct 4 07:22:57 87ff7ad8e4f9 nat PREROUTING Dest incoming packet IN=eth0 OUT= MAC=02:42:ac:11:00:02:02:42:2e:2c:fd:2e:08:00 SRC=76.167.254.196 DST=172.17.0.2 LEN=60 TOS=00 PREC=0x00 TTL=63 ID=39120 DF PROTO=TCP SPT=46644 DPT=8080 SEQ=4027056663 ACK=0 WINDOW=29200 SYN URGP=0 MARK=0

解决方法

我想我明白了.
PREROUTING和INPUT / FORWARD之间有什么关系?看看 the map:路由决策.

从您的日志:SRC = 76.167.254.196 DST = 172.17.0.2.
没有DNAT,您无法将公共路由到私有IP地址.尝试添加

  1. iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 8080 -j DNAT --to-destination 172.17.0.2

或者您可以将VPN设置为拥有私有IP.

猜你在找的Linux相关文章