LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
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 04-20-2003, 10:25 AM   #1
acid2000
Member
 
Registered: Nov 2001
Location: Exeter, UK
Distribution: Gentoo 1.4
Posts: 243

Rep: Reputation: 30
Forwarding connections


I want to forward all connections on port 80 on device ppp0 to a box on my network (eth1) 192.168.0.3. I think its something similar to:

iptables -t nat -A PREROUTING -p tcp -j DNAT --to-destination 192.168.0.3:80

iptables -t nat -A POSTROUTING -p tcp -o eth1 --dport 80

Does anyone have any ideas?
Thanks
 
Old 04-20-2003, 10:58 PM   #2
Robert0380
LQ Guru
 
Registered: Apr 2002
Location: Atlanta
Distribution: Gentoo
Posts: 1,280

Rep: Reputation: 47
#echo 1 > /proc/sys/net/ipv4/ip_forward
#iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 192.168.0.3

that SHOULD do it, if it doesnt let me know
 
Old 04-20-2003, 11:01 PM   #3
Robert0380
LQ Guru
 
Registered: Apr 2002
Location: Atlanta
Distribution: Gentoo
Posts: 1,280

Rep: Reputation: 47
oh, the echo 1 stuff is to turn on ip forwarding if its not already on, you can check by doing this:

#cat /proc/sys/net/ipv4/ip_forward

if that gives you a 0 then ip forwarding is not on and you should turn it on. If forwarding is not on by default then you will have to put that command in everytime you restart your computer. I suggest putting it in a script file and having that file run at startup by adding the line to your rc.local file (in /etc/ i think).
 
Old 04-21-2003, 09:04 AM   #4
acid2000
Member
 
Registered: Nov 2001
Location: Exeter, UK
Distribution: Gentoo 1.4
Posts: 243

Original Poster
Rep: Reputation: 30
No that command does not work

i've tried http://localhost and http://myexternalip neither get me a webpage.
 
Old 04-21-2003, 09:24 AM   #5
Robert0380
LQ Guru
 
Registered: Apr 2002
Location: Atlanta
Distribution: Gentoo
Posts: 1,280

Rep: Reputation: 47
does http://localhost work on the machine that the webserver is on? i.e. the server is running right?

I ask this because the rule basically says:

any new connection attempt comming in on any interface bound for port 80, change the destination address to the .3 machine. You may also want to check the rest of your rules to make sure you arent dropping the packets in a previous rule. If you dont mind, posting the rest of your iptables rules may help.

Last edited by Robert0380; 04-21-2003 at 09:42 AM.
 
Old 04-21-2003, 10:13 AM   #6
acid2000
Member
 
Registered: Nov 2001
Location: Exeter, UK
Distribution: Gentoo 1.4
Posts: 243

Original Poster
Rep: Reputation: 30
Yes the webserver is running on 192.168.0.3, currently I don't have any other rules as i'm testing this before adding it to my existing firewall ( which is down ) iptables is on accept everything.

after the rules you gave me the output of iptables is:

iptables -L

Chain INPUT (policy ACCEPT)
target prot opt source destination

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination
 
Old 04-21-2003, 10:23 AM   #7
Robert0380
LQ Guru
 
Registered: Apr 2002
Location: Atlanta
Distribution: Gentoo
Posts: 1,280

Rep: Reputation: 47
after you put in the rules i gave you, do this:

iptables -t nat -L

or

iptables -t nat --list (of course they are both the same)

this will give you the nat routing chains

Last edited by Robert0380; 04-21-2003 at 10:25 AM.
 
Old 04-21-2003, 11:04 AM   #8
dorian33
Member
 
Registered: Jan 2003
Location: Poland, Warsaw
Distribution: LFS, Gentoo
Posts: 591

Rep: Reputation: 32
It looks like it should be:
iptables -t nat -A PREROUTING -i ppp0 -p tcp --dport 80 -j DNAT --to-destination=192.168.0.3
iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE

and (with some 'firewalling')
iptables -A FORWARD -m state --state NEW -i ppp0 -p tcp --dport 80 -j ACCEPT
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT

or just (without 'firewalling')
iptables -A FORWARD -p tcp -j ACCEPT

above allows you to see http://your_external_ip in browsers on machines connected through ppp (not from LAN! from LAN the machines are using eth to connect)
of course, you need also /proc/sys/net/ipv4/ip_forward set to 1
 
Old 04-21-2003, 03:01 PM   #9
acid2000
Member
 
Registered: Nov 2001
Location: Exeter, UK
Distribution: Gentoo 1.4
Posts: 243

Original Poster
Rep: Reputation: 30
for the rules
iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 192.168.0.3
iptables -t nat -L gives:

Chain PREROUTING (policy ACCEPT)
target prot opt source destination
DNAT tcp -- anywhere anywhere tcp dpt:www to:192.168.0.3
DNAT tcp -- anywhere anywhere tcp dpt:www to:192.168.0.3

Chain POSTROUTING (policy ACCEPT)
target prot opt source destination
MASQUERADE all -- anywhere anywhere

Chain OUTPUT (policy ACCEPT)
target prot opt source destination

Is there anyway they could be being refused on .3? Is there a way to check.

Also dorian33 those rules didn't work either
 
Old 04-22-2003, 01:45 PM   #10
dorian33
Member
 
Registered: Jan 2003
Location: Poland, Warsaw
Distribution: LFS, Gentoo
Posts: 591

Rep: Reputation: 32
Very strange, I am using successfully very similar rules in my firewall; the differences are only: eth1 against the ppp0 and SNAT against the MASQUERADE (I've got static IP).
Have you applied all the 3 rules (with PREROUTING, POSTROUTING and FORWARD) ?
How do you did the test (from 'outside' machine)?
Can you see the http://192.168.0.3 site from firewall box?
If so post all firewall rules.
 
Old 04-22-2003, 04:26 PM   #11
acid2000
Member
 
Registered: Nov 2001
Location: Exeter, UK
Distribution: Gentoo 1.4
Posts: 243

Original Poster
Rep: Reputation: 30
I think i've fixed it, looks like those rules above worked but I just coudln't access the page from within my network.

I checked from an external source and it worked. Thanks for your help.
 
Old 04-23-2003, 01:53 AM   #12
bbenz3
Member
 
Registered: Feb 2002
Location: Orlando
Distribution: Whatever I feel like at the time I install.
Posts: 284

Rep: Reputation: 30
Quote:
#iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 192.168.0.3
If you change that to use the command -i ethx (where x is the number that corresponds to your ext NIC) you should be able to see it from your int network as well.

That is at least how I did it on mine.
 
  


Reply



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
Mail Forwarding in postfix/maildrop/redhat (like yahoo mail forwarding) topcat Linux - Software 1 08-31-2007 12:10 PM
Simple Port Forwarding Firewall - not forwarding MadTurki Linux - Security 14 04-09-2006 12:08 PM
2000 MySQL connections, still "too many connections" newlinuxnewbie Linux - General 0 11-07-2005 01:03 PM
Help! Two internet connections routing + port forwarding? lakoff Linux - Networking 2 09-29-2003 06:27 AM
port forwarding and packet forwarding syrtsardo Linux - Newbie 2 07-03-2003 10:37 AM

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

All times are GMT -5. The time now is 01:28 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