Skip to content

Instantly share code, notes, and snippets.

@jasonruyle
Last active February 26, 2026 08:26
Show Gist options
  • Select an option

  • Save jasonruyle/8870296 to your computer and use it in GitHub Desktop.

Select an option

Save jasonruyle/8870296 to your computer and use it in GitHub Desktop.

Revisions

  1. jasonruyle revised this gist Feb 7, 2014. 1 changed file with 6 additions and 7 deletions.
    13 changes: 6 additions & 7 deletions UFW_ban_country.md
    Original file line number Diff line number Diff line change
    @@ -8,27 +8,26 @@ http://www.ip2location.com/free/visitor-blocker
    ##Add country##
    Run the following command

    [code]
    ```
    while read line; do sudo ufw deny from $line; done < all.txt
    [/code]
    ```

    Where the filename is the country.


    ##Remove country##
    To remove or revert these rules, keep that list of IPs! Then run a command like so to remove the rules:

    [code]
    ```
    while read line; do sudo ufw delete deny from $line; done < all.txt
    [/code]

    ```

    ##Suggestion##
    What I did was exported each individual country as their own country.txt file.
    But then realized that I wanted to run this thing one time, so I ran the following command:

    [code]
    ```
    cat *.txt >> all.txt
    [/code]
    ```

    Then you can run your rule against all of the files.
  2. jasonruyle created this gist Feb 7, 2014.
    34 changes: 34 additions & 0 deletions UFW_ban_country.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    #Country ban with UFW#

    Grab your different country ip addresses and save as Linux IPTables

    http://www.ip2location.com/free/visitor-blocker


    ##Add country##
    Run the following command

    [code]
    while read line; do sudo ufw deny from $line; done < all.txt
    [/code]

    Where the filename is the country.


    ##Remove country##
    To remove or revert these rules, keep that list of IPs! Then run a command like so to remove the rules:

    [code]
    while read line; do sudo ufw delete deny from $line; done < all.txt
    [/code]


    ##Suggestion##
    What I did was exported each individual country as their own country.txt file.
    But then realized that I wanted to run this thing one time, so I ran the following command:

    [code]
    cat *.txt >> all.txt
    [/code]

    Then you can run your rule against all of the files.