hosts.allow和hosts.deny


/etc/hosts.allow和/etc/hosts.deny兩個文件是控制遠程訪問設置的,通過他可以允許或者拒絕某個ip或者ip段的客戶訪問linux的某項服務。

    比如SSH服務,我們通常只對管理員開放,那我們就可以禁用不必要的IP,而只開放管理員可能使用到的IP段。

    使用:

    修改/etc/hosts.allow文件

    #

    # hosts.allow This file describes the names of the hosts which are

    # allowed to use the local INET services, as decided

    # by the '/usr/sbin/tcpd' server.

    #

    sshd:210.13.218.*:allow

    sshd:222.77.15.*:allow

    以上寫法表示允許210和222兩個ip段連接sshd服務(這必然需要hosts.deny這個文件配合使用),當然:allow完全可以省略的。

    當然如果管理員集中在一個IP那么這樣寫是比較省事的

    all:218.24.129.110//他表示接受110這個ip的所有請求!

    /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!

    sshd:all:deny

    注意看:sshd:all:deny表示拒絕了所有sshd遠程連接。:deny可以省略。

    所以:當hosts.allow和 host.deny相沖突時,以hosts.allow設置為准。

    注意修改完后:

    service xinetd restart

    才能讓剛才的更改生效。

    總結:通過這種方法可以控制部分非授權訪問,但不是一勞永逸的方法!我們在看服務日志的時候或許會看到很多掃描記錄,不是還是直接針對root用戶的,這時控制你的訪問列表就非常有作用了!


免責聲明!

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



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