Skip to content

Instantly share code, notes, and snippets.

@pyxze
Last active December 19, 2015 17:09
Show Gist options
  • Save pyxze/5989284 to your computer and use it in GitHub Desktop.
Save pyxze/5989284 to your computer and use it in GitHub Desktop.
idempotent iptables command
REJECT_RULE_NO=$(iptables -L INPUT --line-numbers | grep 'REJECT' | awk '{print $1}'); if ! (iptables-save | grep -q -- "-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT"); then iptables -I INPUT $REJECT_RULE_NO -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT; fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment