We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


Redirecting IP from local network (iptables)

Murdoc asked
Medium Priority
Last Modified: 2010-04-22
Hi everyone.

I'm looking for help with iptables and redirecting. I have local network with NAT.  I'd like to redirect  computer ( for example  using http protocol to another web site.

Thank you in advance.
Watch Question

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT   --to
iptables -A INPUT  -i eth0 -p tcp --dport 30 -j ACCEPT  -d
iptables -A INPUT  -i eth1 -j ACCEPT
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

# assuming that your internet NIC is eth0, and the LAN NIC is eth1

> .. redirecting .. to another web site.
are you shure you need to do it on IP-level, or is it more a application-level issue?


Your example shows how to redirect computer from internet to local network but i'm looking for something opposite.
For example:

Computer from local network wants to reach for instance http://google.com and I want to redirect this computer ( from local network) to http://admf.eu.org which is not in local network but in Internet.

So it would look similar to :  
iptables -t nat -A PREROUTING -s -p tcp --dport 80 -j DNAT   --to

....but I'm almost sure that in example above something's wrong  :)



....or....: iptables -t nat -A PREROUTING -i eth1 -s -p tcp --dport 80 -j DNAT   --to

...have no idea ...just need to redirect user that do not pay for internet:)
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE


I'm newbie to linux but I think that what you wrote above isn't what I want to do.
I want to redirect local IP with destination port 80 to external IP on port 80.


P.S. Believe me i'm newbie :)
> .. redirect local IP with destination port 80 to external IP on port 80.

you mean that you connect from a local host to another local server on port 80, and this should be redirected to an external server?

trying ASCII art

+-- router(with iptables) ---- external:80
+-- server:80
+-- host (connecting to server:80)
+-- other host

If so, iptables might be the wrong place to do it
Why not using a proxy on the host?


Actually my local network is small that's why I'm not using proxy. I know how to redirect ( i've found example) external IP to local host (forward) but have no idea how to forward  local host to to external host on http protocol. Another words it make no sense to use proxy to redirect only one local host.




localhost request: 'http://google.com'->server(iptables)->if protocol http from localhost then
redirect to 'http://yahoo.com'



wrong example above ..sorry i was in hurry

example: request: 'http://google.com'
server ( with iptables: if request from and protocol is http then redirect to 'http://yahoo.com'

Unlock this solution with a free trial preview.
(No credit card required)
Get Preview


Ipchains  is useless in this case as well??
 I've been always thinking that proxy is used when there are many computers in local network to accelerate http protocol.

Anyway tomorrow i wil close this question and give you the points

Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.