Skip to content

Instantly share code, notes, and snippets.

@Hyunho
Last active October 29, 2015 08:43
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 Hyunho/46b9f1b72bfa1f25a56e to your computer and use it in GitHub Desktop.
Save Hyunho/46b9f1b72bfa1f25a56e to your computer and use it in GitHub Desktop.
iptables_rule(only allow ssh connection)
# using firewalld utility
firewall-cmd --direct --add-rule ipv4 filter INPUT 0 -p tcp -m tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
firewall-cmd --direct --add-rule ipv4 filter OUTPUT 0 -p tcp -m tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT
firewall-cmd --direct --add-rule ipv4 filter OUTPUT 1 -p tcp -m multiport --dports 200:65535 -j DROP
#!/bin/bash
# Only allow ssh connection.
# And boud a specific destnation range ports(200~65535) to block unhappy connection
# clear iptables
sudo iptables -F
# set policy
sudo iptables -A INPUT -p tcp -m tcp --dport 22 -m state --state NEW,ESTABLISHED -j ACCEPT
sudo iptables -A OUTPUT -p tcp -m tcp --sport 22 -m state --state ESTABLISHED -j ACCEPT
sudo iptables -A OUTPUT -p tcp -m multiport --dports 200:65535 -j DROP
# list
sudo iptables -L
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment