Sometimes you need to run a script on boot, for example to apply an iptables config at startup so you don’t have to run the script manually after every reboot.
You can run your script on boot in Ubuntu by adding it to the /etc/init.d/rc.local file. Follow the steps below.
1. Open the /etc/init.d/rc.local file with this command:
vim /etc/init.d/rc.local
2. Add your script that you want to run on boot, for example:
sh /home/ivan/iptables.sh
echo 'Iptable Configured!'
3. Save the file. Your script will now run on boot.
PS: These steps only work on Ubuntu. For Debian you need to run:
update-rc.d filename defaults 80
For other distributions like CentOS, Red Hat, or Fedora, please refer to their documentation.
