LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 12-12-2009, 03:41 PM   #1
angle2009
Member
 
Registered: Mar 2007
Location: Egypt
Distribution: Ubuntu 11.10 x86_64
Posts: 80

Rep: Reputation: 15
Redirect http requests


i wanna redirect every http requests in my network to my http server which is equipped with a simple html page "index.html"

what i did is to check that my httpd service is on and i tested index.html using the browser

and i added a rule in iptables as following :

Code:
iptables -t nat -A PREROUTING -p tcp -s 10.0.0.0/24 --sport 1024:  -d 0/0 --dport 80 -j DNAT --to-dest 10.0.0.5:80
and i tested that scheme from another pc in the network but in vain

so what is the problem !

thanks in advance
 
Old 12-12-2009, 06:27 PM   #2
nimnull22
Senior Member
 
Registered: Jul 2009
Distribution: OpenSuse 11.1, Fedora 14, Ubuntu 12.04/12.10, FreeBSD 9.0
Posts: 1,571

Rep: Reputation: 92
How about something like this:

iptables -t nat -A PREROUTING -p tcp --dst<GW IP or INET> --dport 80 -j DNAT --to-destination 10.0.0.5:80

Or without destination:

iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 10.0.0.5:80

I'm not sure that it will work, but you can try

Last edited by nimnull22; 12-12-2009 at 06:34 PM.
 
Old 12-12-2009, 06:34 PM   #3
Web31337
Member
 
Registered: Sep 2009
Location: Russia
Distribution: Gentoo, LFS
Posts: 399
Blog Entries: 71

Rep: Reputation: 65
there is also a way to reverse-proxy HTTP requests. like nginx does.
it is the only solution when you want to balance the load between 2+ servers. of course, iptables is perfect for one. just made this note for you, maybe you will need that in future.
 
Old 12-13-2009, 01:56 PM   #4
angle2009
Member
 
Registered: Mar 2007
Location: Egypt
Distribution: Ubuntu 11.10 x86_64
Posts: 80

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by nimnull22 View Post
How about something like this:

iptables -t nat -A PREROUTING -p tcp --dst<GW IP or INET> --dport 80 -j DNAT --to-destination 10.0.0.5:80

Or without destination:

iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 10.0.0.5:80

I'm not sure that it will work, but you can try
i tried this rule but actually it didn't work
by the way this machine isn't the server in the network but i enabled ip_forward
and i have a router in my network

should this rule work in that situation ?
 
Old 12-13-2009, 02:15 PM   #5
nimnull22
Senior Member
 
Registered: Jul 2009
Distribution: OpenSuse 11.1, Fedora 14, Ubuntu 12.04/12.10, FreeBSD 9.0
Posts: 1,571

Rep: Reputation: 92
Do http requests go through that computer?

It should be a GW in that network, otherwise how are you going to catch http requests, and redirect them?
 
Old 12-18-2009, 04:52 PM   #6
angle2009
Member
 
Registered: Mar 2007
Location: Egypt
Distribution: Ubuntu 11.10 x86_64
Posts: 80

Original Poster
Rep: Reputation: 15
Quote:
Originally Posted by nimnull22 View Post
Do http requests go through that computer?

It should be a GW in that network, otherwise how are you going to catch http requests, and redirect them?
i thought that if i enabled ip_forward parameter so i can catch http requests and redirect them via my iptables
anyway i took the GateWay ip and disconnected the router but the same problem still exits
 
Old 12-18-2009, 05:08 PM   #7
nimnull22
Senior Member
 
Registered: Jul 2009
Distribution: OpenSuse 11.1, Fedora 14, Ubuntu 12.04/12.10, FreeBSD 9.0
Posts: 1,571

Rep: Reputation: 92
Quote:
Originally Posted by angle2009 View Post
i thought that if i enabled ip_forward parameter so i can catch http requests and redirect them via my iptables
anyway i took the GateWay ip and disconnected the router but the same problem still exits
Any computers in the network send their packets to GW, then GW sends them to internet. It is not so easy to replace one with other.
 
  


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
Redirect outgoing http requests with IPtables highllamas Linux - Security 1 06-17-2009 08:07 AM
How do you properly redirect all web client requests from http to https? mehoggan Linux - Server 4 06-02-2009 03:49 AM
redirect all http requests to a different squid proxy server r2d2#jedi Linux - Networking 1 05-27-2009 12:31 AM
http relay - tracking http requests wastingtime Linux - Server 2 04-28-2009 06:05 PM
redirect some http requests to port 443. FMH Linux - Software 5 09-17-2007 08:19 AM

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

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