I am installing a fresh new VPS (from linode.com, if that matters) with Ubuntu 16.04 LTS. I wrote the following script for iptables:
#!/bin/sh iptables -F iptables -P INPUT DROP iptables -P OUTPUT DROP iptables -P FORWARD DROP iptables -A INPUT -i eth0 -p tcp -m multiport --dports 22,80,443 -m state --state NEW,ESTABLISHED -j ACCEPT iptables -A OUTPUT -o eth0 -p tcp -m multiport --sports 22,80,443 -m state --state ESTABLISHED -j ACCEPT iptables -A OUTPUT -p udp -o eth0 --dport 53 -j ACCEPT iptables -A INPUT -p udp -i eth0 --sport 53 -j ACCEPT iptables -A INPUT -i lo -j ACCEPT iptables -A OUTPUT -o lo -j ACCEPT iptables -A INPUT -j DROP iptables -A OUTPUT -j DROP iptables -A FORWARD -j DROP
This script should only allow 22, 80 and 443. It also allows outgoing DNS resolves.
I created and named this script
iptables.sh as root and put it in
/etc/network/if-pre-up.d. I did also
Now, after reboot, this script does not seem to be applied. I verified this by executing
iptables -S, which gives:
-P INPUT ACCEPT -P FORWARD ACCEPT -P OUTPUT ACCEPT
How do I progress from here? I am quite stuck right now.
I have no idea why, but after renaming
iptables, I cannot log in into my server anymore after a reboot. This makes me think that now the script is actually executed (and when it has
.sh file extension not, why?) during boot and there is an error in my script. I am so confused.