8.4 服務(wù)的訪問控制列表

2022-05-31 11:14 更新

TCP Wrappers是RHEL 7系統(tǒng)中默認(rèn)啟用的一款流量監(jiān)控程序,它能夠根據(jù)來訪主機的地址與本機的目標(biāo)服務(wù)程序作出允許或拒絕的操作。換句話說,Linux系統(tǒng)中其實有兩個層面的防火墻,第一種是前面講到的基于TCP/IP協(xié)議的流量過濾工具,而TCP Wrappers服務(wù)則是能允許或禁止Linux系統(tǒng)提供服務(wù)的防火墻,從而在更高層面保護了Linux系統(tǒng)的安全運行。

TCP Wrappers服務(wù)的防火墻策略由兩個控制列表文件所控制,用戶可以編輯允許控制列表文件來放行對服務(wù)的請求流量,也可以編輯拒絕控制列表文件來阻止對服務(wù)的請求流量??刂屏斜砦募薷暮髸⒓瓷В到y(tǒng)將會先檢查允許控制列表文件(/etc/hosts.allow),如果匹配到相應(yīng)的允許策略則放行流量;如果沒有匹配,則去進一步匹配拒絕控制列表文件(/etc/hosts.deny),若找到匹配項則拒絕該流量。如果這兩個文件全都沒有匹配到,則默認(rèn)放行流量。

TCP Wrappers服務(wù)的控制列表文件配置起來并不復(fù)雜,常用的參數(shù)如表8-4所示。

表8-4 TCP Wrappers服務(wù)的控制列表文件中常用的參數(shù)

客戶端類型 示例 滿足示例的客戶端列表
單一主機 192.168.10.10 IP地址為192.168.10.10的主機
指定網(wǎng)段 192.168.10. IP段為192.168.10.0/24的主機
指定網(wǎng)段 192.168.10.0/255.255.255.0 IP段為192.168.10.0/24的主機
指定DNS后綴 .linuxprobe.com 所有DNS后綴為.linuxprobe.com的主機
指定主機名稱 www.linuxprobe.com 主機名稱為www.linuxprobe.com的主機
指定所有客戶端 ALL 所有主機全部包括在內(nèi)

指定所有客戶端 ALL 所有主機全部包括在內(nèi) 在配置TCP Wrappers服務(wù)時需要遵循兩個原則:

編寫拒絕策略規(guī)則時,填寫的是服務(wù)名稱,而非協(xié)議名稱; 建議先編寫拒絕策略規(guī)則,再編寫允許策略規(guī)則,以便直觀地看到相應(yīng)的效果。 下面編寫拒絕策略規(guī)則文件,禁止訪問本機sshd服務(wù)的所有流量(無須/etc/hosts.deny文件中修改原有的注釋信息):

    [root@linuxprobe ~]# vim /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
    sshd:*
    [root@linuxprobe ~]# ssh 192.168.10.10
    ssh_exchange_identification: read: Connection reset by peer

接下來,在允許策略規(guī)則文件中添加一條規(guī)則,使其放行源自192.168.10.0/24網(wǎng)段,訪問本機sshd服務(wù)的所有流量。可以看到,服務(wù)器立刻就放行了訪問sshd服務(wù)的流量,效果非常直觀:

    [root@linuxprobe ~]# vim /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
    sshd:192.168.10.


    [root@linuxprobe ~]# ssh 192.168.10.10
    The authenticity of host '192.168.10.10 (192.168.10.10)' can't be established.
    ECDSA key fingerprint is 70:3b:5d:37:96:7b:2e:a5:28:0d:7e:dc:47:6a:fe:5c.
    Are you sure you want to continue connecting (yes/no)? yes
    Warning: Permanently added '192.168.10.10' (ECDSA) to the list of known hosts.
    root@192.168.10.10's password: 
    Last login: Wed May 4 07:56:29 2017
    [root@linuxprobe ~]#
以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號