Solved

Redirecting IP from local network (iptables)

Posted on 2004-03-22
11
2,177 Views
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 10.10.2.3)  using http protocol to another web site.

Thank you in advance.
0
Comment
Question by:Murdoc
  • 7
  • 4
11 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 10652702
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j DNAT   --to 10.10.2.3
iptables -A INPUT  -i eth0 -p tcp --dport 30 -j ACCEPT  -d  10.10.2.3
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

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

Author Comment

by:Murdoc
ID: 10656715
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 10.10.2.3 -p tcp --dport 80 -j DNAT   --to 212.33.84.236:80

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

Regards
0
 

Author Comment

by:Murdoc
ID: 10656739
....or....: iptables -t nat -A PREROUTING -i eth1 -s 10.10.2.3 -p tcp --dport 80 -j DNAT   --to 212.33.84.236:80


...have no idea ...just need to redirect user that do not pay for internet:)
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 10658645
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
0
 

Author Comment

by:Murdoc
ID: 10661121
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.

Regards


P.S. Believe me i'm newbie :)
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 51

Expert Comment

by:ahoffmann
ID: 10661933
> .. 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?
0
 

Author Comment

by:Murdoc
ID: 10662113
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.

Regards
0
 

Author Comment

by:Murdoc
ID: 10662224
Example:

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


:)
0
 

Author Comment

by:Murdoc
ID: 10662269
wrong example above ..sorry i was in hurry

example:

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

:+}
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 125 total points
ID: 10665046
this is not a iptables job
either simply change your DNS, or add yahoo.com with IP of google.com in your hosts file

> Another words it make no sense to use proxy to redirect only one local host.
why do you make a rule effecting all traffic, when it only should be for one host? That's what a proxy is for.
0
 

Author Comment

by:Murdoc
ID: 10672122
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

Regards
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

​Being a Managed Services Provider (MSP) has presented you  with challenges in the past— and by meeting those challenges you’ve reaped the rewards of success.  In 2014, challenges and rewards remain; but as the Internet and business environment evol…
Hello EE, Today we will learn how to send all your network traffic through Tor which is useful to get around censorship and being tracked all together to a certain degree. This article assumes you will be using Linux, have a minimal knowledge of …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now