I am using
iptables in conjunction with
net-filter queue in order to alter packets programmatically.
iptables rules over ubuntu lab with 2 NICs eth0 to the internet and eth1 to the LAN I have used the well known iptables rules for NATing with masquerading on eth0.
sudo iptables --table nat --append POSTROUTING -o eth0 -j MASQUERADE sudo iptables -append FORWARD -i eth1 -j ACCEPT. sudo iptables -t mangle -A PREROUTING -j NFQUEUE --queue-num 0 sudo iptables -t mangle -A OUTPUT -j NFQUEUE
These 4 rules are used to help me capture packets inside my program and modify packets or drop what I want using
In fact everything is going as I am expecting, that is the three protocol types
udp packets are modified and reinjected. In the queue then exits eth0 to the internet taking eth0 ip address as source address (effect of using MASQUERADE NAT rule).
That is true for all packets EXCEPT: ICMP ping reply or TCP ACK packets.
They exit to the internet taking the private ip of the lan device - 192.168.x.x at eth1 and reaches the other side with this private source ip address.
Any ideas. Thx.