I want to add an iptables rule on my Android phone. I used:

iptables -t nat -A PREROUTING -p 6 -d --dport 80 -j DNAT --to

...as root. This rule can be checked in adb shell, and I can see that it was added:

# iptables -t nat -nL
chain PREROUTING (policy ACCEPT)
prot   opt    source       destination    idletimer_nat_PREROUTING  
all    --      DNAT       
tcp    --   tcp dpt:80 to:

I want this rule to persist after a reboot, so I added an iptabless file in /etc/sysconfig with these contents:

-t nat -A PREROUTING -p 6 -d --dport 80 -j DNAT --to

However, when I reboot my phone, no rule is added.

Does Android support the /etc/sysconfig/iptables path? I got this path from a PC Linux installation ( I tested /etc/iptables/rules.v4 as well, it also did not work).

At the same time, I also don't know whether its content is right.

Additionally, I cannot root my testing phone in the future. Is it possible to add persistent iptables rules on an unrooted phone?


Running scripts at boot (init) as you are trying to do is only supported if the kernel supports it.

If you are using a stock kernel, you may need to install a custom kernel that includes init support.

There are also apps that start with Android and automatically apply firewall/iptables rules, however keep in mind these require root access.

It is not possible to modify iptables rules without root access. However, you can use a VPN connection to route network traffic which works on any Android 4.0+ device without root access.

  • could you please clarify step-by-step how to modify iptables at boot? Which file should I edit? And what add there?
    – LA_
    Oct 19 '17 at 20:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.