Linux hosts.allow与hosts.deny文件设置

1.需要安装rpcbind

# yum -y installl rpcbind

 

2.更改文件的效果即时成效的,如deny某ip地址ssh本机,更改完hosts.deny文件保存后,telnet 22端口马上失败。

 

3.与iptables的区别:iptables阻止包的传输,hosts.deny文件只阻止接入。比如:已经ssh到server上面,如果更改iptables设置禁止ssh,那么本连接会被马上阻断,更改host.deny文件则不会。

 

 

以下转载http://www.cnblogs.com/hicome/archive/2007/11/22/968780.html

 

hosts.allow与hosts.deny
两个文件均在/etc/目录下
优先级为先检查hosts.deny,再检查hosts.allow, 
后者设定可越过前者限制, 

例如: 
1.限制所有的ssh, 
除非从218.64.87.0——127上来。 
hosts.deny: 
in.sshd:ALL 
hosts.allow: 
in.sshd:218.64.87.0/255.255.255.128 


2.封掉218.64.87.0——127的telnet 
hosts.deny 
in.sshd:218.64.87.0/255.255.255.128 


3.限制所有人的TCP连接,除非从218.64.87.0——127访问 
hosts.deny 
ALL:ALL 
hosts.allow 
ALL:218.64.87.0/255.255.255.128 


4.限制218.64.87.0——127对所有服务的访问 
hosts.deny 
ALL:218.64.87.0/255.255.255.128 

其中冒号前面是TCP daemon的服务进程名称,通常系统 
进程在/etc/inetd.conf中指定,比如in.ftpd,in.telnetd,in.sshd 


其中IP地址范围的写法有若干中,主要的三种是: 
1.网络地址——子网掩码方式: 
218.64.87.0/255.255.255.0 
2.网络地址方式(我自己这样叫,呵呵) 
218.64.(即以218.64打头的IP地址) 
3.缩略子网掩码方式,既数一数二进制子网掩码前面有多少个“1”比如: 
218.64.87.0/255.255.255.0《====》218.64.87.0/24 

_______________________________
设置好后,要重新启动

# /etc/rc.d/init.d/xinetd restart

# /etc/rc.d/init.d/network restart

_ _ _ _ _ _ _ _ _ _ 避开尘世纷纷扰扰,所谓修身齐家治国平天下。

 

posted @ 2013-04-03 15:46  jydeng  阅读(4196)  评论(0编辑  收藏  举报