LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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-26-2007, 02:37 AM   #1
sanjibgupta
Member
 
Registered: Apr 2003
Location: Kolkata
Posts: 215

Rep: Reputation: 30
http port forwarding


Hi
I have redhat linux running on a pc with 2 cards
eth0 -> 203.197.xxx.xx
eth1 -> 202.141.xxx.28 netmask 255.255.255.248
both are live ip.

I need to send all request from the internet to port 80 and 443 of card eth0 to a machine (202.141.xxx.26) in the network of eth1 internally.

Please let me know how to do it (no firewall runs on this machine).

I have tried to use DNAT but I am new to it couldnot configure it. It will kind of any one it they can generate a script.
Thanks
Sanjib Gupta
 
Old 04-26-2007, 06:39 AM   #2
sanjibgupta
Member
 
Registered: Apr 2003
Location: Kolkata
Posts: 215

Original Poster
Rep: Reputation: 30
i have added DNAT iptables status show
Table: nat
Chain PREROUTING (policy ACCEPT)
target prot opt source destination
DNAT tcp -- anywhere anywhere tcp dpt:http to:202.141.xxx.26:80
DNAT tcp -- anywhere anywhere tcp dpt:http to:202.141.xxx.26:80

Chain POSTROUTING (policy ACCEPT)
target prot opt source destination



but now when i try to access the http port(203.xxx.xxx.10) (from any other machine) it reply after much time as ERROR
but if i can directly do http to targeted ip(forwarded) from the machine(203.xxx.xxx.10) i can see the webpage.

Sanjib Gupta
 
Old 04-27-2007, 01:02 PM   #3
jrmann1999
Member
 
Registered: Feb 2001
Location: Texas
Distribution: Slackware, Mandrake, LFS
Posts: 306

Rep: Reputation: 30
You have asynchronous routing in place. Here's an example of the packet flow:


1. Packet comes into machine destined for port 80.
2. DNAT rule is matched immediately, setting the new destination to 202.141.xxx.26:80, source is untouched.
3. Packet is routed(assuming forwarding is enabled) to 204.141.xxx.26:80
4. Assuming 204.141.xxx.26 doesn't have it's default gateway set to this machine, the packet returns via the internet, never hitting this box again.

Now, sometimes this is acceptable, however since whatever is listening on port 80 will inevitably fork to another random port, your two machines will communicate directly bypassing your linux box.

To correct this, you need to rewrite the source address after the DNAT so that the packet will come back to your linux box, something like:
Code:
iptables -t nat -A POSTROUTING -o <interface> -p tcp -d 202.141.xxx.26 --dport 80 -j SNAT --to <ip of interface>
 
  


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
IPCHAINS port forwarding and IPTABLES port forwarding ediestajr Linux - Networking 26 01-14-2007 07:35 PM
http port forwarding: outside network not working sharathg786 Linux - Networking 2 08-12-2006 11:37 PM
Simple Port Forwarding Firewall - not forwarding MadTurki Linux - Security 14 04-09-2006 12:08 PM
iptables - http port forwarding kevsco77 Linux - Newbie 2 01-23-2005 11:34 PM
belkin router http port forwarding illtbagu Linux - Networking 3 08-16-2003 02:44 PM

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

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