-
-
Save Mouad-BGD/2967844 to your computer and use it in GitHub Desktop.
iptables rules
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
| allow incoming ssh | |
| iptables -A INPUT -i eth0 -p tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT | |
| iptables -A OUTPUT -o eth0 -p tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT | |
| Allow Incoming HTTP and HTTPS | |
| iptables -A INPUT -i eth0 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT | |
| iptables -A OUTPUT -o eth0 -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT | |
| iptables -A INPUT -i eth0 -p tcp --dport 443 -m state --state NEW,ESTABLISHED -j ACCEPT | |
| iptables -A OUTPUT -o eth0 -p tcp --sport 443 -m state --state ESTABLISHED -j ACCEPT | |
| Allow Outgoing HHTP and HTTPS | |
| iptables -A OUTPUT -o eth0 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT | |
| iptables -A INPUT -i eth0 -p tcp --sport 80 -m state --state ESTABLISHED -j ACCEPT | |
| iptables -A OUTPUT -o eth0 -p tcp --dport 443 -m state --state NEW,ESTABLISHED -j ACCEPT | |
| iptables -A INPUT -i eth0 -p tcp --sport 443 -m state --state ESTABLISHED -j ACCEPT | |
| Allow Loopback Access | |
| You should allow full loopback access on your servers. i.e access using 127.0.0.1 | |
| iptables -A INPUT -i lo -j ACCEPT | |
| iptables -A OUTPUT -o lo -j ACCEPT | |
| Allow outbound DNS Lookup (recomended for mails) | |
| iptables -A OUTPUT -p udp -o eth0 --dport 53 -j ACCEPT | |
| iptables -A INPUT -p udp -i eth0 --sport 53 -j ACCEPT | |
| Allow Sendmail or Postfix Traffic | |
| iptables -A INPUT -i eth0 -p tcp --dport 25 -m state --state NEW,ESTABLISHED -j ACCEPT | |
| iptables -A OUTPUT -o eth0 -p tcp --sport 25 -m state --state ESTABLISHED -j ACCEPT | |
| iptables-save > /etc/sysconfig/iptables.filename save current rules | |
| iptables-restore < /etc/sysconfig/iptables.filename load rules | |
| service iptables save apply the change | |
| service iptables restart |
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
| -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT | |
| -A INPUT -p tcp -m tcp --dport 20 -j ACCEPT | |
| -A INPUT -p tcp -m tcp --dport 21 -j ACCEPT | |
| -A INPUT -p tcp -m tcp --dport 22 -j LOG_ACCEPT | |
| -A INPUT -p tcp -m tcp --dport 25 -j LOG_ACCEPT | |
| #-A INPUT -p tcp -m tcp --dport 43 -j ACCEPT | |
| -A INPUT -p udp -m udp --dport 53 -j ACCEPT | |
| -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT | |
| -A INPUT -p tcp -m tcp --dport 110 -j ACCEPT | |
| -A INPUT -p tcp -m tcp --dport 143 -j ACCEPT | |
| -A INPUT -p tcp -m tcp --dport 443 -j ACCEPT | |
| -A INPUT -p tcp -m tcp --dport 783 -j ACCEPT | |
| -A INPUT -p tcp -m tcp --dport 993 -j ACCEPT | |
| -A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT | |
| -A INPUT -p tcp -m tcp --dport 15883 -j ACCEPT | |
| -A INPUT -s 127.0.0.1 -j ACCEPT | |
| -A INPUT -p icmp -j icmp_packets | |
| -A INPUT -j LOG_DROP | |
| -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT | |
| -A OUTPUT -p tcp -m tcp --dport 20 -j ACCEPT | |
| -A OUTPUT -p tcp -m tcp --dport 21 -j ACCEPT | |
| -A OUTPUT -p tcp -m tcp --dport 22 -j ACCEPT | |
| -A OUTPUT -p tcp -m tcp --dport 23 -j ACCEPT | |
| -A OUTPUT -p tcp -m tcp --dport 25 -j ACCEPT | |
| #-A OUTPUT -p tcp -m tcp --dport 43 -j ACCEPT | |
| -A OUTPUT -p udp -m udp --dport 53 -j ACCEPT | |
| -A OUTPUT -p tcp -m tcp --dport 80 -j ACCEPT | |
| -A OUTPUT -p tcp -m tcp --dport 110 -j ACCEPT | |
| -A OUTPUT -p tcp -m tcp --dport 143 -j ACCEPT | |
| -A OUTPUT -p tcp -m tcp --dport 443 -j ACCEPT | |
| -A OUTPUT -p tcp -m tcp --dport 783 -j ACCEPT | |
| -A OUTPUT -p tcp -m tcp --dport 993 -j ACCEPT | |
| -A OUTPUT -p tcp -m tcp --dport 3306 -j ACCEPT | |
| -A OUTPUT -p tcp -m tcp --dport 15883 -j ACCEPT | |
| -A OUTPUT -d 127.0.0.1 -j ACCEPT | |
| -A OUTPUT -p icmp -j icmp_packets | |
| -A OUTPUT -j LOG_DROP | |
| -A LOG_DROP -j LOG --log-prefix "[IPTABLES DROP] : " --log-tcp-options --log-ip-options | |
| -A LOG_DROP -j DROP | |
| -A LOG_ACCEPT -j LOG --log-prefix "[IPTABLES ACCEPT] : " --log-tcp-options --log-ip-options | |
| -A LOG_ACCEPT -j ACCEPT |
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
| http://www.thegeekstuff.com/2011/06/iptables-rules-examples/ | |
| https://help.ubuntu.com/community/IptablesHowTo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment