Translation from ipchains to iptables
If someone would be so kind as to help me translate the following ipchains commands to iptables, that would be great.
Basically I need DNAT, or PAT, what ever you want to call it. However the tricky part is that each internal IP will have at least two external IP's. So depending upon which interface the traffic is traversing I need it's internal IP changed to one on that interfaces network. Confused yet?
Here are my current working ipchains commands
ip addr add 127.0.0.1/8 brd 127.0.0.255 dev lo ip addr add 192.168.1.250/24 brd 192.168.1.255 dev eth0 ip addr add 10.1.0.2/16 brd 10.1.255.255 dev eth1 ip addr add 10.1.0.99/16 brd 10.1.255.255 dev eth1 ip addr add 10.2.0.2/16 brd 10.2.255.255 dev eth2 ip addr add 10.2.0.59/16 brd 10.2.255.255 dev eth2
ipmasqadm portfw -a -P tcp -L 10.1.0.99 443 -R 192.168.1.1 443 ipmasqadm portfw -a -P tcp -L 10.1.0.99 143 -R 192.168.1.1 143 ipmasqadm portfw -a -P tcp -L 10.1.0.99 110 -R 192.168.1.1 110 ipmasqadm portfw -a -P tcp -L 10.1.0.99 81 -R 192.168.1.1 81 ipmasqadm portfw -a -P tcp -L 10.1.0.99 80 -R 192.168.1.1 80 ipmasqadm portfw -a -P tcp -L 10.1.0.99 25 -R 192.168.1.1 25 ipmasqadm portfw -a -P tcp -L 10.1.0.99 22 -R 192.168.1.1 22 ipmasqadm portfw -a -P tcp -L 10.1.0.99 21 -R 192.168.1.1 21
ipmasqadm portfw -a -P tcp -L 10.2.0.59 443 -R 192.168.1.1 443 ipmasqadm portfw -a -P tcp -L 10.2.0.59 143 -R 192.168.1.1 143 ipmasqadm portfw -a -P tcp -L 10.2.0.59 110 -R 192.168.1.1 110 ipmasqadm portfw -a -P tcp -L 10.2.0.59 81 -R 192.168.1.1 81 ipmasqadm portfw -a -P tcp -L 10.2.0.59 80 -R 192.168.1.1 80 ipmasqadm portfw -a -P tcp -L 10.2.0.59 25 -R 192.168.1.1 25 ipmasqadm portfw -a -P tcp -L 10.2.0.59 22 -R 192.168.1.1 22 ipmasqadm portfw -a -P tcp -L 10.2.0.59 21 -R 192.168.1.1 21
ipchains -A forward -s 192.168.1.0/24 -j MASQ
I have researched this some time ago, but never came up with a solution. I did some brief research today, but most DNAT examples I come across are dealing with a single ip. Where as stated above for each internal machine, I have at least two external IP's
Any help or comments is greatly appreciated.
Thank you
Signature · 8 lines
Sincerely, William L. Thomson Jr. Support Group Obsidian-Studios, Inc. 3548 Jamestown Ln. Jacksonville, FL 32223 Phone/Fax 904.260.2445 http://www.obsidian-studios.com
Joel,
Quoted 4 lines · Joel Newkirk
Quoted 1 line
ipchains -A forward -s 192.168.1.0/24 -j MASQ
The equivalent would be:
Quoted 8 lines
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -j MASQUERADE
but incurs the added overhead of checking the IP of the outbound interface all the time. You can eliminate this by using a SNAT target instead, as in:
iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth1 -j SNAT --to 10.1.0.2
Correct me if I am wrong, but I believe I have to stick with the first. Unless I can get away with the following?
iptables -t nat -A POSTROUTING -s 192.168.1.1/24 -o eth1 -j SNAT --to 10.1.0.99
Which for some reason I do not think will work? Or I seem to remember it not working?
If I stick with the one you mentioned than every internal machine's ip address will get natted to 10.1.0.2. Or the ip of the interface it's traveling. Which will screw things up for the next hop, which is a router doing PAT. Again.
In the example commands provided, I only showed one server. In reality I have a few, and each server has two IP's.
So while there is added overhead, I think it is necessity for what I am trying to accomplish.
Quoted 3 lines
This one would need to be matched to the specific interface and IP you would be using for outbound traffic from the LAN, and replicated for each one if you use several.
Maybe it will work since I am giving each interface many IP's. When I did trial and error before, I do not think I was doing the ip addr thing. So that could have been my problem with the above then.
Quoted 3 lines
Reply traffic to a DNATted request will automatically be routed back out the incoming interface and un-DNATted, so it doesn't affect the SNAT/MASQUERADE of new connections initiated from the LAN.
Got it.
Quoted 3 lines
Finally, to make it all come together, you should ACCEPT the traffic in FORWARD (ideally with a DROP policy to prevent other traffic, but that's not really pertinent to the DNAT traffic in this situation)
No, but should be a part of any standard firewall. First I want to get things working. Then I will tighten up things. Although at this point the traffic has already traversed a router, doing PAT. So while I am not specifically denying requests on ports, you will get no response, and if you talk to that port, you will only be talking to the router. Which will not respond.
Thank you very much for your assistance.
It is greatly appreciated.
Signature · 8 lines
Sincerely, William L. Thomson Jr. Support Group Obsidian-Studios, Inc. 3548 Jamestown Ln. Jacksonville, FL 32223 Phone/Fax 904.260.2445 http://www.obsidian-studios.com