LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 11-09-2009, 06:09 AM   #1
gubak
Member
 
Registered: Jul 2004
Posts: 332

Rep: Reputation: 30
How to route port 80 to another ip


Hi!

I have a LAN with a linux server (CentOS 5.4 connected to internet on PPP)
I want to route port 80 on linux server to another machine on the LAN. So my webserver is on another machine on LAN.
Steps I've already made:

Changed Apache port from 80 to 8080 on linux server (on httpd.conf file)
Restarted Apache (service httpd restart)
Switched off iptables (service iptables stop)
Enter the following 4 rows on consol:
Code:
sysctl -w net.ipv4.ip_forward=1
iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
iptables -t nat -A PREROUTING -i ppp0 -p tcp -m tcp --destination-port 22 -d x.x.x.x -j DNAT --to-destination 5.2.2.231
iptables -t nat -A PREROUTING -i ppp0 -p tcp -m tcp --destination-port 80 -d x.x.x.x -j DNAT --to-destination 5.2.2.231


5.2.2.231 is my web server's ip inside of my LAN.
The webserver works, I can see website inside my LAN if I type 5.2.2.231 into the browser, but If I want to reach the website through my public IP , I cant!

Can somebody tell me what can be the problem?
 
Old 11-09-2009, 06:33 AM   #2
vishesh
Member
 
Registered: Feb 2008
Distribution: Fedora,RHEL,Ubuntu
Posts: 661

Rep: Reputation: 66
On which interface you public ip is configured.
Do you started iptables after iptables entries? I mean instead of stopping iptables, just Flush its contents using following command
iptables -F
then do your iptables entries. After that save iptables configuration using command
service iptables save

Thanks
 
Old 11-09-2009, 07:11 AM   #3
gubak
Member
 
Registered: Jul 2004
Posts: 332

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by vishesh View Post
On which interface you public ip is configured.
Do you started iptables after iptables entries? I mean instead of stopping iptables, just Flush its contents using following command
iptables -F
then do your iptables entries. After that save iptables configuration using command
service iptables save

Thanks

My public ip is configured on ppp0 interface.
I not started iptables after iptables entries. So iptables is stopped!
 
Old 11-11-2009, 02:47 AM   #4
vishesh
Member
 
Registered: Feb 2008
Distribution: Fedora,RHEL,Ubuntu
Posts: 661

Rep: Reputation: 66
To implement iptables rules, you must start iptables

thnks
 
Old 11-11-2009, 03:35 AM   #5
gubak
Member
 
Registered: Jul 2004
Posts: 332

Original Poster
Rep: Reputation: 30
Quote:
Originally Posted by vishesh View Post
To implement iptables rules, you must start iptables

thnks
I was started iptables, but prerouting still don't work.

Here is my iptables:

First iptables -L:

Code:
Chain INPUT

target  prot opt source     destination
ACCEPT  all  --  anywhere   anywhere
ACCEPT  tcp  --  anywhere   anywhere          tcp dpt: 80
ACCEPT  tcp  --  anywhere   anywhere          tcp dpt: 8080


other chains are empty

iptables -t nat -L

Code:
Chain PREROUTING

target   prot  opt  source     destination
DNAT     tcp   --   anywhere   x.x.x.x            tcp dpt:http to: 5.2.2.231


Chain POSTROUTING
target       prot  opt  source     destination
MASQUERADE   all   --   anywhere   anywhere

other chains are empty

x.x.x.x is my static ip on the linux server.
 
Old 11-12-2009, 05:38 AM   #6
vishesh
Member
 
Registered: Feb 2008
Distribution: Fedora,RHEL,Ubuntu
Posts: 661

Rep: Reputation: 66
does Ip forwarding option in on on your server ?

thnks
 
Old 11-12-2009, 05:51 AM   #7
gubak
Member
 
Registered: Jul 2004
Posts: 332

Original Poster
Rep: Reputation: 30
If you mean "net.ipv4.ip_forward=1", then yes ip forwarding is on!
 
Old 11-12-2009, 08:36 AM   #8
mrlinux2000
Member
 
Registered: Feb 2008
Posts: 144

Rep: Reputation: 15
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT --to 192.168.**.**:8080
this will solve it
 
  


Reply


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
no route to host on port 25 brockangelo Linux - Newbie 24 09-04-2008 12:43 AM
IP tables -- re route a port Dan8080 Linux - Newbie 2 06-07-2006 11:43 PM
Is it not possible to route incomming port to another external port? ziggie216 Linux - Software 5 12-03-2005 06:16 PM
route locally generated traffic to ip:port to localhost:port maenho Linux - Software 2 03-11-2005 04:08 AM
Port 25: No route to host dhruv Linux - Newbie 0 04-03-2004 09:37 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

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