我的问题:
我使用了下面的iptables命令:
iptables -t nat -A PREROUTING -p udp -i eth0 --dport 52220 -j DNAT --to-destination 192.168.19.40
192.168.19.40是虚拟机的IP地址,可以ping通:
root@Helium ~ # ip route get 192.168.19.40 192.168.19.40 dev untrusted-vm-br src 192.168.19.1 cache root@Helium ~ # ping 192.168.19.40 PING 192.168.19.40 (192.168.19.40) 56(84) bytes of data. 64 bytes from 192.168.19.40: icmp_seq=1 ttl=64 time=0.181 ms
但是,来自eth0的UDP数据包不会被转发:
root@Helium ~ # tcpdump -i eth0 udp port 52220 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes 20:36:15.425602 IP <reverse_hostname_of_my_home>.19834 > Helium.52220: UDP, length 160 20:36:23.621066 IP <reverse_hostname_of_my_home>.19834 > Helium.52220: UDP, length 160 ^C 2 packets captured 2 packets received by filter 0 packets dropped by kernel root@Helium ~ # tcpdump -i untrusted-vm-br udp port 52220 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode listening on untrusted-vm-br, link-type EN10MB (Ethernet), capture size 262144 bytes ^C 0 packets captured 0 packets received by filter 0 packets dropped by kernel
我有类似的端口redirect的TCP端口,这一切都按预期工作。
我究竟做错了什么? 有什么特定的UDP我错过了?
其他debugging信息:
IPv4转发已启用:
root@Helium ~ # cat /proc/sys/net/ipv4/ip_forward 1
使用iptables -v显示没有数据包匹配我的iptable规则:
root@Helium ~ # iptables -L -v -t nat Chain PREROUTING (policy ACCEPT 9680 packets, 612K bytes) pkts bytes target prot opt in out source destination [...] 0 0 DNAT udp -- eth0 any anywhere anywhere udp dpt:52220 to:192.168.19.40
我试过使用iptables -j日志:
iptables -t nat -A PREROUTING -p udp -j LOG --log-prefix "[iptables log udp]"
这使:
Aug 10 17:01:33 Helium kernel: [1824208.192607] [iptables log udp]IN=eth0 OUT= MAC=<mac_address_of_my_eth0> SRC=<ip_address_of_my_home> DST=<ip_address_of_eth0> LEN=188 TOS=0x00 PREC=0x00 TTL=51 ID=1476 DF PROTO=UDP SPT=19834 DPT=
Linux / iptables版本:
root@Helium ~ # uname -a Linux Helium 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt25-2+deb8u3 (2016-07-02) x86_64 GNU/Linux root@Helium ~ # iptables --version iptables v1.4.21
花了几个小时试图解决这个问题之后,我让机器发送UDP数据包进入睡眠状态。
当我醒来的时候,我又开始了这个过程,并且数据包按照预期进入虚拟机。 我已经尝试过之前重新启动发送过程,所以不只是这样。 也许暂时停止这个数据包…
所以,我想是魔术。