Since 15.04 Ubuntu version it uses systemd as a startup daemon. Here is how to make a script run during system startup. You need two files to make it happen. First is your script file, for example iptables.sh bash script that sets firewall rules and the second is so called service file.
[Unit]
Description=Iptables firewall
[Service]
Type=oneshot
ExecStart=/usr/lib/systemd/scripts/iptables.sh
[Install]
WantedBy=multi-user.target
sudo systemctl enable iptables_sh.service
From now then the script will be executed during system startup.
In case your script is parameterized with start/stop arguments, ex.:
start() {
command_1;
command_2;
...
}
stop() {
command_3;
command_4;
...
}
case $1 in
start|stop) "$1" ;;
esac
then your service file should look like below:
[Unit]
Description=Iptables firewall
[Service]
Type=oneshot
ExecStart=/usr/lib/systemd/scripts/iptables.sh start
ExecStop=/usr/lib/systemd/scripts/iptables.sh stop
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target