i am starting to build a web server for a project at work and i am going from the bottom to the top. After reading a lot - watching some you tube videos etc , i came up to a script - or better a procedure to apply some starter iptables rules for a Debian 8.5 or Ubuntu 14.04 lts server.
I would love to show you the code here and get some recommendations and replies from you if i am doing something wrong or what do i have to add more so i can make the firewall act better.
My questions are:
1: Is script and procedure ok?
2: Since i am blocking by default everything on OUTPUT chain but i am leaving some ports on ACCEPT will i have any problem regarding updating my server?
3: What other implementations do i have to apply so the iptables perform better like dropping port scanners etc?
Thanks a lot for your time .
Here is the code we create with the name firewall.sh :
#!/bin/sh
#We flush all the previous rules we had in iptables
iptables -F
#Policies - We need to DROP everything
iptables -P OUTPUT DROP
iptables -P INPUT DROP
iptables -P FORWARD DROP
#Established Connections
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A OUTPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
#Loopback Authorization
iptables -A INPUT -i lo -j ACCEPT
iptables -A OUTPUT -o lo -j ACCEPT
#Ping Enable
iptables -A INPUT -p icmp -j ACCEPT
iptables -A OUTPUT -p icmp -j ACCEPT
#SSH
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 22 -j ACCEPT
#HTTP
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 80 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 443 -j ACCEPT
We need to make this script to run when server reboots:
sudo mv firewall.sh /etc/init.d
cd /etc/init.d
sudo mv firewall.sh firewall
sudo chmod +x firewall
sudo update-rc.d firewall defaults