0
on boot
    iptables blah --blah
    iptables blah --blah

service myservice /system/bin/myarm64binary --config /path/to/conf.cfg
    class main
    user root

According to the documentation: https://android.googlesource.com/platform/system/core/+/master/init/README.md

/ init.rc is the most important. RC file. It is loaded by init process at the time of initialization. It is mainly responsible for system initialization. It will import / init.${ro.hardware}.rc, which is the main. RC file provided by system-level core vendors.

When the mount_all statement is executed, the init process loads all files in the /{system,vendor,odm}/etc/init/ directory, which will serve Actions and Services when the file system is mounted.

Is there something I'm missing? service list does not list my app and iptables not appended. Even if I test-edit init.rc and import my .rc directly it still does nothing.

6
  • Yes, my man, you know search-fu better than me, I never got any relevant results. May be then you know why it wont exec iptables command?
    – Kirikan
    May 18 '20 at 21:32
  • 1
    Kirikan. Please edit your question by a) linking the question marked as duplicate b) focus on the specific aspect that is not covered by it c) remove aspects that are already covered in the duplicate. That would help reviewers to vote for re-open your question. Also, go through the other answers linked at the end of the duplicate to make sure your doubt isn't covered (if it is, it may get closed again as duplicate of that!)
    – beeshyams
    May 18 '20 at 21:52
  • init's .rc files aren't like shell scripts. You need to use proper formatting. Replace iptables blah --blah with exec command as explained in the official documentation you linked. Also take care of SELinux context as explained in the question marked as duplicate. Also set proper file permissions on file. Btw settings iptables rules on boot isn't of much use. They may get reset by netd on network events. May 18 '20 at 23:16
  • Yeah, thanks man, was just re-reading your old answer, it was tremendous help. What are my options to make sure my iptables rules are kept? Catch some netd events somehow? Right now wifi on/off does not seems to affect it, gonna need to test VPN mode.
    – Kirikan
    May 18 '20 at 23:20
  • 1
    Much appreciated, thanks!
    – Kirikan
    May 19 '20 at 0:53