Just a slight modification from the answer @peterh gave, for those if you don't already have the rc.local in those folders (/etc/ or /etc/rc.d/), like in Archlinux, you'll have to create your own. I did that slight bit of modification as follows:
(This is done in a systemd OS)
create a text file /etc/systemd/system/rc-local.service using whatever tool you like, I'm using vim so it'll be:
sudo vim /etc/systemd/system/rc-local.service
And then add:
[Unit]
Description=Enable /etc/rc.local
[Service]
Type=oneshot
ExecStart=/etc/rc.local start
[Install]
WantedBy=multi-user.target
After that, run:
sudo systemctl enable rc-local.service
It'll create a symlink to run the service on startup (according to one person on Archlinux forum, you don't need this command to enable it because if the file exists, the system will automatically enable it, but just in case.)
And finally you can add the rc.local script to /etc/ directory. You can read about it online and create a file of your prefrence but for the sake of simplicity I'll just use this:
sudo vim /etc/rc.local
# rc.local file
#!/bin/sh
# Enable firewall (sudo command)
ufw enable
# Must always be the last line
exit 0
Mark it as executable:
chmod +x /etc/rc.local
You can check if the file is correct and is working without having to reboot by sudo systemctl enable rc-local.service and then see its status sudo systemctl status rc-local.service if there's any indicator that the script was shutdown inactive that means the proccess was successfully executed
FYI: Now you can add any command using sudo to run on startup in rc.local , just be careful
Again this answer may be excessive but I just want to elaborate a bit more from above, you may have resolved your question by now but I'm adding this for anyone who just happen to stumble across this site and still don't know what to do.
That's it, have a great day!
sudo service ufw start