- 论坛徽章:
- 0
|
使用 TCP-Wrapper 管理服务
使用 TCP-Wrapper 管理服务
设定档
- /etc/hosts.allow
- /etc/hosts.deny
参考文件
- man hosts.allow
- man hosts.deny
Linux 的安全设定中,安全设定大制分为三个类别,Kernel Filter、应用程式本身安全设定以及 TCP-Wrapper。
TCP-Wrapper 就像一个服务总管一样,所有使用(支援)TCP-Wrapper 的程式,都可以透过他来限制一些安全的控管,比如只允许那些地方可以连入,那些地方无法连入等等。如果连线是允许的,才让该连线和相关的服务接洽。
现行常见使用 TCP-Wrapper 的服务有 pop3、sshd、vsftpd、telnet、imap ... .... 等常见的服务。
流程
![]()
当封包到达主机之后,使用 TCP-Wrapper 会先参考 hosts.allow,若是该服务在 hosts.allow 里面,就会先被通过,如果不在 hosts.allow 里面,就会继续往下,参考 hosts.deny,如果该服务在 hosts.deny 在该项目里面,那么就无法使用;最后,万一该服务在 hosts.allow 或 hosts.deny 里被没有被描述的话,就可以使用。
实例:允许使用者只能从 eic.com.tw 网段连进来。
# vi /etc/hosts.deny
___________________________
sshd:ALL EXCEPT .eic.com.tw
:__________________________
如此就马上生效,也不用重新启动。
安全政策:
实作中,都是先 deny 所有的 service,再一一打开。因此,都会在 hosts.deny 里会设定 ALL:ALL,再到 hosts.allow 开启必要的设定,以本例来说,只允许 ssh 服务启动。
# vi /etc/hosts.deny
_____________________
ALL:ALL
:____________________
# vi /etc/hosts.allow
_____________________
sshd:.eic.com.tw
:____________________
如此就可以达到稍微安全的机制。
指定正确的服务名称:
现在知道了 TCP-Wrapper 的大致用法,那我们如何指定服务名称呢?其实这个问题不难,一般来说,只要是被 xinetd 所控制的服务,大约都是使用 TCP-Wrapper 机制;其它的服务像是 vsftpd、ssh 等,也是使用 TCP-Wrapper 的机制。
如果是被 xinetd 所控制的服务,可以到 /etc/xinetd.d 看看真正的服务名称。
[root@xml root]# cd /etc/xinetd.d
[root@xml xinetd.d]# ls
chargen daytime-udp finger ipop2 pop3s rsh services telnet
chargen-udp echo imap ipop3 rexec rsync sgi_fam time
daytime echo-udp imaps ntalk rlogin servers talk time-udp
[root@xml xinetd.d]#
假设现在要设定 ipop3,那么我们知道这个服务是被 xinetd 所控制,所以就来看看 ipop3 这个真正的服务者是谁!
[root@xml xinetd.d]# cat ipop3
# default: off
# description: The POP3 service allows remote users to access their mail \
# using an POP3 client such as Netscape Communicator, mutt, \
# or fetchmail.
service pop3
{
disable = no
socket_type = stream
wait = no
user = root
server = /usr/sbin/ipop3d
log_on_success += HOST DURATION
log_on_failure += HOST
}
[root@xml xinetd.d]#
在上面有 server = /usr/sbin/ipop3d 这个字样,所以我们就可以知道,真正付责 ipop3 是由 ipop3d 这个程式来跑的,所以我们在 hosts.allow 或 hosts.deny 设定服务名称时,请记得要写成 ipop3d,而不是 ipop3 喔!
[root@xml xinetd.d]# vi /etc/hosts.deny
______________________________________________________________________
#
# hosts.deny This file describes the names of the hosts which are
# *not* allowed to use the local INET services, as decided
# by the '/usr/sbin/tcpd' server.
#
# The portmap line is redundant, but it is left to remind you that
# the new secure portmap uses hosts.deny and hosts.allow. In particular
# you should know that NFS uses portmap!
ipop3d:ALL EXCEPT .eic.com.tw
:______________________________________________________________________
如果是非由 xinetd 所控制的服务,如 ssh 或是 vsftpd 等,就直接指定他们的服务名称就可以了!
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/42053/showart_336961.html |
|