LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 06-16-2008, 04:24 AM   #1
irey
Member
 
Registered: Jun 2008
Location: Torino, Italy
Posts: 66

Rep: Reputation: 17
iptables: how to forward ports not only from the outside world?


Hi,

I've set up the classical port 80 to 8080 redirection with iptables:
Code:
iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8080
But this will only work for connections coming from the outside world. When telneting to localhost:80 I get "connection refused" errors.

The manpage for iptables hasn't helped me
 
Old 06-16-2008, 08:40 AM   #2
eco
Member
 
Registered: May 2006
Location: BE
Distribution: Debian/Gentoo
Posts: 412

Rep: Reputation: 48
The point of routing 80 to 8080 is usualy because you have a proxy in place and you want it to be transparent to the internet users.

Why don't you just use port 8080 internaly?

If iptables is still a little cryptic you could use a tool like shorewall which will make it a lot easier to manage your firewall.

-eco
 
Old 06-16-2008, 10:37 AM   #3
irey
Member
 
Registered: Jun 2008
Location: Torino, Italy
Posts: 66

Original Poster
Rep: Reputation: 17
Using port 8080 internally is a good idea, but this implies reconfiguring lots of different applications. A simple trick with iptables would allow me to do it only once and for all
 
Old 06-16-2008, 12:23 PM   #4
javaroast
Member
 
Registered: Apr 2005
Posts: 131

Rep: Reputation: 19
I am wondering why you wouldn't just bind the (I'm assuming) web server to port 80 as well as port 8080 or set up the redirect in the web server configuration.
 
Old 06-17-2008, 03:07 AM   #5
irey
Member
 
Registered: Jun 2008
Location: Torino, Italy
Posts: 66

Original Poster
Rep: Reputation: 17
You're right that binding the web server to port 80 would be the normal thing to do. But my case is a particular one

My team of programmers is setting up a website with both apache tomcat and apache web server. For many reasons (specific to our web applications and too many to list them here) we have to use tomcat in front of apache (I know the standard thing would be the oposite), so running apache web server on port 80 would be a bad idea: users would connect directly to it without passing through tomcat. In a future setup apache web server may be moved to a different phisical host.

Tomcat can run on port 80 only with root privileges: this is a bad idea too.

My current setup is tomcat on port 8080 and apache web server on 8090, iptables redirects 80->8080. A redirection to 8090 is performed by web applications when required. Many web applications also open connections to localhost on port 80, I'd like to keep this setting for transparency reasons. But such loopback connections are not currently working
 
Old 06-17-2008, 05:59 AM   #6
irey
Member
 
Registered: Jun 2008
Location: Torino, Italy
Posts: 66

Original Poster
Rep: Reputation: 17
I finally solved it.

In addition to the previous rule the following command had to be run:
Code:
iptables -A OUTPUT -t nat -o lo -p tcp --dport 80 -j REDIRECT --to-ports 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
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 do I forward ports in a D-Link? anticuchos Linux - Networking 11 09-29-2005 06:42 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 12:27 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