-   Linux - Networking (
-   -   IPTables port forwarding to routed IP (

hobbes80 08-03-2010 12:46 PM

IPTables port forwarding to routed IP

I have a linux server I'm intending to use as a firewall.
The server has the following adapters
eth0 - Public IP (VLAN2)
eth0:1 - Public IP2 (VLAN2)
eth1 - (VLAN4)

the Default gateway is my ISPs gateway.
Additionally, I have the following route set:
route add -net netmask gw

I have a server that exists on VLAN 208 at IP, its GW is (first IP in /21 range)

as it is on the network, traffic from the firewall is successfully routed from that server through my router to the FW and out to the Internet. The FW can ping, ssh, etc... the server and vice versa.

I want an iptables rule that will allow me to forward port 4401 on eth0:1 to

Is this possible since the IP is not on the same subnet as eth1, even though it is accessible?

I am very new to iptables, though I'm a bit better than a neophyte linux user. I have not made port forwards with it in the past without scripts to assist so I'm looking for not just "it is possible", but also the syntax of how to add it.

Thanks in advance.

tlowk 08-03-2010 03:57 PM

IP2= ip address of eth0:1
iptables -t nat -A PREROUTING -d ${IP2} --protocol tcp --dport 4401 -j DNAT --to-destination

when the packet arrive with the destination address IP2 it will change the destination address to the one you specify at the end, then the normal routing will apply and the packet will end at the right place

make sure that there is a 1 in /proc/sys/net/ipv4/ip_forward

hobbes80 08-03-2010 07:51 PM

Thank you, this resolved my issue.

All times are GMT -5. The time now is 08:32 PM.