{"id":22196693,"url":"https://github.com/parmaster/geoblock","last_synced_at":"2026-03-19T22:03:51.985Z","repository":{"id":169514385,"uuid":"620953949","full_name":"parMaster/geoblock","owner":"parMaster","description":"Convenient way to block countries by IP with ipset, iprange and iptables. Only couple iptables rules are added, which is easily revertable. Run services to keep geoblock persistent","archived":false,"fork":false,"pushed_at":"2024-03-19T23:56:59.000Z","size":134,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-30T02:14:14.968Z","etag":null,"topics":["block-ip-country","country-blocker","firewall","firewall-automation","firewall-configuration","firewall-rules","ipset-data","ipset-rules","ipsets","iptables","iptables-rules"],"latest_commit_sha":null,"homepage":"","language":"Makefile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/parMaster.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-03-29T17:43:09.000Z","updated_at":"2024-04-28T15:53:25.000Z","dependencies_parsed_at":"2023-11-12T01:26:21.221Z","dependency_job_id":"121273fd-2ba5-48c0-9226-3e762538f567","html_url":"https://github.com/parMaster/geoblock","commit_stats":null,"previous_names":["parmaster/geoblock"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parMaster%2Fgeoblock","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parMaster%2Fgeoblock/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parMaster%2Fgeoblock/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/parMaster%2Fgeoblock/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/parMaster","download_url":"https://codeload.github.com/parMaster/geoblock/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245366207,"owners_count":20603438,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["block-ip-country","country-blocker","firewall","firewall-automation","firewall-configuration","firewall-rules","ipset-data","ipset-rules","ipsets","iptables","iptables-rules"],"created_at":"2024-12-02T14:16:08.517Z","updated_at":"2026-01-06T04:36:16.518Z","avatar_url":"https://github.com/parMaster.png","language":"Makefile","readme":"\u003e [!CAUTION]\n\u003e Use at your own risk, make sure you have alternative ways to access your server before making changes to firewall (like KVM etc.).\n\nIt is basically a convenient way to block countries by IP with iptables. Step-by-step instructions are combined into one Makefile to compile and optimize multiple ip blocks. Only three iptables rule added as a result, which is easily revertable. Two systemd services run at system startup and load ip lists to keep geoblock persistent.\n\n## Prerequisites\n\nLoad countries IP ranges in CIDR format to the `lists/` folder (see `make load \u003ccountry code\u003e` instructions). Multiple lists will be automatically combined and optimized. Remember to update lists from time to time.\n\nInstall `iprange` and `ipset` with:\n\n\tsudo apt install -y iprange ipset\n\n## Installation\n\n`make load \u003ccountry code\u003e [\u003ccountry code\u003e \u003ccountry code\u003e ...]` will load lists of IP ranges for specific countries from the [herrbischoff/country-ip-blocks](https://github.com/herrbischoff/country-ip-blocks) repository and save into `lists` directory. For example, to load usual suspects:\n\n\tmake load ru cn by\n\n`make add` will copy everything where it supposed to be and start services: \n\n\tsudo make add \n\nTo check services status:\n\n\tsudo make status\n\nOnly one iptables rule is added as a result. To delete geoblock rule from iptables:\n\n\tsudo make cleanup\n\nTo update lists:\n\n\tmake load \u003ccountry code\u003e [\u003ccountry code\u003e \u003ccountry code\u003e ...]\n \tsudo make update\n\nTo uninstall - stop and remove services, iptables rule and ipset list:\n\n\tsudo make uninstall\n\n## How it works\n\nAfter combining and optimizing every list from `lists` folder into one `geoblock.txt` file, new `geoblock` list is created with `ipset`, then every line from `geoblock.txt` is put into that list, finally the list is saved to `/etc/ipset.conf` file.\n\nThen there are two systemd services:\n\n- `ipset-persistent.service` is configured so it starts at the right time in server startup sequence and loads `/etc/ipset.conf`, so `geoblock` set is loaded and ready to be used by iptables.\n- `geoblock-persistent.service` starts next and runs a script that sets up a firewall rule to block incoming traffic from IP addresses listed in the `geoblock` set, log the blocked attempts up to a limit, and then drop the packets.\n\n## Logging blocked packets\nBlocket packets are logged to syslog by default.\nTo log blocked packets to the separate log file, use the following rsyslog configuration file `/etc/rsyslog.d/20-geoblock.conf`:\n\n```conf\n# Geoblock generated log messages to file\n:msg,contains,\"geoblock: \" /var/log/geoblock.log\n\u0026 stop\n```\n\nLogrotate configuration could be useful as well \n`/etc/logrotate.d/geoblock`:\n\n```conf\n/var/log/geoblock.log\n{\n        rotate 5\n        weekly\n        missingok\n        notifempty\n        compress\n        delaycompress\n        sharedscripts\n}\n```\n\n## Some sources that were used to make this\n\n### Country IP blocks:\n\nhttps://github.com/herrbischoff/country-ip-blocks\n\n### iptables man:\n\nhttps://www.digitalocean.com/community/tutorials/how-to-list-and-delete-iptables-firewall-rules\n\n### country ban gist:\n\nhttps://gist.github.com/jasonruyle/8870296\n\n### persistent ipset manual\n\nhttps://selivan.github.io/2018/07/27/ipset-save-with-ufw-and-iptables-persistent-and.html\n\n## Contributors\n\n- [nisenbeck](https://github.com/nisenbeck) - added rate limited logging of blocked packets\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparmaster%2Fgeoblock","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fparmaster%2Fgeoblock","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fparmaster%2Fgeoblock/lists"}