su root
vi /etc/hosts.allow
容许内容html |
书写格式(改为自自须要的IP或IP段)linux |
ssh容许单个ipssh |
sshd:192.168.220.1spa |
ssh容许ip段rest |
sshd:192.168.220.htm |
telnet容许单个ipblog |
in.telnetd:192.168.220.1教程 |
telnet容许ip段ip |
in.telnetd:192.168.221.get |
以ssh容许192.168.220.1和telnet容许192.168.220网段为例,具体在/etc/hosts.allow加入内容以下:
vi /etc/hosts.deny
在文件中加入:
sshd:ALL in.telnetd:ALL
具体在/etc/hosts.deny加入内容以下:
service sshd restart service xinetd restart
说明:
1.一个IP请求连入,linux的检查策略是先看/etc/hosts.allow中是否容许,若是容许直接放行;若是没有,则再看/etc/hosts.deny中是否禁止,若是禁止那么就禁止连入。
2.实验发现对/etc/hosts.allow和/etc/hosts.deny的配置不用重启就当即生效,但无论重启不重启当前已有会话都不会受影响;也就是说对以前已经连入的,即使IP已配置为禁止登陆会话仍不会强制断开。不过不知是否全部linux都同样,由此第四步标为可选。
3.网上发现有些教程写成不是sshd而是in.sshd不是in.telnetd而是telnetd的,我的以为应该是独立启的不用加in.托管于xinetd的须要加in.