Por algum motivo, meu NAT só permite conexões na rede local. Quando faço ping na rede local, os pacotes saem com o gateway NAT como a fonte. Quando faço ping na rede remota (host da Internet, etc.), a origem do pacote é o endereço IP interno do dispositivo e as respostas não são retornadas corretamente. Alguma idéia sobre o que poderia ser configurado incorretamente?
router ~ # iptables -S
-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -i eth2 -j ACCEPT
-A INPUT -i eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -i eth0 -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -i eth0 -p tcp -m tcp --dport 3306 -j ACCEPT
router ~ # iptables -S -t nat
-P PREROUTING ACCEPT
-P INPUT ACCEPT
-P OUTPUT ACCEPT
-P POSTROUTING ACCEPT
-A POSTROUTING -o eth0 -j MASQUERADE
A rede interna é 192.168.0.0/16 e a externa (NAT local) é 10.72.16.0/22.
Atualizado com informações para A.B.
router ~ # ip -br link; ip -4 -br addr; ip route; ip rule
lo UNKNOWN 00:00:00:00:00:00 <LOOPBACK,UP,LOWER_UP>
eth0 UP 00:15:5d:e8:47:39 <BROADCAST,MULTICAST,UP,LOWER_UP>
eth1 UP 00:15:5d:e8:47:3a <BROADCAST,MULTICAST,UP,LOWER_UP>
eth2 UP 00:15:5d:e8:47:46 <BROADCAST,MULTICAST,UP,LOWER_UP>
sit0@NONE DOWN 0.0.0.0 <NOARP>
lo UNKNOWN 127.0.0.1/8
eth0 UP 10.72.16.140/22
eth1 UP 10.72.21.14/22
eth2 UP 192.168.0.1/16
default via 10.72.20.1 dev eth1
default via 10.72.16.1 dev eth0
10.72.16.0/22 dev eth0 proto kernel scope link src 10.72.16.140
10.72.20.0/22 dev eth1 proto kernel scope link src 10.72.21.14
192.168.0.0/16 dev eth2 proto kernel scope link src 192.168.0.1
0: from all lookup local
32766: from all lookup main
32767: from all lookup default
E o mesmo de um host interno:
int_host ~ # ip -br link; ip -4 -br addr; ip route; ip rule
lo UNKNOWN 00:00:00:00:00:00 <LOOPBACK,UP,LOWER_UP>
eth0 UP 52:69:6e:00:81:95 <BROADCAST,MULTICAST,UP,LOWER_UP>
usb0 DOWN 52:69:6e:00:00:00 <NO- CARRIER,BROADCAST,MULTICAST,UP>
lo UNKNOWN 127.0.0.1/8
eth0 UP 192.168.0.5/16
usb0 DOWN 192.168.127.5/24 169.254.0.1/16
default via 192.168.0.1 dev eth0
169.254.0.0/16 dev usb0 proto kernel scope link src 169.254.0.1 linkdown
192.168.0.0/16 dev eth0 proto kernel scope link src 192.168.0.5
192.168.127.0/24 dev usb0 proto kernel scope link src 192.168.127.5 linkdown
RTNETLINK answers: Address family not supported by protocol
Dump terminated
Ping do host interno para um host externo (local):
int_host ~ # ping 10.72.16.50
PING 10.72.16.50 (10.72.16.50) 56(84) bytes of data.
64 bytes from 10.72.16.50: icmp_seq=1 ttl=127 time=1.37 ms
^C
Ping do host interno para um host externo (externo):
int_host ~ # ping 172.18.221.227
PING 172.18.221.227 (172.18.221.227) 56(84) bytes of data.
^C
--- 172.18.221.227 ping statistics ---
8 packets transmitted, 0 received, 100% packet loss, time 7243ms
O Wireshark mostra que o ping veio com a fonte sendo o endereço IP interno do host interno:
4842 60.182197 192.168.0.5 172.18.221.227 ICMP 98 Echo (ping) request id=0x567d, seq=7/1792, ttl=62 (reply in 4843)
4843 60.182365 172.18.221.227 192.168.0.5 ICMP 98 Echo (ping) reply id=0x567d, seq=7/1792, ttl=128 (request in 4842)
Como esperado, a resposta nunca é enviada de volta porque vai para o host 192.168.0.5 inexistente em vez do roteador em 10.72.16.140 (e depois para o endereço interno 192.168.0.5).