Skip to content

Instantly share code, notes, and snippets.

@BenMorel
Forked from LouWii/iptables-config-script
Created October 17, 2019 22:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BenMorel/5b1eb2e5803ab8857fd8eaec1ad7de79 to your computer and use it in GitHub Desktop.
Save BenMorel/5b1eb2e5803ab8857fd8eaec1ad7de79 to your computer and use it in GitHub Desktop.
Bash script to configure iptables for a web server. Some rules can be removed depending on used services.
#!/bin/sh
# Empty all rules
sudo iptables -t filter -F
sudo iptables -t filter -X
# Set up default rules
sudo iptables -t filter -P INPUT DROP
sudo iptables -t filter -P FORWARD DROP
sudo iptables -t filter -P OUTPUT ACCEPT
# Authorize already established connexions
sudo iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
# Authorize loopback
sudo iptables -t filter -A INPUT -i lo -j ACCEPT
# ICMP (Ping)
sudo iptables -t filter -A INPUT -p icmp -j ACCEPT
# SSH
sudo iptables -t filter -A INPUT -p tcp --dport 22 -j ACCEPT
# HTTP
sudo iptables -t filter -A INPUT -p tcp --dport 80 -j ACCEPT
# HTTPS
sudo iptables -t filter -A INPUT -p tcp --dport 443 -j ACCEPT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment