Linux 限制IP远程连接

1、允许访问
编辑 /etc/hosts.allow 文件,如下:

sshd:all:allow                                      #允许所有 IP 远程 ssh 访问。【:allow】可写可不写
sshd:10.203.XX.*:allow                      # 允许10.203.XX.*  网段都可以远程 ssh 访问。【:allow】可写可不写
sshd:10.203.XX.19:allow                   #只允许10.203.XX.19 主机远程 ssh 访问。【:allow】可写可不写

2、拒绝访问
编辑  /etc/hosts.deny(IP配置冲突 /etc/hosts.allow 文件的,则以 /etc/hosts.allow 为准),如下:
sshd:all:deny                                      #拒绝所有 IP 远程 ssh 访问。【:deny】可写可不写
sshd:10.203.XX.*:deny                       #拒绝210.13.218.* 网段都可以远程 ssh 访问。【:deny】可写可不写
sshd:10.203.XX.19:deny                   #拒绝 10.203.XX.19 主机远程 ssh 访问。【:deny】可写可不写

3、编辑文件后,需要重启服务才有效

  #systemctl restart xinetd

  #systemctl restart network 

猜你喜欢

转载自www.cnblogs.com/leihongnu/p/13366917.html