Eu tenho 3 sistemas Linux A, B e C. A é um cliente TCP e envia uma mensagem para o servidor TCP em C. A pode ver apenas o IP externo de B que está na interface wlan0, 192.168.0.3
------------------ --------------------- --------------------------
System A System B System C
192.168.0.5 wlan0 <-----> 192.168.0.3 wlan0
192.168.61.73 eth0 <---> 192.168.61.81 eth0
TCP Client TCP Server on 192.168.61.81
------------------ ---------------------- -------------------------
O cliente TCP envia mensagem para 192.168.0.3.
Isso deve ser redirecionado para o servidor TCP em execução no 192.168.61.81 na porta 8036 do System C (através da interface eth0 do B).
Portanto, eu escrevi as seguintes regras da tabela ip e, em seguida, iniciei o Servidor em C e enviei uma mensagem do Cliente TCP em A. Eu posso ver os pacotes no Sistema B de A em wlan0, mas eles nunca são encaminhados. O sistema B parece estar recebendo pacotes SYN de A, mas soltando-os (veja logs).
Aqui está o que eu fiz no Sistema B:
#Enable IP Forwarding for NAT
echo "1" > /proc/sys/net/ipv4/ip_forward
#Flush all iptable chains and start afresh
sudo iptables -F
#Forwarding rules
sudo iptables -A PREROUTING -p tcp -m tcp -d 192.168.0.3 --dport 8036 -j DNAT --to-destination 192.168.61.81:8036
sudo iptables -A FORWARD -m state -p tcp -d 192.168.61.81 --dport 8036 --state NEW,ESTABLISHED,RELATED -j ACCEPT
sudo iptables -t nat -A POSTROUTING -p tcp -m tcp -s 192.168.61.81 --sport 8036 -j SNAT --to-source 192.168.0.3
#Enable logging
sudo iptables -A INPUT -j LOG --log-prefix INPUT
sudo iptables -A OUTPUT -j LOG --log-prefix OUTPUT
sudo iptables -A FORWARD -j LOG --log-prefix FORWARD
sudo iptables -A INPUT -j LOG --log-prefix 'drop:'
sudo iptables -A OUTPUT -j LOG --log-prefix 'drop:'
sudo iptables -A FORWARD -j LOG --log-prefix 'drop:'
tail -F /var/log/messages
Logs do Sistema B de / var / log / messages: (pacotes SYN sendo descartados)
May 2 11:53:17 my-laptop kernel: [42879.905449] FORWARDIN=wlan0 OUT=eth0 SRC=192.168.0.5 DST=192.168.61.81 LEN=60 TOS=0x00 PREC=0x00 TTL=63 ID=30394 DF PROTO=TCP SPT=40582 DPT=8036 WINDOW=5840 RES=0x00 SYN URGP=0
May 2 11:53:17 my-laptop kernel: [42879.905459] drop:IN=wlan0 OUT=eth0 SRC=192.168.0.5 DST=192.168.61.81 LEN=60 TOS=0x00 PREC=0x00 TTL=63 ID=30394 DF PROTO=TCP SPT=40582 DPT=8036 WINDOW=5840 RES=0x00 SYN URGP=0
Tabela de roteamento de IP do kernel no Sistema B:
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.61.0 * 255.255.255.0 U 0 0 0 eth0
default localhost 0.0.0.0 UG 0 0 0 eth0
Por favor ajude.
ATUALIZADO:
sudo iptables -L -n -v
Chain INPUT (policy ACCEPT 39844 packets, 25M bytes)
pkts bytes target prot opt in out source destination
26926 10M LOG all -- * * 0.0.0.0/0 0.0.0.0/0 LOG flags 0 level 4
12866 8559K LOG all -- * * 0.0.0.0/0 0.0.0.0/0 LOG flags 0 level 4 prefix 'INPUT'
12862 8558K LOG all -- * * 0.0.0.0/0 0.0.0.0/0 LOG flags 0 level 4 prefix 'drop:'
Chain FORWARD (policy ACCEPT 43 packets, 2580 bytes)
pkts bytes target prot opt in out source destination
79 4740 ACCEPT tcp -- * * 0.0.0.0/0 192.168.61.81 state NEW,RELATED,ESTABLISHED tcp dpt:8036
16 960 LOG all -- * * 0.0.0.0/0 0.0.0.0/0 LOG flags 0 level 4 prefix 'FORWARD'
16 960 LOG all -- * * 0.0.0.0/0 0.0.0.0/0 LOG flags 0 level 4 prefix 'drop:'
Chain OUTPUT (policy ACCEPT 36130 packets, 4943K bytes)
pkts bytes target prot opt in out source destination
27863 4093K LOG all -- * * 0.0.0.0/0 0.0.0.0/0 LOG flags 0 level 4
14035 2296K LOG all -- * * 0.0.0.0/0 0.0.0.0/0 LOG flags 0 level 4 prefix 'OUTPUT'
14034 2296K LOG all -- * * 0.0.0.0/0 0.0.0.0/0 LOG flags 0 level 4 prefix 'drop:'
sudo iptables -t nat -L -n -v
Chain PREROUTING (policy ACCEPT 252 packets, 63782 bytes)
pkts bytes target prot opt in out source destination
8 480 DNAT tcp -- * * 0.0.0.0/0 192.168.0.3 tcp dpt:8036 to:192.168.61.81:8036
236 59206 LOG all -- * * 0.0.0.0/0 0.0.0.0/0 LOG flags 0 level 4
Chain OUTPUT (policy ACCEPT 3098 packets, 208K bytes)
pkts bytes target prot opt in out source destination
Chain POSTROUTING (policy ACCEPT 3121 packets, 210K bytes)
pkts bytes target prot opt in out source destination
0 0 SNAT tcp -- * * 192.168.61.81 0.0.0.0/0 tcp spt:8036 to:192.168.0.3
2975 199K LOG all -- * * 0.0.0.0/0 0.0.0.0/0 LOG flags 0 level 4