Created
July 2, 2020 12:33
-
-
Save dhgouveia2/12ce6f161fda9730eb4cf68f73e9b7cd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Flush IPtables rules | |
iptables -F | |
# Ensure default deny firewall policy | |
iptables -P INPUT DROP | |
iptables -P OUTPUT DROP | |
iptables -P FORWARD DROP | |
# Ensure loopback traffic is configured | |
iptables -A INPUT -i lo -j ACCEPT | |
iptables -A OUTPUT -o lo -j ACCEPT | |
iptables -A INPUT -s 127.0.0.0/8 -j DROP | |
# Ensure outbound and established connections are configured | |
iptables -A OUTPUT -p tcp -m state --state NEW,ESTABLISHED -j ACCEPT | |
iptables -A OUTPUT -p udp -m state --state NEW,ESTABLISHED -j ACCEPT | |
iptables -A OUTPUT -p icmp -m state --state NEW,ESTABLISHED -j ACCEPT | |
iptables -A INPUT -p tcp -m state --state ESTABLISHED -j ACCEPT | |
iptables -A INPUT -p udp -m state --state ESTABLISHED -j ACCEPT | |
iptables -A INPUT -p icmp -m state --state ESTABLISHED -j ACCEPT | |
# Open inbound ssh(tcp port 22) connections | |
iptables -A INPUT -p tcp --dport 22 -m state --state NEW -j ACCEPT | |
# Add new inbound ports connections | |
# iptables -A INPUT -p <protocol> --dport <port> -m state --state NEW -j ACCEPT |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment