d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Basic Ip Tables Help
Add Reply New Topic New Poll
Member
Posts: 1,999
Joined: May 29 2010
Gold: 990.00
Apr 11 2015 12:52pm
I am trying to simulate the effects of

"route add default gw 192.168.0.2 eth0"

using IP tables, but am not very familiar with them. Could someone please provide some explanation?

My searches return results for forwarding other traffic.

Much appreciated!

Topology:
Host1: eth0 192.168.0.1; eth1 10.0.20.1
Host2: eth0 192.168.0.2; eth1 10.0.40.1
PrivHost1: eth0 10.0.20.2
PrivHost2: eth0 10.0.40.2

This post was edited by Cattotonic on Apr 11 2015 12:54pm
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Apr 11 2015 01:13pm
Are you just trying to redirect traffic to another interface? If so you can use the PREROUTING table and apply redirects.

Code
iptables -t nat --flush
iptables --flush
iptables -P FORWARD ACCEPT
iptables -t nat -A PREROUTING -i eth0
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE



Not exactly what you wanted, but it might be able to redirect based on ip address rather than interface.
Member
Posts: 1,999
Joined: May 29 2010
Gold: 990.00
Apr 11 2015 02:10pm
Quote (AbDuCt @ Apr 11 2015 03:13pm)
Are you just trying to redirect traffic to another interface? If so you can use the PREROUTING table and apply redirects.

Code
iptables -t nat --flush
iptables --flush
iptables -P FORWARD ACCEPT
iptables -t nat -A PREROUTING -i eth0
iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE



Not exactly what you wanted, but it might be able to redirect based on ip address rather than interface.


That should work! So to address it to, say 10.0.20.2, would it be simply:

Code
iptables -t nat -A POSTROUTING -o eth1 -d 10.0.20.2 -j MASQUERADE
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll