linux--安全配置hosts

1、/etc/hosts

[root@VM_0_11_centos etc]# cat hosts
127.0.0.1 VM_0_11_centos VM_0_11_centos
127.0.0.1 localhost.localdomain localhost
127.0.0.1 localhost4.localdomain4 localhost4

::1 VM_0_11_centos VM_0_11_centos
::1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6

       hosts文件是Linux系統上一個負責ip地址與域名快速解析的文件,以ascii格式保存在/etc/目錄下。hosts文件包含了ip地址與主機名之間的映射,還包括主機的別名。在沒有域名解析服務器的情況下,系統上的所有網絡程序都通過查詢該文件來解析對應於某個主機名的ip地址,否則就需要使用dns服務程序來解決。通過可以將常用的域名和ip地址映射加入到hosts文件中,實現快速方便的訪問。 

2、/etc/host.conf

[root@VM_0_11_centos etc]# cat host.conf
multi on
[root@VM_0_11_centos etc]#

指定如何解析主機域名。可設置網絡安全。 

默認情況,/etc/hosts.conf 文件有如下內容——

 order hosts,bind

     multi on

1)、order 是解析順序的參數,order hosts,bind,nis //說明先查詢解析/etc/hosts文件,然後DNS,再是NIS;

2)、 multi on  //表示是否運行/etc/hosts文件允許主機指定多個多個地址 ,on表示運行。

3、/etc/hosts.allow與/etc/hosts.deny

[root@VM_0_11_centos etc]# cat 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
#
[root@VM_0_11_centos etc]#
[root@VM_0_11_centos etc]# cat 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
#
[root@VM_0_11_centos etc]#

       /etc/hosts.allow和/etc/hosts.deny這兩個文件是tcpd服務器的配置文件,tcpd服務器可以控制外部IP對本機服務的訪問。一個IP請求連入,linux的檢查策略是先看/etc/hosts.allow中是否允許,如果允許直接放行;如果沒有,則再看/etc/hosts.deny中是否禁止,如果禁止那麼就禁止連入。 /etc/hosts.allow控制可以訪問本機的IP地址,/etc/hosts.deny控制禁止訪問本機的IP。如果兩個文件的配置有衝突,以/etc/hosts.deny爲準。

       兩個文件的配置方法,服務進程名:主機列表:當規則匹配時可選的命令。如下所示:

       sshd:192.168.100.0/255.255.255.0          #允許局域網內所有機器訪問服務器上的sshd進程
       sshd:60.28.160.244                                  #允許外網的60.28.160.244訪問這個服務器上的sshd進程

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章