iptables -t nat -A POSTROUTING -s 192.168.81.238 -j SNAT --to 192.168.81.245
把本地網卡的IP位址從192.168.81.238改為192.168.81.245
然後:
/ # ping 192.168.81.211
PING 192.168.81.211 (192.168.81.211): 56 data bytes
發現沒有回複。
在192.168.81.211上抓包可以看到icmp的源位址是192.168.81.245,但是隻抓到接收,沒有回複icmp。
原因:應該是211進行arp解析時沒有發現245的mac,是以不能回複。
解決辦法:
在81.211上增加靜态arp映射。
arp -s 192.168.81.245 00-0b-82-27-fd-e4
位址00-0b-82-27-fd-e4是211的位址。
這樣就可以ping通了:
/ # ping 192.168.81.211
PING 192.168.81.211 (192.168.81.211): 56 data bytes
64 bytes from 192.168.81.211: seq=0 ttl=64 time=0.688 ms
64 bytes from 192.168.81.211: seq=1 ttl=64 time=0.599 ms
64 bytes from 192.168.81.211: seq=2 ttl=64 time=0.558 ms
64 bytes from 192.168.81.211: seq=3 ttl=64 time=0.482 ms
64 bytes from 192.168.81.211: seq=4 ttl=64 time=0.424 ms
64 bytes from 192.168.81.211: seq=5 ttl=64 time=0.512 ms
64 bytes from 192.168.81.211: seq=6 ttl=64 time=0.427 ms
64 bytes from 192.168.81.211: seq=7 ttl=64 time=0.546 ms