3

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

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

...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    --     0.0.0.0/0    0.0.0.0/0      DNAT       
tcp    --     0.0.0.0/0    192.168.66.1   tcp dpt:80 to:192.168.66.1:8080

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 192.168.66.1 --dport 80 -j DNAT --to 192.168.66.1:8080

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?

0

1 Answer 1

1

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.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .