Skip to content

Instantly share code, notes, and snippets.

@danmactough
Created December 17, 2013 15:21
Show Gist options
  • Save danmactough/8006629 to your computer and use it in GitHub Desktop.
Save danmactough/8006629 to your computer and use it in GitHub Desktop.
Block port except via localhost. Optionally, pass `-D` as second argument to remove the block.
#/bin/bash
PORT=$1
ACTION=${2:-"-A"}
iptables $ACTION INPUT -p tcp -s localhost --dport $PORT -j ACCEPT
iptables $ACTION INPUT -p tcp --dport $PORT -j DROP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment