网络配置文件

Linux网络配置文件概述

网络配置文件

Linux下有许多文件可以配置-定义Linux网络。以下是您作为Linux系统管理员会遇到的一些主要文件。

/etc/resolv.conf

该文件用于配置DNS(域名系统)解析器库。resolv.conf配置文件包含DNS解析器使用的信息参数。DNS解析器允许操作系统将域名转换为IP地址。该过程称为解决。该文件的路径为/etc/resolv.conf

通常,resolv.conf文件将包含域的搜索顺序,当查询中未使用任何域后缀时,该搜索顺序将用于完全限定域名。您还将找到将用于DNS查找的名称服务器列表。通常,至少会提供两个名称服务器,一个用于主服务器,一个用于冗余服务器。

#/etc/resolv.conf
search mydomain.com mydomain.net
nameserver 8.8.8.8
nameserver 8.8.4.4

其中
search
search列表通常由本地域名决定。默认情况下,它只包含本地域名。要改变这一点,您可以在search关键字之后传递所需的名称搜索路径。目前最多可以列出六个域。

nameserver
名称服务器由其IP地址指定。如果参数名称服务器有多个条目,则解析器库将按找到的顺序查询这些条目。目前最多可以指定三个服务器。

/etc/hosts

hosts文件是一个静态查找表,用于将主机名映射到ip地址。可以将您的系统配置为在查询DNS之前首先查看主机文件中的条目。此首选项由位于/etc/nsswitch.conf的文件配置。通常,在大多数系统上首先咨询DNS。

hosts文件的格式:

IP地址    Full-Qualified-Hostname    Short-Hostname

该文件中的字段由制表符或空格分隔。主机名字段可能只包含alpha数字字符、减号-和句号.。短主机名或别名用于缩短的名称或昵称。

hosts文件示例:

       127.0.0.1       localhost
       192.168.1.10    foo.mydomain.org       foo
       192.168.1.13    bar.mydomain.org       bar
       146.82.138.7    master.debian.org      master
       209.237.226.90  www.opensource.org

/etc/hostname

hostname是一个用来设置或显示当前主机名的程序。主机名文件通常在系统启动时读取一次。如果执行的主机名例程没有参数,则显示当前主机名。您可以传递以下任何选项到hostname:

[root@centos ~]# hostname
centos

以下是一些可以传递到hostname命令的可用的选项:

OPTIONS
       -a, --alias
              Display the alias name of the host (if used).

       -d, --domain
              Display  the  name  of  the  DNS  domain.  Don't use the command
              domainname to get the DNS domain name because it will  show  the
              NIS  domain  name and not the DNS domain name. Use dnsdomainname
              instead.

       -F, --file filename
              Read the host name from  the  specified  file.  Comments  (lines
              starting with a `#') are ignored.

       -f, --fqdn, --long
              Display  the FQDN (Fully Qualified Domain Name). A FQDN consists
              of a short host name and the DNS domain  name.  Unless  you  are
              using  bind  or NIS for host lookups you can change the FQDN and
              the DNS  domain  name  (which  is  part  of  the  FQDN)  in  the
              /etc/hosts file.

       -h, --help
              Print a usage message and exit.

       -i, --ip-address
              Display the IP address(es) of the host.

       -n, --node
              Display the DECnet node name. If a parameter is given (or --file
              name ) the root can also set a new node name.

       -s, --short
              Display the short host name. This is the host name  cut  at  the
              first dot.

       -V, --version
              Print  version  information on standard output and exit success-
              fully.

       -v, --verbose
              Be verbose and tell what's going on.

/etc/nsswitch.conf

/etc/nsswitch.conf文件包含有关如何执行各种系统查找的设置。
在这里,你可以配置你的系统使用/etc/hosts/etc/passwd文件本地或使用NIS服务器或DNS。conf的主要功能之一是控制网络的解析方式。
在下面来自Ubuntu 12.04系统和CentOS系统的例子中,我们可以看到files是在搜索顺序中首先指定的。这意味着在访问命名服务器之前首先要查看主机文件。大多数情况下是nsswitch.conf文件取代/etc/host.conf`文件。

Ubuntu 12.04 LTS

# /etc/nsswitch.conf
#
# Example configuration of GNU Name Service Switch functionality.
# If you have the `glibc-doc-reference' and `info' packages installed, try:
# `info libc "Name Service Switch"' for information about this file.

passwd:         compat
group:          compat
shadow:         compat

hosts:          files mdns4_minimal [NOTFOUND=return] dns mdns4
networks:       files

protocols:      db files
services:       db files
ethers:         db files
rpc:            db files

netgroup:       nis

CentOS

hosts:      files dns

/etc/host.conf

正如我们前面提到的,这个文件被/etc/nsswitch.conf文件所取代。

在Ubuntu 12.04中示例:

order hosts,bind
multi on

/etc/networks

此文件用于描述网络。每个有效的条目应该以0结尾。

[root@centos ~]# cat /etc/networks
default 0.0.0.0
loopback 127.0.0.0
link-local 169.254.0.0
日期:2019-04-29 03:17:34 来源:oir作者:oir