0

Here, I can type this in Termux

su
iptables -I OUTPUT -d 1.2.3.4 -j REJECT
iptables-save

to reject the packet so as to forbid the Application to visit a certain host. It works well.

However, now I want to make the Application thinks it is visiting 1.2.3.4 but it is visiting 5.6.7.8 instead. which means change the IP packet's destination IP address from 1.2.3.4 to 5.6.7.8

I tried many tutorials but ended up in a failure. Not working at all, the Application still visits 1.2.3.4.

Can anyone help me with this? By using iptables or any other method. My Android device is rooted with Magisk installed.

1
  • If the application uses host/dns names, you could edit your hosts file or use a local dns server to resolve those to different IP addresses
    – Cpt.Whale
    Commented Nov 16, 2022 at 16:48

1 Answer 1

1

You can do that using a destination NAT (DNAT), see here

Specifically, in your example you would do one of:

iptables -t nat -I OUTPUT -d 1.2.3.4 -j DNAT --to-destination 5.6.7.8

Of course, you would want the return packets to make the inverse translation, so it looks like the reply is coming from 1.2.3.4 again, so you need also on of these:

iptables -t nat -I INPUT -s 5.6.7.8 -j SNAT --to-source 1.2.3.4

(In the original answer I had PREROUTING/POSTROUTING instead of OUTPUT/INPUT, but that is when you are doing that in a router. For locally generated packets, OUTPUT/INPUT should be the correct one).

You must log in to answer this question.