Chặn IP theo dải (IP range) sử dụng iptables
Sử dụng VPS Linux, đôi khi chúng ta cần firewall để chặn truy cập từ 1 vùng, 1 quốc gia hay 1 IP ranges cụ thể. Điều này hoàn toàn đơn giản và dễ thực hiện với IP tables.
1. Các bước như sau:
Lấy địa chỉ các IP ranges của 1 quốc gia từ link sau http://www.find-ip-address.org và cho vào 1 file gọi là country_IPTạo 1 scripts với cú pháp như sau gọi là iptables_autoallow.sh
#!/bin/bash if [ -f country_IP ] then for IP_select in `cat country_IP` do iptables -A INPUT -s $IP_select -p tcp -j DROP done else echo "Can't read country_IP" fiCó thể add thêm các port cụ thể như port 22
iptables -A INPUT -s $IP_select -p tcp --dport 22 -j ACCEPT oriptables -A INPUT -s $IP_select -p tcp --dport 22 -j DROP
Thay đổi quyền cho scripts và thực thi nó
chmod 755 iptables_autoallow.shsh iptables_autoallow.shOK như vậy là đã hoàn thành xong cách chặn IP theo dải (IP range) sử dụng iptables rồi nhé. Chúc các bạn thành công.
Nhận xét
Đăng nhận xét