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 03-16-2005, 03:52 AM   #1
QAR
LQ Newbie
 
Registered: Feb 2005
Posts: 2

Rep: Reputation: Disabled
Port forwarding


Hi There,

I'm a newbie to linux and would like someone to help with the following issue.

I have a web application running on my server. This application uses port 8080. I would like to set up the server so that the server accepts requests on port 80 and forwards them to port 8080.

I'm running Redhat 9.0 and JBoss.

Thanking you in advance.
 
Old 03-16-2005, 04:18 AM   #2
Ephracis
Senior Member
 
Registered: Sep 2004
Location: Sweden
Distribution: Ubuntu, Debian
Posts: 1,109

Rep: Reputation: 50
Oh my god. Yes, I am sorry. I was too tired and forgot to change the code I only copied.

Anyway. The table should be NAT as I said (but did not use in the code :P) and then PREROUTING. The rule applied should be REDIRECT.

Here is a working shell script. Just make it executable and put it into the rc.d-dir or some other place to make it start on boot.

Code:
#!/bin/sh

# flush tables
iptables -F
iptables -Z

# drop on default
iptables -P INPUT DROP

# redirect port 80 to 8080
iptables -t nat -A PREROUTING -p tcp --dport 80 --to-ports 8080 -j REDIRECT

# established connections
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
Maybe you don't want (or need) to set default to drop all packages but I was just assuming now. Anyway, it is much easier to let all the iptables-commands be in one file instead of typing them.

Check out the man for more info. iptables is kinda big and there are several great books on the subject. Unfortenly I can only recommend swedish books. :P

If you want to redirect to another host use the [b]--destination[b] flag.

Last edited by Ephracis; 03-16-2005 at 06:41 AM.
 
Old 03-16-2005, 05:44 AM   #3
linuxxed
Member
 
Registered: Feb 2004
Posts: 273

Rep: Reputation: 30
Quote:
Originally posted by MezzyMeat
iptables -A INPUT -s 0/0 -p tcp --dport 8080 --sport 80 -j ACCEPT
??

Iptables line should be "REDIRECT" in "PREROUTING" chain on NAT table.

iptables -t NAT -A PREROUTING -m tcp -p tcp --dport 80 --to-ports 8080 -j REDIRECT


Note: DNAT is done in OUTPUT or PREROUTING chain. SNAT is done in POSTROUTING chain. The above iptables entry is a "type of DNAT".


Another way is to set up a tunnel from 80 to 8080.
 
  


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
Simple Port Forwarding Firewall - not forwarding MadTurki Linux - Security 14 04-09-2006 12:08 PM
Port 80 forwarding to port 22 with iptables zahoo Linux - Networking 3 02-22-2005 07:22 AM
Port Forwarding sfichera Linux - Networking 2 07-22-2004 12:28 PM
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 06:50 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