CentOS 訪問控制列表(tcp wrappers)


1、TCP Wrappers是一個工作在應用層的安全工具,它只能針對某些具體的應用或者服務起到一定的防護作用。
比如說ssh、telnet、FTP等服務的請求,都會先受到TCP Wrappers的攔截。它能夠根據來訪主機的地址
與本機的目標服務程序作出允許或拒絕的操作。

2、TCP Wrappers 服務的防火牆策略由兩個控制列表文件所控制,用戶可以編輯允許控制列表文
件來放行對服務的請求流量,也可以編輯拒絕控制列表文件來阻止對服務的請求流量。控制列表
文件修改后會立即生效,系統將會先檢查允許控制列表文件(/etc/hosts.allow),如果匹配到相應
的允許策略則放行流量;如果沒有匹配,則去進一步匹配拒絕控制列表文件(/etc/hosts.deny),若
找到匹配項則拒絕該流量。如果這兩個文件全都沒有匹配到,則默認放行。

3、直接編輯/etc/hosts.allow和/etc/hosts.deny就可以實現主機、ip、服務等控制

在配置 TCP Wrappers 服務時需要遵循兩個原則:
1)編寫拒絕策略規則時,填寫的是服務名稱,而非協議名稱;
2)建議先編寫拒絕策略規則,再編寫允許策略規則,以便直觀地看到相應的效果。

4、配置格式

service:host(s) [:action]

service:代表服務名,例如 sshd、vsftpd、sendmail 等,可以是多個,多個情況使用","逗號隔開。

host(s):主機名或者 IP 地址,可以有多個,例如 192.168.1.0,www.baidu.com(可以使用空格或,隔開)。

action:動作,符合條件后所采取的動作。

配置文件中常用的關鍵字有:

ALL:所有服務或者所有 IP。

ALL EXCEPT:所有的服務或者所有 IP 除去指定的。

例如:

ALL:ALL EXCEPT 192.168.31.11

表示除了 192.168.31.11 這台設備,任何設備執行所有服務時或被允許或被拒絕。

5、用例

[root@bigdata-senior01 ~]# cat /etc/hosts.deny 
#
# hosts.deny    This file contains access rules which are used to
#        deny connections to network services that either use
#        the tcp_wrappers library or that have been
#        started through a tcp_wrappers-enabled xinetd.
#
#        The rules in this file can also be set up in
#        /etc/hosts.allow with a 'deny' option instead.
#
#        See 'man 5 hosts_options' and 'man 5 hosts_access'
#        for information on rule syntax.
#        See 'man tcpd' for information on tcp_wrappers
#
vsftpd:* #禁止所有設備使用ftp
[root@bigdata-senior01 ~]# cat /etc/hosts.allow
#
# hosts.allow    This file contains access rules which are used to
#        allow or deny connections to network services that
#        either use the tcp_wrappers library or that have been
#        started through a tcp_wrappers-enabled xinetd.
#
#        See 'man 5 hosts_options' and 'man 5 hosts_access'
#        for information on rule syntax.
#        See 'man tcpd' for information on tcp_wrappers
#
vsftpd:192.168.31.0/255.255.255.0 #允許31段所有設備使用ftp服務

最終192.168.31.0/24 網段可以使用ftp服務

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM