可以直接服務配置nginx.conf
添加 deny+IP 例如:
封禁單個IP
deny 106.5.76.83;
#封整個段即從123.0.0.1到123.255.255.254的命令
deny 123.0.0.0/8
#封IP段即從123.45.0.1到123.45.255.254的命令
deny 124.45.0.0/16
#封IP段即從123.45.6.1到123.45.6.254的命令是
deny 123.45.6.0/24
重啟nginx 服務 ./nginx -s reload
也可以 在tcpd服務器配置中封禁
/etc/hosts.deny
封禁單個IP
ALL: 106.5.76.83;
#封整個段即從123.0.0.1到123.255.255.254的命令
ALL: 123.0.0.0/8
#封IP段即從123.45.0.1到123.45.255.254的命令
ALL: 124.45.0.0/16
#封IP段即從123.45.6.1到123.45.6.254的命令是
ALL: 123.45.6.0/24
重啟服務 service xinetd restart
在防火牆禁止ip訪問也是可行的:
封禁IP:
#iptables -I INPUT -s ***.***.***.*** -j DROP
解封IP:
#iptables -D INPUT -s ***.***.***.*** -j DROP
封禁IP段:
#iptables -I INPUT -s ***.***.***.0/24 -j DROP
添加完規則記得保存規則
#/etc/rc.d/init.d/iptables save
查看規則
#iptables -L
重啟iptables
#service iptables restart
即可生效