[网络相关]/etc/host.conf & /etc/hosts/ & /etc/resolv.conf等等

来源:互联网 发布:公网ip绑定域名 编辑:程序博客网 时间:2024/04/26 09:34

买了本自己一直期望的书《Linux系统架构与目录解析》,其实想要这样一本书很久了。虽然不是一个sa,但是也想对linux做到应用方面的熟练,而对linux整体把握,甚至细到有哪些目录,哪些文件,这些文件是做什么用的,我想做到这些应该能水平提升不少。


初步浏览了这本书,正如作者所说这本书书更像是工具书,适合查阅,而不是通篇读。又正如有人评论这本书,感觉正入境了,作者却停止了他的思绪---讲得比较浅。而我要这本书仅仅是作为一个大纲。然后自己慢慢去网上找相关更详细的资料去研究。好了,废话不多说。

今天主要谈的三个文件

/etc/host.conf       #1

/etc/hosts             #2

/etc/resolv.conf    #3


第一个/etc/host.conf,linux中通过解析库将host name解析成ip地址,而host.conf则告诉linux用什么方式去解析。通过编辑/etc/host.conf来添加相关条目,举例子

# Lookup names via DNS first then fall back to /etc/hosts.
           order bind,hosts
           # We have machines with multiple IP addresses.
           multi on
           # Check for IP address spoofing.
           nospoof on

常用的就是oder,multi,nospoof这三项。

order:通过什么顺序来解析host name,这里表示先通过name server解析host name,然后通过查找/etc/hosts文件。 bind(Berkeley Internet Name Domain),一种开源DNS协议实现。

multi on:允许一个主机名对应多个ip地址,如果你的机器有多网卡,那么这个就设置为on

nospoof on:这个主要是从安全考虑,防止黑客攻击,原理我也不大清楚,默认就是on的


第二个/etc/hosts,在上面提到了当设置了order里面包含hosts,那么表示要查找这个/etc/hosts文件(前提当然是在name server里面没找到,或是hosts的顺序在bind之前),可以编辑/etc/hosts

格式为:

ip地址  域名 别名, 比如 192.169.131.2  www.example.com example.com


第三个为/etc/resolv.conf(不是resolve.conf) ,这个是记录的域名服务器,name server

常见的有下面几种类型

domain   your_domain

nameserver  ip_address


上面主要是网络中的域名解析成IP地址相关的文件,原理就不多说了。另外还有两个文件/etc/hosts.allow,/etc/hosts.deny 这两个就类似于白名单、黑名单,如果配置了,先查找hosts.allow,如果需要再查找hosts.deny但是一般情况下应该不怎么用到。


参考文章:

1. http://www.faqs.org/docs/securing/chap5sec39.html /etc/host.conf

2. http://linux.die.net/man/5/hosts /etc/hosts

3. http://linux.die.net/man/5/resolv.conf /etc/resolv.conf

原创粉丝点击