How to run .sh script (iptables commands) on start up



  • I am using LineageOS 18.1

    When I was on LOS 16, I used to edit the file /system/etc/init.d/00banner and put my iptables commands there, e.g.:

    #!/system/bin/sh
    sh -c 'iptables -A OUTPUT -m owner --uid-owner 10195 -d 203.205.255.78/23 -j REJECT'
    

    All iptables commands I put in there used to run on phone start up. But in LOS 18.1, the /system/etc/init.d/ directory was deprecated.

    1. I created and filled the custom script with the iptables commands above:

    touch /system/etc/custominit.sh
    chmod 0755 /system/etc/custominit.sh
    

    2. Then I edited /system/etc/init/hw/init.rc and I added to the end:

    chmod 0755 /system/etc/custominit
    exec /system/etc/custominit
    

    3. I also tried adding:

    service custominit /system/bin/custominit.sh
        disabled
        oneshot
    

    But none of this worked.

    What is it that I doing wrong? I have root access but I do not want to install any additional apps on my phone for this, as it was possible to do on LOS 16.



  • Issue was solved by following instructions here:

    https://ch1p.io/lineageos-run-shell-script-at-boot-as-root/

    The main issue turned out to be missing full path of executables, e.g.:

    /system/bin/iptables instead of iptables




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2