Linux - Block access from specific countires, How to Allow and Deny access to server for Countries

Block access from specific countires

How to Allow and Deny access in server for Countries using CSF.

As a admin we will be in a situation to allow and deny Countries using to access our websites or webcontents, this can be easily achieved by using CSF. It is a firewall and to achieve this we must know the IP ranges to deny and allow countries. IP ranges vary from countries to countries. To make ourself feel easire we can block websites using county cod insted of remembering all the IP Ranges. Country codes are available to use in our CSF. There are TWO variables (directives) available in CSF configuration file, they are CC_ALLOW and CC_DENY.

Login as root user in your server.
 # su 
Open CSF configuration File.
 # vi /etc/csf/csf.conf

Countries to be allowed
 # CC_ALLOW = "IN,US"

Find CC_DENY variable and add the countries which you like to deny.
 # CC_DENY = "CN,PK"
In the above examples We have allowed access to india and united status countries and denied to china and pakistan. After you make the changes, save the file and quit your text editor.

You have to restart your CSF firewall for the changes to take effect.
 # csf -r
The above command will restart the CSF firewall. Here are some of the country codes

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

You can search about country codes and IP Ranges allocated for countries in any one of the search engine. Check the following URLs to know about country code and IP Range.

https://www.countryipblocks.net/allocation-of-ip-addresses-by-country.php

http://www.nirsoft.net/countryip/

The topic on Linux - Block access from specific countires is posted by - Math

Hope you have enjoyed, Linux - Block access from specific countiresThanks for your time

Tech Bluff