How to block traffic from selected country

Intuz

New member
Joined
Nov 24, 2016
Messages
44
Points
0
To block traffic from specific country, you can apply filter on geopgraphy.

For example you want to block russian traffic from Google analytics, follow the below stepes:


Filter Type: Custom filter > Include

Filter Field: Country

Filter Pattern: Russia
 

onliveserver

New member
Joined
Jun 22, 2017
Messages
29
Points
0
Hello,

First of install the csf on the serer after that Click on the Firewall Configuration button to open the configuration file and page, scroll down to the Country Code Lists and Settings section.

## Use the CC_DENY field to block by country code:
The CC_DENY field accepts two-letter country codes.
such as “US” for the United States of America, “GB” for Great Britain, and “DE” for Germany.
IN this way the specific country code traffic has deny to server.
 

WeWatchYourWebsite

New member
Joined
Oct 10, 2017
Messages
3
Points
0
I realize I'm late on this, but you'll want to block the IP addresses (or ranges) as far up the "chain" as possible.

In other words, if you're blocking them with .htaccess or similar level, that means the traffic has already "hit" your site.

If you block at the iptables level, then you're saving website processing (Apache, Nginx...) for your website.

Let me know if you have further questions about this.
 

genesis

New member
Joined
Oct 12, 2017
Messages
28
Points
0
This will actually depends on the internet provider you are using. VPN is now a trend. If you tend to use VPN and want to block countries for your site, I'd prefer not to do it. Because once you logged into another device, your settings will be refreshed. Better have a suitable internet provider first. Then follow the steps the others have given. Ciao
 

dejan.kolar

New member
Joined
Aug 30, 2018
Messages
3
Points
0
You may try the CSF which has ability to filter out access by country codes.
 

BenSupportSages

New member
Joined
Jun 13, 2019
Messages
18
Points
3
1. Adding rules in htaccess

You can use the link: https://www.ip2location.com/free/visitor-blocker to generate the range of IP's which needs to be blocked

2. Using Cloudflare CDN

You can find the instructions to so here: https://support.cloudflare.com/hc/en-us/articles/217074967-Configuring-IP-Access-Rules

3. Using CSF

In the csf configuration file (/etc/csf/csf.conf), there is an option to block/allow access from an IP range by using country code. Here I’m going to explain how to allow or deny IP range using this feature.

For allowing a country to your server you can use the directive ‘CC_ALLOW‘ from the csf configuration file

CC_ALLOW = ""

Similarly, you can deny by using the directive ‘CC_DENY‘

CC_DENY = ""

Each option is a comma separated list of CC’s, e.g. “US,GB,DE”

You need to restart the csf service to get the changes to be worked. Run the following command for restarting the csf service.

csf -r

Country codes:
AF,AL,DZ,AS,AD,AO,AI,AQ,AG,AR,AM,AW,AU,AT,AZ,BS,BH,BD,BB,BY,BE,BZ,BJ,BM,BT,BO,BA,BW,BV,BR,IO,BN,BG,BF,BI,KH,CM,CA,CV,KY,CF,TD,CL,CN,CX,CC,CO,KM,
CG,CD,CK,CR,CI,HR,CU,CY,CZ,DK,DJ,DM,DO,TP,EC,EG,SV,GQ,ER,EE,ET,FK,FO,FJ,FI,FR,FX,GF,PF,TF,GA,GM,GE,DE,GH,GI,GR,GL,GD,GP,GU,GT,GN,GW,GY,HT,HM,VA,
HN,HK,HU,IS,IN,ID,IR,IQ,IE,IL,IT,JM,JP,JO,KZ,KE,KI,KP,KR,KW,KG,LA,LV,LB,LS,LR,LY,LI,LT,LU,MO,MK,MG,MW,MY,MV,ML,MT,MH,MQ,MR,MU,YT,MX,FM,MD,MC,MN,
MS,MA,MZ,MM,NA,NR,NP,NL,AN,NC,NZ,NI,NE,NG,NU,NF,MP,NO,OM,PK,PW,PA,PG,PY,PE,PH,PN,PL,PT,PR,QA,RE,RO,RU,RW,KN,LC,VC,WS,SM,ST,SA,SN,SC,SL,SG,SK,SI,
SB,SO,ZA,GS,ES,LK,SH,PM,SD,SR,SJ,SZ,SE,CH,SY,TW,TJ,TZ,TH,TG,TK,TO,TT,TN,TR,TM,TC,TV,UG,UA,AE,GB,US,UM,UY,UZ,VU,VE,VN,VG,VI,WF,EH,YE,ZM,ZW
 

alitce

New member
Joined
Feb 23, 2019
Messages
25
Points
0
Hi everyone
How to block traffic from selected country?
Hello YacaZG
If your site is wordpress you can block countries from their IP address, but if your site is not wordpress, you can block it via the server directly
 

Server Trafficweb

New member
Joined
Jul 24, 2020
Messages
15
Points
1
Head to Country IP Blocks homepage. Select the countries you want to block or allow. For the Select Format section, choose Apache . htaccess Deny or Apache. Click Create ACL. The ACL results will appear on the right side of your screen. Press the Copy ACL to Clipboard button.
 

shiju

New member
Joined
Aug 9, 2020
Messages
17
Points
3
I think the IP range can block with the Config server firewall itself. For blocking in use CC_DENY and you can also use .htacess for an immediate result.
 

Dreamwebhosts

New member
Joined
Sep 18, 2020
Messages
15
Points
3
You can block unwanted traffice from firewall (CSF) or you can add deny rules in .htaccess file.
 

budgetvm

New member
Joined
Jul 24, 2020
Messages
4
Points
1
It depends on what server do you run. You can block it on firewall.

CSF should be the perfect one on linux servers.
 

Hostigger

New member
Joined
Oct 18, 2017
Messages
4
Points
1
Hello there,

You can easily block countries from the Cloudflare panel. This service is available in the free plan.
 

EngagementRingsUSA

Active member
Joined
Feb 9, 2021
Messages
195
Points
28
Today's unwanted traffic is far more challenging to navigate, so blocking a specific country is hardly the answer. Most malicious activity is now conducted by proxy, using VPN/VPS or cloud computing platforms (the likes of AWS, Google Cloud, Microsoft Azure, Oracle, Huawei, etc...).

This means that blocking malicious scripts, crawlers and live users requires a constant monitoring of your raw server logs. That is where you can see exactly who is browsing what, and immediately detect probing, scraping and attempted hacking activity in real time. The user may be in China but they could be crawling your website via a proxy server located anywhere in the world, sadly including the U.S. and Canada.
 

hostguy

New member
Joined
Sep 25, 2021
Messages
20
Points
3
If you are server owner then you can definitely block IP addresses on server with server Firewall option, it will make all your hosted websites secure.
On the other hand you can add IP address in your .htaccess file to deny access.
 
Older threads
Replies
23
Views
5,841
Replies
4
Views
2,540
Replies
4
Views
2,569
Replies
9
Views
2,763
Replies
12
Views
5,164
Newer threads
Replies
15
Views
4,459
Replies
13
Views
8,421
Replies
18
Views
7,561
Replies
6
Views
3,076
Latest threads
Replies
1
Views
80
Replies
1
Views
175
Replies
4
Views
383
Replies
11
Views
525
Replies
2
Views
228
Recommended threads
Replies
5
Views
2,162
Replies
13
Views
8,631
Replies
7
Views
3,461
Replies
5
Views
2,826

Latest postsNew threads

Referral contests

Referral link for :

Sponsors

Popular tags

You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an alternative browser.

Top