VPS and independent servers block Chinese IPs with one click (other countries can be used)

888u

Last update at :2024-05-28,Edit by888u

This code can block mainland China IP. Of course, changing the IP library address (cn.zone file) can block specific IPs and IP segments.

1. Block Chinese IP and save the following code as blockcn.sh

ipset -N china hash:net rm cn.zone wget -P . https://we.com/wp-content/uploads/2018/04/cn.zone for i in $(cat /root/cn.zone ); do ipset -A china $i; done iptables -I INPUT -p tcp -m set --match-set china src -j DROP

Then, execute:

shblockcn.sh

2. Unblock Chinese IP and save the following code as boblockcn.sh:

ipset -N china hash:net rm cn.zone wget -P . https://we.com/wp-content/uploads/2018/04/cn.zone for i in $(cat /root/cn.zone ); do ipset -A china $i; done iptables -D INPUT -p tcp -m set --match-set china src -j DROP

Then, execute:

sh noblockcn.sh

via: https://www.lowendtalk.com/discussion/141800/blocking-attack-ips-ddos-ips-from-china

3. Further optimized script This script is based on the IP segment provided by ipdeny.com. The above script can be added and deleted accurately and in real time, each with its own advantages and disadvantages. 1. Download

wget --no-check-certificate https://us.com/wp-content/uploads/2018/04/block-ips.sh

2. Use

Here is China as an example. If you want to block other countries, please modify the final code parameters yourself

Add rules

bash block-ips.sh -a cn

Start blocking

bash block-ips.sh -b cn

List of blocked countries

bash block-ips.sh -l

Unblock

bash block-ips.sh -u cn

View other country codes: http://www.ipdeny.com/ipblocks

via: https://lolico.moe/projects/block-countries-ips.html

Recommended site searches: vps dynamic ip, foreign space service providers, ip reverse check, domain name query network, ip detailed address query, registered password retrieval, free ip proxy server, domain name purchase, host space, US vps host, < /p>

VPS and independent servers block Chinese IPs with one click (other countries can be used)

All copyrights belong to 888u unless special state
取消
微信二维码
微信二维码
支付宝二维码