Skip to content

Instantly share code, notes, and snippets.

@webpepper
Last active January 15, 2020 14:53
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 webpepper/4fdeeb47c6c9ba9fa890af0ad95e1bf6 to your computer and use it in GitHub Desktop.
Save webpepper/4fdeeb47c6c9ba9fa890af0ad95e1bf6 to your computer and use it in GitHub Desktop.
Block an IP with iptables

Block an IP

Use a real IPv4 instead of x.x.x.x

This will add the block rule to the beginning of the list moving (not overwriting) everything else down.

sudo /sbin/iptables -I INPUT 1 -s x.x.x.x -j DROP

View IP rules

sudo /sbin/iptables -L --line-numbers

Delete a rule

Get the line number (let's call it $line_number) from the previous step (View IP rules).

sudo /sbin/iptables -D INPUT $line_number
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment