user2033139
user2033139

Reputation: 583

Redirect outgoing connection to localhost

Is it possible to redirect outgoing connection back to localhost using iptables?

For example, if php script requests someonlinesite.com/bla.php then it would redirect to 127.0.0.1/bla.php

OS: Debian 7

Upvotes: 1

Views: 3358

Answers (3)

user2033139
user2033139

Reputation: 583

Thank you for replies, i managed to do it with hosts file. /etc/hosts

127.0.0.1 domain.com

Now it redirects always to localhost when script tryes to reach domain.com

Upvotes: 0

giusc
giusc

Reputation: 103

try with:

iptables -t nat -A OUTPUT -d 0/0 -p tcp --dport 80 -j DNAT --to-destination 127.0.0.1:80

Upvotes: 0

arkascha
arkascha

Reputation: 42885

The question does not really make much sense the way it currently is asked.

Most likely you are trying to redirect a http request? Then you should take a closer look at your systems name resolution, since that is the step that translates the host name someonlinesite.com to an ip address. So that is where you want to manipulate.

You might also want to consider using a proxy as an alternative. But a pure iptables based solution is questionable, since in typical setups the local http server will not react to incoming requests to a remote ip address...

Upvotes: 1

Related Questions