Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Networking
User Name
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.


  Search this Thread
Old 10-16-2006, 02:07 AM   #1
LQ Newbie
Registered: Oct 2006
Posts: 6

Rep: Reputation: 0
iptables nat port forwarding rule set

I have been trying to do a port forward, but I am new to iptables.

I have two ethernet ports: eth0 WAN, and eth1 LAN

I want anything which hits eth0 dport 2222 to be forwarded out eth1 to

Do I need to do a FORWARD, PREROUTE and POSTROUTE rule? Or can I just do a PREROUTE

I tried this with no luck:

sudo iptables -A FORWARD -i eth0 -p tcp --dport 2222 -j ACCEPT
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 2222 -j DNAT --to-destination

Do I need the:
sudo iptables -A FORWARD -i eth0 -p tcp --dport 2222 -j ACCEPT
or will PREROUTE work without it?

Do I need to FORWARD if I already have a routing table set up?
Old 10-16-2006, 04:11 AM   #2
LQ Newbie
Registered: Sep 2006
Location: Germany
Distribution: FreeBSD
Posts: 29

Rep: Reputation: 15
for an example:


/sbin/iptables -A PREROUTING -t nat -p tcp --dport $PORT -i ppp0 -j DNAT --to $DMZ_IP:$PORT
/sbin/iptables -A FORWARD -p tcp -d $DMZ_IP --dport $PORT -i ppp0 -o $DMZ_IF -j ACCEPT
/sbin/iptables -A FORWARD -p tcp -s $DMZ_IP --sport $PORT -i $DMZ_IF -o ppp0 -j ACCEPT
Old 02-13-2012, 03:39 AM   #3
LQ Newbie
Registered: Feb 2012
Posts: 1

Rep: Reputation: Disabled
Nat forward port 29070

Hello, the Nat and the forward worked on my debian server up to the reboot of machines.

The following rules*:

/sbin/iptables -t nat -A PREROUTING -p tcp -i eth2 -d --dport 29070 -j DNAT --to-destination
/sbin/iptables -A FORWARD -p tcp -i eth2 -o eth0 -d --dport 29070 --sport 1024:65535 -m state --state NEW -j ACCEPT

Since the reboot, that doesn't work any more.

I have another rules towards one the others server and that her works.

/sbin/iptables -t nat -A PREROUTING -p tcp -i eth2 -d --dport 29082 -j DNAT --to-destination
/sbin/iptables -A FORWARD -p tcp -i eth2 -o eth0 -d --dport 29082 --sport 1024:65535 -m state --state NEW -j ACCEPT

Thank you for your help .


forwarding, iptables, nat

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
IPCHAINS port forwarding and IPTABLES port forwarding ediestajr Linux - Networking 26 01-14-2007 07:35 PM
Problem with port forwarding (NAT) on FC 5 heberrdacruz Linux - Networking 49 08-20-2006 12:32 AM
iptables port 80 rule Q doronunu Linux - Security 3 06-04-2006 06:55 PM
NAT and Port Forwarding aq_mishu Linux - Networking 2 09-16-2005 07:58 AM
iptables + NAT + Port forwarding problem SirGertrude Linux - Networking 9 05-14-2004 04:02 AM > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 01:31 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration