LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 08-04-2005, 07:25 PM   #1
jebaird
Member
 
Registered: Jul 2005
Location: Iowa
Distribution: openSuse10, FC5
Posts: 46

Rep: Reputation: 15
Iptables problems with port forwarding


I am trying to get portforwarding to work on my linux router. I would like to host a webserver that listens on 8080.
eth1 is my internet interface
eth0 is my LAN interface

I got NAT to work this scricpt:

modprobe iptable_nat
echo 1> /proc/sys/net/ipv4/ip_forward

iptables -A POSTROUTING -t nat -o eth1 -s 10.0.0.0/24 -d 0/0 -j MASQERADE
iptables - FORWARD -t filter -o eth1 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT

iptables -A FORWARD -t filter -i eth1 -m state --state ESTABLISHED,RELATED -j ACCEPT

as for the Port forwarding this is what I have so far:
Iptables -t nat - A POSTROUTING -p tcp -i eth1 -d 161.210.34.156 ---dport 80 ---sport 1024:65535 -j DNAT --to 10.0.0.11:8080

iptables -p tccp -i eth1 -eth0 -d 10.0.0.11 --dport 8080 --sport 1024:65535 -m state --state NEW -j ACCEPT

iptables -A FORWARD -t filter -o eth1 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -t filter -i eth1 -m state --state ESTABLISHED,RELATED -j ACCEPT

I am very new with iptables. any tips would be great!!
thanks
 
Old 08-04-2005, 11:40 PM   #2
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Re: Iptables problems with port forwarding

Quote:
Originally posted by jebaird
I am trying to get portforwarding to work on my linux router. I would like to host a webserver that listens on 8080.
eth1 is my internet interface
eth0 is my LAN interface

I got NAT to work this scricpt:

modprobe iptable_nat
echo 1> /proc/sys/net/ipv4/ip_forward

iptables -A POSTROUTING -t nat -o eth1 -s 10.0.0.0/24 -d 0/0 -j MASQERADE
iptables - FORWARD -t filter -o eth1 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT

iptables -A FORWARD -t filter -i eth1 -m state --state ESTABLISHED,RELATED -j ACCEPT

as for the Port forwarding this is what I have so far:
Iptables -t nat - A POSTROUTING -p tcp -i eth1 -d 161.210.34.156 ---dport 80 ---sport 1024:65535 -j DNAT --to 10.0.0.11:8080

iptables -p tccp -i eth1 -eth0 -d 10.0.0.11 --dport 8080 --sport 1024:65535 -m state --state NEW -j ACCEPT

iptables -A FORWARD -t filter -o eth1 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT
iptables -A FORWARD -t filter -i eth1 -m state --state ESTABLISHED,RELATED -j ACCEPT

I am very new with iptables. any tips would be great!!
thanks
try this instead (it's basically the same but i cleaned it up for you a little bit ):

Code:
echo 0 > /proc/sys/net/ipv4/ip_forward
echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter

iptables -F
iptables -F -t nat
iptables -F -t mangle
iptables -X
iptables -X -t nat
iptables -X -t mangle

iptables -P FORWARD DROP

iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT

iptables -A FORWARD -i eth0 -o eth1 -s 10.0.0.0/24 \
-m state --state NEW -j ACCEPT

iptables -A FORWARD -p TCP -i eth1 -eth0 -d 10.0.0.11 --dport 8080 \
-m state --state NEW -j ACCEPT

iptables -t nat -A PREROUTING -p TCP -i eth1 -d 161.210.34.156 \
--dport 80 -j DNAT --to-destination 10.0.0.11:8080

iptables -t nat -A POSTROUTING -o eth1 -j MASQUERADE

echo 1 > /proc/sys/net/ipv4/ip_forward
just my ...


Last edited by win32sux; 08-04-2005 at 11:53 PM.
 
Old 08-05-2005, 11:28 AM   #3
jebaird
Member
 
Registered: Jul 2005
Location: Iowa
Distribution: openSuse10, FC5
Posts: 46

Original Poster
Rep: Reputation: 15
thanks win32sux,
I like the cleaned up code, it makes more sence
 
Old 08-05-2005, 12:35 PM   #4
win32sux
LQ Guru
 
Registered: Jul 2003
Location: Los Angeles
Distribution: Ubuntu
Posts: 9,870

Rep: Reputation: 380Reputation: 380Reputation: 380Reputation: 380
Quote:
Originally posted by jebaird
thanks win32sux,
I like the cleaned up code, it makes more sence
your welcome...

BTW, since you have a static IP, you might wanna use SNAT instead of MASQUERADE:
Code:
EXT_IP="161.210.34.156"

echo 0 > /proc/sys/net/ipv4/ip_forward
echo 1 > /proc/sys/net/ipv4/conf/all/rp_filter

iptables -F
iptables -F -t nat
iptables -F -t mangle
iptables -X
iptables -X -t nat
iptables -X -t mangle

iptables -P FORWARD DROP

iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT

iptables -A FORWARD -i eth0 -o eth1 -s 10.0.0.0/24 \
-m state --state NEW -j ACCEPT

iptables -A FORWARD -p TCP -i eth1 -eth0 -d 10.0.0.11 --dport 8080 \
-m state --state NEW -j ACCEPT

iptables -t nat -A PREROUTING -p TCP -i eth1 -d $EXT_IP --dport 80 \
-j DNAT --to-destination 10.0.0.11:8080

iptables -t nat -A POSTROUTING -o eth1 -j SNAT --to-source $EXT_IP

echo 1 > /proc/sys/net/ipv4/ip_forward

Last edited by win32sux; 08-05-2005 at 12:36 PM.
 
  


Reply


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
port forwarding with iptables kkennedy Linux - Networking 1 09-01-2005 06:48 PM
iptables port forwarding jefmwols Linux - Networking 9 05-20-2005 04:08 PM
iptables port forwarding problems JCdude2525 Linux - Networking 18 02-09-2005 04:25 PM
IPTables port forwarding.. NeoTech Linux - Networking 2 01-03-2005 11:27 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 11:51 PM.

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