tcp_wraper:
libwrap.so
必須在編譯的時候鏈接到libwrap.so這個庫之後才能實現調用tcp_wraper實現訪問控制
可以通過ldd來查看
[root@localhost ~]# ldd `which sshd` |grep libwrap
libwrap.so.0 => /lib64/libwrap.so.0 (0x00007fe51d88b000)
如果出現libwrap.so則能實現wraper訪問控制
靜態鏈接:把動態庫直接編譯到服務裏
strings命令查詢是否加載靜態hosts.allow和host.deny文件,如果加載,則受tcpwraper控制,否則不受控制
strings `which portmap` | grep hosts
tcpwraper控制機制:主要由/etc/hosts.allow和/etc/hosts.deny這兩個文件進行控制
匹配順序:首先查詢/etc/hosts.allow,再查詢/etc/hosts.deny,最後默認規則是允許所有通過
/etc/hosts.allow和/etc/hosts.deny文件格式:
xinetd:超級守護進程,管理非獨立守護進程,非獨立守護進程安需啓動
standalone:獨立守護進程
超級守護進程接收tcp_wraper控制,旗下所有非獨立守護進程都受其控制
服務列表: 客戶端列表(client_list) [:選項]
服務列表有下幾種類型寫法:
sshd:192.168.0.
vsftpd,sshd,in.telnetd #可執行程序名
ALL #所有受tcp_wraper控制的服務
[email protected]:1. #本機有2個IP地址,只希望服務只接收某一個IP地址是通過tcp_wraper控制的(1網段通過192.168.1.2訪問vsftp受tcp_wraper控制)
客戶端列(client_list)表有下幾種類型寫法:
IP
network address
network/mask(如192.168.1.0/255.255.255.0)
172.16.1.
HOSTNAME
FQDN #完整合格域名,如mail.mylinux.com.
.mylinux.com #域名
MACRO
ALL #所有來賓
LOCAL(本地來賓,IP和服務器在同一個網段的),KNOWN(主機名可以被正常解析的),UNKNOWN,PARANOID(主機名正向和反向解析不匹配)
EXCEPT #意思是除了,不包含
選項有如下幾種類型寫法:
DENY
ALLOW
spawn #記錄日誌
tcp_wraper宏定義:
%c:代表客戶端信息(user@host)
%s:代表服務器信息(server@host)
%h:客戶端主機名(hostname)
%p:服務ID(server PID)
tcp_wraper宏定義查詢方法: man 5 hosts_access
tcp wraper
ssh僅允許172.16.0.0/16網段訪問:
方法1:
1./etc/hosts.allow
sshd: 172.16.
2./etc/hosts.deny
sshd: ALL
telnet服務不允許172.16.0.0/16訪問,但是允許172.16.100.200訪問,其他客戶端不受控制
方法1:
1./etc/hosts.allow
in.telnetd: 172.16.100.200:spawn echo “`date`, Login attempt from %c to %s” >> /var/log/tcpwarper.log
2./etc/hosts.deny
in.telnetd: 172.16.
方法2:
2./etc/hosts.deny
in.telnetd: 172.16. EXCEPT 172.16.100.200
方法3:
1./etc/hosts.allow
in.telnetd: ALL EXCEPT 172.16. EXCEPT 172.16.100.200
2./etc/hosts.deny
in.telnetd: 172.16.