# OpenWrt Geoblocking

**URL:** <https://forum.openwrt.org/t/openwrt-geoblocking/150198>\
**Category:** Installing and Using OpenWrt\
**Created:** [February 1, 2023, 7:02am UTC](https://forum.openwrt.org/t/openwrt-geoblocking/150198 "2023-02-01T07:02:39Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![eckinga](https://forum.openwrt.org/user_avatar/forum.openwrt.org/eckinga/32/68264_2.png) [@eckinga](https://forum.openwrt.org/u/eckinga)\
**Post date:** [February 1, 2023, 7:02am UTC](https://forum.openwrt.org/t/openwrt-geoblocking/150198/1 "2023-02-01T07:02:40Z")

</div>

Hello,

I'm searching for the best way to block IPs by country. Any suggestions to get this working with openwrt.

Thanks Christian

---

<div class="post-metadata">

**Author:** ![trendy](https://forum.openwrt.org/user_avatar/forum.openwrt.org/trendy/32/8800_2.png) [@trendy](https://forum.openwrt.org/u/trendy)\
**Post date:** [February 1, 2023, 7:12am UTC](https://forum.openwrt.org/t/openwrt-geoblocking/150198/2 "2023-02-01T07:12:42Z")

</div>

banip has option for that.

> [@banIP support thread](https://forum.openwrt.org/t/banip-support-thread/16985):
>
> Hi, in OpenWrt snapshot package repo you'll find the banIP package: stable OpenWrt version 23.05.x.: [banIP 0.9.3-4](https://downloads.openwrt.org/releases/packages-23.05/x86_64/packages/) plus [luci companion package](https://downloads.openwrt.org/releases/packages-23.05/x86_64/luci/) latest snapshot version: [banIP 0.9.3-4](https://downloads.openwrt.org/snapshots/packages/x86_64/packages/) plus [luci companion package](https://downloads.openwrt.org/snapshots/packages/x86_64/luci/) Link to the latest [banIP documentation](https://github.com/openwrt/packages/blob/master/net/banip/files/README.md) Feel free to test, ask questions or make suggestions. 
> 
> > **Changelog**
> >
> > --- update 0.9.3-4 made the default mail template "responsive" to get a better view esp. on mobile devices --- update 0.9.3-3 more init fixes --- update 0.9.3-…

---

<div class="post-metadata">

**Author:** ![frollic](https://forum.openwrt.org/user_avatar/forum.openwrt.org/frollic/32/30113_2.png) [@frollic](https://forum.openwrt.org/u/frollic)\
**Post date:** [February 1, 2023, 7:14am UTC](https://forum.openwrt.org/t/openwrt-geoblocking/150198/3 "2023-02-01T07:14:25Z")

</div>

I discovered geo blocking is pretty inaccurate, even though I used the latest DBs, and started blocking all + white list of ISP ranges I would allow.

---

<div class="post-metadata">

**Author:** ![eckinga](https://forum.openwrt.org/user_avatar/forum.openwrt.org/eckinga/32/68264_2.png) [@eckinga](https://forum.openwrt.org/u/eckinga)\
**Post date:** [February 1, 2023, 10:23am UTC](https://forum.openwrt.org/t/openwrt-geoblocking/150198/4 "2023-02-01T10:23:05Z")

</div>

thanks@trendy I'll take a look

@frollic it may be inaccurate, I'm using Maxminds GeoIP Database on another server with nginx and had no problems so far. In my oppion its better and more secure to filter prox. about 90% percent of the ips on this world for my services than not.... in addition to the other safety features ...

---

<div class="post-metadata">

**Author:** ![frollic](https://forum.openwrt.org/user_avatar/forum.openwrt.org/frollic/32/30113_2.png) [@frollic](https://forum.openwrt.org/u/frollic)\
**Post date:** [February 1, 2023, 10:40am UTC](https://forum.openwrt.org/t/openwrt-geoblocking/150198/5 "2023-02-01T10:40:05Z")

</div>

I used the same DB, updating it on a weekly basis.

I had the lists injected into my shorewall firewall, and noticed (mainly) IPs originating from  
CN wouldn't get blocked, since the DB wasn't accurate (or updated ?) enough.

Using some other lookup tool/site like [ipinfo.io](http://ipinfo.io), confirmed the IP location.

But I agree, it's better than nothing.

---

<div class="post-metadata">

**Author:** ![eckinga](https://forum.openwrt.org/user_avatar/forum.openwrt.org/eckinga/32/68264_2.png) [@eckinga](https://forum.openwrt.org/u/eckinga)\
**Post date:** [February 1, 2023, 12:18pm UTC](https://forum.openwrt.org/t/openwrt-geoblocking/150198/6 "2023-02-01T12:18:08Z")

</div>

like i said better block than not block. i, for my personal needs, will block all and whitelist a few countries so the hope that they're more accurate is higher....

i had a quickview on banIP but it seems its not precompiled in snapshot i use (bpi-r3). there are easier way?

---

<div class="post-metadata">

**Author:** ![moeller0](https://forum.openwrt.org/user_avatar/forum.openwrt.org/moeller0/32/1591_2.png) [@moeller0](https://forum.openwrt.org/u/moeller0)\
**Post date:** [February 1, 2023, 12:47pm UTC](https://forum.openwrt.org/t/openwrt-geoblocking/150198/7 "2023-02-01T12:47:07Z")

</div>

> [@frollic](#):
>
> But I agree, it's better than nothing.

I heartily disagree, geoIP is fundamentally just a heuristic and one that fails relatively often. That might be OK if you need to convince your content providers that you only serve a specific region of the world and hence do not need to pay for world-wide distribution rights. But for anything else you need to consider whether the inevitable false positive rate is going to be a problem as well as the inevitable false negative rates, that is you will fail to detect users from excluded parts of the world and you will mis classify users from permitted parts of the world as being located in excluded parts. Well possible that this is an acceptable trade-off, but it certainly not a win all around.

Personally, I would rather look at fail2ban or similar solutions that are based on suspect behaviour instead of suspect IP ranges, but I understand that this is a subjective preference (plus my in my case I routinely see how geoIP providers consistently fail to localize my link appropriately, even though the country is correct).

---

<div class="post-metadata">

**Author:** ![frollic](https://forum.openwrt.org/user_avatar/forum.openwrt.org/frollic/32/30113_2.png) [@frollic](https://forum.openwrt.org/u/frollic)\
**Post date:** [February 1, 2023, 12:54pm UTC](https://forum.openwrt.org/t/openwrt-geoblocking/150198/8 "2023-02-01T12:54:31Z")

</div>

> [@moeller0](#):
>
> I heartily disagree, geoIP is fundamentally just a heuristic and one that fails relatively often

I thought I just said the same ? 😉

> [@moeller0](#):
>
> Personally, I would rather look at fail2ban or similar solutions that are based on suspect behaviour instead of suspect IP ranges

I actually used f2b with the previously mentioned [ipinfo.io](http://ipinfo.io). All IPs got queried, and if the reply  
didn't match the white list, it got added to the f2b DB, and dropped in the fw.  
IP also got distributed to the other host(s), open to internet.

Eventually I just blocked everything, and put up a narrow white list 🙂

---

<div class="post-metadata">

**Author:** ![moeller0](https://forum.openwrt.org/user_avatar/forum.openwrt.org/moeller0/32/1591_2.png) [@moeller0](https://forum.openwrt.org/u/moeller0)\
**Post date:** [February 1, 2023, 12:57pm UTC](https://forum.openwrt.org/t/openwrt-geoblocking/150198/9 "2023-02-01T12:57:10Z")

</div>

> [@frollic](#):
>
> I thought I just said the same ? 😉

Sorry, I was reading too much endorsement into your "better than nothing"....

---

<div class="post-metadata">

**Author:** ![moeller0](https://forum.openwrt.org/user_avatar/forum.openwrt.org/moeller0/32/1591_2.png) [@moeller0](https://forum.openwrt.org/u/moeller0)\
**Post date:** [February 1, 2023, 12:58pm UTC](https://forum.openwrt.org/t/openwrt-geoblocking/150198/10 "2023-02-01T12:58:11Z")

</div>

> [@frollic](#):
>
> Eventually I just blocked everything, and put up a narrow white list 🙂

That works well, if you can control the IPs of your intended remote end-devices...

---

<div class="post-metadata">

**Author:** ![eckinga](https://forum.openwrt.org/user_avatar/forum.openwrt.org/eckinga/32/68264_2.png) [@eckinga](https://forum.openwrt.org/u/eckinga)\
**Post date:** [February 1, 2023, 9:05pm UTC](https://forum.openwrt.org/t/openwrt-geoblocking/150198/11 "2023-02-01T21:05:42Z")

</div>

Thanks for answers. F2b alone is just additional for sure but with [ipinfo.io](http://ipinfo.io) and all queried this locks really promising. and like i said geoblocking cant be the one but blocking that amount is a beginning for my demands. i won't serve customers from different locations. i only serve me with best security i can get for my service an one would be block all expect in addition to all other features.

while i'm writing: why query every single ip with [ipinfo.io](http://ipinfo.io) although i can block 90% with ipsets?

thanks christian

---

<div class="post-metadata">

**Author:** ![frollic](https://forum.openwrt.org/user_avatar/forum.openwrt.org/frollic/32/30113_2.png) [@frollic](https://forum.openwrt.org/u/frollic)\
**Post date:** [February 1, 2023, 10:03pm UTC](https://forum.openwrt.org/t/openwrt-geoblocking/150198/12 "2023-02-01T22:03:27Z")

</div>

> [@eckinga](#):
>
> while i'm writing: why query every single ip with [ipinfo.io](http://ipinfo.io) although i can block 90% with ipsets

Because the geo db is a hit or miss...

---

<div class="post-metadata">

**Author:** ![eckinga](https://forum.openwrt.org/user_avatar/forum.openwrt.org/eckinga/32/68264_2.png) [@eckinga](https://forum.openwrt.org/u/eckinga)\
**Post date:** [February 1, 2023, 10:03pm UTC](https://forum.openwrt.org/t/openwrt-geoblocking/150198/13 "2023-02-01T22:03:29Z")

</div>

I have just another idea. What about taking the data from [ripe.net](http://ripe.net) and make ipset for eu countries to whitelist?

---

<div class="post-metadata">

**Author:** ![moeller0](https://forum.openwrt.org/user_avatar/forum.openwrt.org/moeller0/32/1591_2.png) [@moeller0](https://forum.openwrt.org/u/moeller0)\
**Post date:** [February 2, 2023, 6:55am UTC](https://forum.openwrt.org/t/openwrt-geoblocking/150198/15 "2023-02-02T06:55:15Z")

</div>

If a company mainly located in the ripe area happens to use ripe-sourced IP ranges for oversea branches you get false positives...  
Let's face it geoIP is at best a rough heuristic that should not be taken too seriuously, it is not a good match for how IP networks like the internet are set up and operate....

Sidenote, the 'obviouos' alternative, delay triangulation from a set of known vantage points has similar challenges, e.g. with rural customers in country A being served via geostationary satellite in country B... or chestnuts like the otherwise excellent init7 routing traffic too from european incumbents via data centers in the US to make a policy point..,.

However if one truly wants to outsource the decision which IPs to accept or reject, ripe and friends seem like better places than commercial geoIP providers....

Again, for some use-cases false positive and negatives can be a non-issue and there geoIP might have some utility.... or a lot of utility it really depends on the 'why' one wants this information in the first place.

---

<div class="post-metadata">

**Author:** ![eckinga](https://forum.openwrt.org/user_avatar/forum.openwrt.org/eckinga/32/68264_2.png) [@eckinga](https://forum.openwrt.org/u/eckinga)\
**Post date:** [February 15, 2023, 12:16am UTC](https://forum.openwrt.org/t/openwrt-geoblocking/150198/16 "2023-02-15T00:16:28Z")

</div>

thanks so far. at this moment i set this a few steps back due the lack of time and many other things i have to do to make services running reliable and harden it.

I'll come back soon and report.

Thanks
