Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 06-07-2006, 12:47 AM   #1
LQ Newbie
Registered: Jun 2006
Distribution: CentOS 4.3
Posts: 25

Rep: Reputation: 15
IP tables -- re route a port


I'm looking to re-route connections coming into port 80, to actually go to 81. What I do now is:

I have two apaches. One setup on 80, one on 81. The 80 one contains a mod_rewrite condition that accepts the request, then rides the person onto the 81.

RewriteEngine On
RewriteRule (.*) h_t_t_p://%{HTTP_HOST}:81/$1

That's my code. Works fine, but... someone said I could use this instead:

iptables -t nat A PREROUTING -p tcp --dport 80 -j DNAT --to-destination webserver-ip-address:81

This is the code I was given. However, it doesn't work when I enter it. I just get "Bad arguement 'A'" when I put it in the termial. Also for destination web server IP address, what do I put, my router IP or the actual IP, and what does this do exactly?

Thanks for your time,
Old 06-07-2006, 02:17 AM   #2
Registered: Aug 2005
Distribution: Debian, Ubuntu, Fedora
Posts: 74

Rep: Reputation: 15

you have replaced "-A" with "A" only, (without dash).

I use this to forward ports as following:
iptables -t nat -A PREROUTING -d -p tcp --dport 80 -j DNAT --to-destination
where is my server IP address.
and it is working.

just a reminder: ports 80 and 81 must be allowed in your INPUT chain.
hope this help

Last edited by dimsh; 06-07-2006 at 02:19 AM.
Old 06-07-2006, 11:43 PM   #3
LQ Newbie
Registered: Jun 2006
Distribution: CentOS 4.3
Posts: 25

Original Poster
Rep: Reputation: 15

Thanks, but for some reason it does not work, or I did not do it correctly.

Apache is listening on port 80 and 81.

When I added that, and had a friend download a file from 80, it was going at 15kb/sec (this is the cap by my ISP), however, when downloading at 81 after adding the code it was 300kb/sec.

Why does my port 80 download so slow compared to my 81? It's my ISP. They have a cap on port 80 but not other ports.

This is the reason I wish to redirect the port. Don't know if it's possible.


edit: Ok, I fixed the problem by adding a virtual host for port 80. But I'm still interested in this way now, if its possible I'd like to learn how to still add it. Thanks.

Last edited by Dan8080; 06-07-2006 at 11:47 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Is it not possible to route incomming port to another external port? ziggie216 Linux - Software 5 12-03-2005 06:16 PM
IP Route/IP Tables depam Linux - Networking 2 10-12-2005 02:10 PM
how to route internal Networks by IP tables? quazidaniel Linux - Networking 4 10-12-2005 10:32 AM
IP tables, forwarding port 25 bsherwood Linux - Networking 6 03-19-2005 05:20 PM
route locally generated traffic to ip:port to localhost:port maenho Linux - Software 2 03-11-2005 04:08 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 08:11 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration