I have an application that tries to connect to 10.0.0.172. I would like these connections to be redirected to localhost. What is the best way to achieve this?
(I've just learned that /etc/hosts only works for DNS requests, and not for IP addresses.)
I think I need to write some iptables commands but I've never used those before.
You need to add a rule like this:
The above example redirect all http requests to localhost on same port 80. Of course, you can change the ports and protocol according to your needs. However, there is one more requirement that this host should be receiving this traffic to be able to redirect it (such as your gateway).
If you don't need to filter any traffic, you can just set default policy to
ACCEPT
forINPUT
.