I am trying to do something I though would be easy with iptables, but proving to be difficult. The problem is that the PREROUTING chain in the nat table seems to either not be catching packets or is ignoring them...
I have a network setup as follows:
Gatway - eth0:192.168.0.2 eth0:1 10.1.1.2 ppp0: x.x.x.x
DSL modem - 192.168.0.1
ATA - 10.1.1.1
other PCs - 192.168.0.*
I have the following hand written firewall script on the gateway:
-----------------------
iptables -F INPUT
iptables -F FORWARD
iptables -F OUTPUT
iptables -F -t nat
iptables -N mine
iptables -F mine
iptables -F mine
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -A POSTROUTING -t nat -o ppp0 -s 172.16.0.0/24 -d 0/0 -j MASQUERADE
iptables -A POSTROUTING -t nat -o ppp0 -s 10.1.1.0/24 -d 0/0 -j MASQUERADE
iptables -A POSTROUTING -t nat -o ppp0 -s 192.168.0.0/24 -d 0/0 -j MASQUERADE
iptables -A FORWARD -s 172.16.0.0/24 -d 0/0 -j ACCEPT
iptables -A FORWARD -s 10.1.1.0/24 -d 0/0 -j ACCEPT
iptables -A FORWARD -s 192.168.0.0/24 -d 0/0 -j ACCEPT
iptables -A FORWARD -i ppp0 -j ACCEPT
iptables -A INPUT -m state --state ESTABLISHED,RELATED -p icmp -j mine
iptables -A INPUT -p tcp -m multiport --dports 80,25,443,22,20,21 -j mine
iptables -A INPUT -p tcp -m state --state ESTABLISHED,RELATED -j mine
iptables -A INPUT -p udp -m state --state ESTABLISHED,RELATED -j mine
iptables -A OUTPUT -m state --state NEW,ESTABLISHED,RELATED -p icmp -j mine
iptables -A OUTPUT -p tcp -m state --state NEW,ESTABLISHED,RELATED -j mine
iptables -A OUTPUT -p udp -m state --state NEW,ESTABLISHED,RELATED -j mine
iptables -A mine -i ppp0 -j ACCEPT
iptables -A mine -o ppp0 -j ACCEPT
iptables -A INPUT -i ppp0 -j DROP
iptables -A OUTPUT -o ppp0 -j DROP
iptables -A FORWARD -j DROP
----------------------
The firewall may not be 'proper' but it seems to work. I also have a bunch of rules on the POSTROUTING chain in the nat table for QOS which is working well. Now, the ATA on 10.1.1.1 is trying to connect to a machine on the net on port 123. tcpdump shows the source as 10.1.1.1.1026 and destination x.x.x.x.123.
I am trying to do DNAT, altering the destination of those packets. I have tried a rule as follows without success:
iptables -A PREROUTING -t nat -p udp --dport 123 -s 10.1.1.1/32 -j DNAT --to x.x.x.x:123
Since that didn't work, I decided to log all packets caught with the same rule, which was nil. Then I used the following rule:
iptables -A PREROUTING -t nat -j LOG
I was trying to work out if iptables was even seeing the packet. That rule above shows maybe 1 packet a minute on the gateway where traffic is constantly flying around between machines and ppp0 on the gateway.
So, I don't understand how iptables works with relation to what I want to do, and I don't know why the line above doesn't log all packets.
Im probably doing something really retardedly stupid, but please tell me!
