Skip to content

Instantly share code, notes, and snippets.

@gene1wood
Created November 15, 2013 18:56
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 gene1wood/7489673 to your computer and use it in GitHub Desktop.
Save gene1wood/7489673 to your computer and use it in GitHub Desktop.
Script to delete an iptables rule inserted by knockd based on an IP address
#!/bin/bash
# This script is called by knockd and configured in the knockd.conf : https://gist.github.com/gene1wood/7489372
if [ -z "$1" ]; then
echo "usage : $0 IPADDRESS"
exit 1
fi
num="`iptables --list INPUT -n --line-numbers | awk '$13 == "knockd" {print $0}' | awk -v IP=$1 '$5 == IP {print $1}' | head -1`"
if [ -n "$num" ]; then
iptables -D INPUT $num
else
echo "Couldn't find IP $1"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment