3、启动服务
注意修改完后:
#service xinetd restart
才能让刚才的更改生效。
需求:需要用hosts.deny限制用户通过ssh登录
在/etc/hosts.deny中加入
sshd: all
在/etc/hosts.allow中加入
sshd:all #拒绝所有的ip链接ssh服务
在其他服务器上尝试链接该服务器,却发现还是正常链接
继续找问题,又从网上得知, /etc/hosts.allow 与 /etc/hosts.deny 只对调用了 tcp_wrappers 的才起作用。若是源代码编译的,看看编译时是否寻找了 libwrap.so
在起效果机器下,执行如下命令:
[root@zt ~]# ldd /usr/sbin/sshd | grep libwrap.so
libwrap.so.0 =》 /lib64/libwrap.so.0 (0x00002ba28edcc000)
在不起效果机器下,却找不到libwrap.so
在生效的机器上执行:
rpm -qf /lib64/libwrap.so.0 结果如下:
tcp_wrappers-7.6-40.7.el5
在不生效的机器上
yum install -y tcp_wrappers
安装后,用ldd /usr/sbin/sshd | grep libwrap.so 还是没有内容
在不生效机器上,继续
yum list |grep openssh 结果:
openssh.x86_64 5.3p2-24.el5 installed
openssh-clients.x86_64 5.3p2-24.el5 installed
openssh-server.x86_64 5.3p2-24.el5 installed
openssh.x86_64 5.3p2-41.el5_5.1 updates
openssh-askpass.x86_64 5.3p2-41.el5_5.1 updates
openssh-clients.x86_64 5.3p2-41.el5_5.1 updates
openssh-server.x86_64 5.3p2-41.el5_5.1 updates
于是,执行:
yum update -y openssh
再次执行:
ldd /usr/sbin/sshd | grep libwrap.so
有结果显示了。
别的服务器链接该服务器,也会报下面的错误
ssh_exchange_identification: Connection closed by remote host
另一种,也是大家常用的iptalbes来限制IP访问网站
只允许指定的一个IP访问服务器
vi /etc/sysconfig/iptables
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -s 165.232.121.17 -j ACCEPT
-A INPUT -j DROP
COMMIT
如果你之前的防火墙设置了永久关闭,则需要解除
chkconfig --list 查看启动服务,找到要关闭服务名
chkconfig --level 235 服务名 off 【在等级3和5为开机运行服务】
系统运行级别有0—6,就在/etc/inittab中的0-6
等级0表示:表示关机
等级1表示:单用户模式
等级2表示:无网络连接的多用户命令行模式
等级3表示:有网络连接的多用户命令行模式
等级4表示:不可用
等级5表示:带图形界面的多用户模式
等级6表示:重新启动2011/10/26