Linux provides many tools for configuring the network, including a graphical interface (such as
NetworkManager1) and a pseudo-graphical interface (such as system-config-network 2). Although
it is very convenient to use these tools to configure the network, because the network configuration tools provided by various Linux distributions
are likely to be completely different, and the remote login through the command line interface cannot use these
graphical interface tools, so we Instead of using tools to configure the network, choose
to configure the network parameters by directly editing the relevant files.
In the Linux system, the network is configured through several text files, which need to be edited
to complete the networking work. The important network configuration files in the system are: /etc/services,
/etc/host.conf, /etc/nsswitch.conf, /etc/xinetd.conf /etc/modules.conf,
/etc/sysconfig/network, / etc/hosts, /etc/resolv.conf and /etc/sysconfig/networkscripts/ifcfg-ethN. The last four files that we briefly explain here are also
the four files used in our assignment.
1 /etc/sysconfig/network file The
/etc/sysconfig/network file is used to set global network parameters for the host (that is, parameters that are not specific to a single
network interface).
Table error! There is no text in the specified style in the document. -1
parameter name parameter value NETWORKING=<value> The value of <value> indicates whether to configure the network, which can be the following values:
yes - configure the network
no - not configure the networkHOSTNAME=<value> <value> is the host name. Generally speaking, the host name should be a complete
FQDN (Fully Qualified Domain Name), that is,
host name + domain name, such as hostname.expample.com. But the host
name does not have to be FQDN, you can give the host a name in any formatGATEWAY=<value> <value> is the default gateway IP address of the network
Below is a sample
2 /etc/sysconfig/network-scripts/ifcfg-ethN file
For each network interface on the host there is a configuration required, in Linux there is
1 for each network interface NetworkManager is the default graphic in RHEL and CentOS Interface network parameter configuration tool, if the host does not have a desktop installed, then
there is no such tool.
2 system-config-network is a network parameter configuration tool with a text graphical interface provided in RHEL and CentOS. It can provide a text graphical interface under the
command line interface to configure network parameters.
Notice The above files all support comments starting with "#"
Notice The GATEWAY parameter in
/etc/sysconfig/network is overwritten by the GATEWAY parameter in /etc/sysconfig/network-scripts/ifcfg-eth0.
An independent configuration file, the file name is generally: /etc/sysconfig/network-scripts/ifcfg-ethN,
where N is a number, representing the serial number of the host network interface, for example, if there are multiple network interfaces in the host,
then the first The configuration file for one interface is called ifcfg-eth0, the configuration file for the second interface is called
ifcfg-eth1, and so on.
Network interface configuration files control the behavior of each network interface, and are used when the system starts
to determine which network interfaces to activate and how to configure them.
Note that some configurations in the network interface configuration file can affect other network interfaces
on entire host network configuration.
Table error! There is no text in the specified style in the document. -2
parameter name parameter value BOOTPROTO=<value> The <value> value indicates how to configure the host network parameters, which can
be the following values:
none/static — manually configure the host network
bootp — use the BOOTP protocol to dynamically configure the host network parameters.
dhcp — use the dhcp protocol to dynamically configure Host network parameters.DEVICE=<value> The <value> value represents the name of the physical device, that is, the name of the network card DEFROUTE = <value> The value of <value> indicates whether to use this network interface as the default route of the network
, which can be the following values:
yes — yes.
no — no.DNS{1,2}=<value> The value of <value> represents the IP address of the DNS server. Two DNS
servers, DNS1 and DNS2, can be added. If the PEERDNS parameter value is yes, then this DNS parameter value will override the DNS server configuration
in the /etc/resolv.conf file .HWADDR=<value> <value> is the MAC address of the Ethernet card, which is a 12-bit
hexadecimal string in the following format: AA:BB:CC:DD:EE:FF. This parameter is required if there are
more than It is guaranteed that
the device name will not change regardless of the loading order of the NICs, so that the correct configuration file can
be used to configure it.IPADDR=<value> <value> is the current network interface IP address. IPV4_FAILURE_FATAL
=<value>The <value> value refers to
whether IPv4 configuration failure is regarded as a device activation failure when both IPv4 and IPv6 configurations are available, and can be the following values:
yes — yes.
no — no.IPV6INIT=<value> <value>值表示是否对配置主机的 IPv6 网络参数,可以是
如下值:
yes — 是.
no — 否.NETMASK=<value> <value>值为当前网络接口的子网掩码. NM_CONTROLLED=<value> <value>值表示此网络接口是否允许 RHEL 和 CentOS 中
的默认图形界面的网络配置工具 NetworkManager 来进
行配置, 可以是如下值:
yes — 是.
no — 否.ONBOOT=<value> <value>值表示是否在启动时激活此网络接口,可以是如
下值:
yes — 是.
no — 否. PEERDNS=<value> <value>值表示是否允许接口配置文件中的 DNS 参数值覆
盖 /etc/resolv.conf 文件中的 DNS 服务器配置,可以
是如下值:
yes — 是.
no — 否.PEERROUTES=<value> SRCADDR=<value> 表示为从这个接口发出去的数据包指定另外一个源地址
<value> (而不是接口的 IP 地址).USERCTL=<value> The <value> value indicates whether users other than the root user are allowed to configure this
network interface, which can be the following values:
yes — yes.
no — no.
The following is an example of an /etc/sysconfig/network-scripts/ifcfg-ethN file:
3 The /etc/resolv.conf and /etc/hosts files
This file is a DNS client configuration file and has a very simple format, with each line starting with Begins with a keyword,
followed by configuration parameters. The most important is the nameserver keyword. If the nameserver is not specified,
the . Other keywords are optional.
Table error! There is no text in the specified style in the document. -3
parameter name parameter value nameserver =<value> <value> is the IP address of the DNS server, a total of 3 DNS
server IP addresses can be specifieddomain=<value> The <value> value indicates the local domain name search=<value> The <value> value represents a search list of domain names, which by default only includes local
domain names
下面是一个/etc/resolv.conf 文件的示例:
domain ringkee.com
search www.ringkee.com ringkee.com
nameserver 202.96.128.86
nameserver 202.96.128.166
/etc/hosts 文件是一个用于储存计算机网络中各节点信息的文件。这个文件
负责将主机名映射到相应的 IP 地址。 hosts 文件通常用于补充或取代小型网络
中 DNS 的功能。和 DNS 不同的是, 用户可以直接对/etc/hosts 文件进行控制。
在默认情况下, /etc/hosts 仅包括两行,分别用于指定 IPv4 网络中和 IPv6 网
络中回环接口的主机名(默认情况下为 localhost.localdomain) :
# IP 地址
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
下面是一个/etc/resolv.conf 文件的示例:
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
#以上两行建议保留
# IP 地址 主机名(Hostname) 主机别名(Alias)
208.164.186.1 deep.openna.com deep
208.164.186.2 mail.openna.com mail
208.164.186.3 web.openna.com web
configure tcp/ip
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=325479466&siteId=291194637
Recommended
Ranking