LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 08-29-2008, 12:43 AM   #1
timgerr
LQ Newbie
 
Registered: Feb 2004
Location: Michigan
Distribution: Debian
Posts: 27

Rep: Reputation: 15
forward ports with iptables


Hello all,
I am in need of some help. When a request comes into my server on port 80, I would like the request to be forward to port 5223. When the information leaves the server via 5223 I would like it to go out port 80. Can someone show me in iptable speak what that looks like?

Thanks,
timgerr
 
Old 08-29-2008, 03:31 PM   #2
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
It would be something like this. The reverse direction is handled automatically.
Code:
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to-destination :5223
 
Old 08-29-2008, 05:14 PM   #3
fberbert
LQ Newbie
 
Registered: May 2004
Location: Brazil
Distribution: Debian
Posts: 7

Rep: Reputation: 0
In addition, if the origin packet comes from the destination server (what I consider improbable), you can try:

iptables -t nat -A OUTPUT -i eth0 -p tcp --dport 5223 -j DNAT --to-destination :80

I often use this rule to access my remove ssh server, that runs on port 22022:

iptables -t nat -A OUTPUT -p tcp -m tcp -d my.remote.host --dport 22 -j DNAT --to my.remove.host:22022

So I can just type:

ssh my.remote.host

Instead of:

ssh -p 22022 my.remote.host
 
  


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
iptables: how to forward ports not only from the outside world? irey Linux - Networking 5 06-17-2008 05:59 AM
how? redirect apache2 outbound ports to specific ports w/iptables? nowshining Linux - Security 5 05-27-2008 02:46 AM
How can I forward ports with IPtables? I want to forward 80 to 8080 abefroman Linux - Networking 3 05-23-2008 10:05 AM
Configure iptables to forward ports to an internal server ikaro_tatsomura Linux - Networking 1 02-08-2007 06:45 PM
How to forward ports with iptables? Electrode Linux - Networking 3 11-12-2002 12:04 AM

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

All times are GMT -5. The time now is 06:46 AM.

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