Here, I can type this in Termux

iptables -I OUTPUT -d -j REJECT

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 but it is visiting instead. which means change the IP packet's destination IP address from to

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

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

  • 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


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 -j DNAT --to-destination

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

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

(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.