linux禁止特定的ip访问

转载https://blog.csdn.net/weixin_42433970/article/details/108408552

linux 服务器通过设置/etc/hosts.allow和/etc/hosts.deny这个两个文件,hosts.allow许可大于hosts.deny可以限制或者允许某个或者某段IP地址远程 SSH 登录服务器,方法比较简单,且设置后立即生效,不需要重启SSHD服务,具体如下:

/etc/hosts.allow添加

sshd:192.168.0.1:allow #允许 192.168.0.1 这个IP地址SSH登录
sshd:192.168.0.:allow #允许192.168.0.1/24这段IP地址的用户登录,多个网段可以以逗号隔开,比如192.168.0.,192.168.1.:allow
/etc/hosts.allow添加

sshd:ALL #允许全部的ssh登录
hosts.allow和hosts.deny两个文件同时设置规则的时候,hosts.allow文件中的规则优先级高,按照此方法设置后服务器只允许192.168.0.1这个IP地址的SSH登录,其它的IP都会拒绝。

/etc/hosts.deny添加

sshd:ALL #拒绝全部IP
sshd:223.99.14.18 #禁止该ip登录

猜你喜欢

转载自blog.csdn.net/weixin_37707670/article/details/121450809