Network configuration file

xiaoxiao2021-03-06  118

In the Linux system, the TCP / IP network is configured by several text files, which requires editing these files to complete the networked work. Important network profiles in the system are:

◆ / etc / sysconfig / network

◆ / ETC / Hostname

◆ / etc / hosts

◆ / etc / services

◆ /etc/host.conf

◆ /etc/nsswitch.conf

◆ /etc/resolv.conf

◆ /etc/rc.d/init.d/network

Next, we will tell these files one by one, these files can be modified when the system is running, do not have to start or stop any daemon, and change will take effect immediately (except / etc / sysconfig / network). In addition, these files support annotations from "#", each file has one in a section 5 in the UNIX man page, and can use the Man command to get them.

◆ / etc / sysconfig / network setup

This file is used to specify network configuration information on the server, including parameters of behavior of files related to the control and network, and daemons. Here is an example file:

Networking = yes

Hostname = Machine1

Gateway = 210.34.6.2

Forward_IPv4 = YES

GatewayDev =

Among them, NetWork = YES / NO indicates whether the network is configured;

Hostname = hostname hostname indicates the host name of the server;

GATEWAY = GW-IP GW-IP represents the IP address of the network gateway;

Whether IP forwarding function is turned on forward_ipv4 = yes / no.

GarewayDev = GW-dev GW-DW indicates the device name of the gateway, such as: eth0, etc .;

In order to be compatible with some software, the "/ etc / hostname" file should be used with HostName = HostName.

◆ / etc / hostname host name

This file contains the host name of the system, including a complete domain name, such as:

192.168.0.1 Machine1.domain Machine11

This file is obtained from the hostname line in the file / etc / sysconfig / network when startup, which is used to set the host name of the system at startup.

◆ Mapping of / etc / hosts IP address and hostname

/ etc / hosts include mappings between IP addresses and hostnames, including the alias of the host name, the design of the IP address makes the computer easily identified, but it is difficult for people to remember them, in order to solve this problem, create / etc / hosts this file. Here is an example file:

127.0.0.1 Machine1 Localhost.localdomain Localhost

192.168.1.100 Machine7

192.168.1.101 OtherPC Otheralias

In this example, this name is Machine1, OtherPC and alias Otheralias, which can point to Otheralias. . Once the machine's network configuration file should be configured, you should restart the network to take effect, use the following command to restart the network:

/etc/rc.d/init.d/network restart

/ etc / hosts file typically contains host names, localhost, and system administrators often use system alias, sometimes telnet to Linux machines wait for a long time, can be added in "/ etc / hosts" to join customers' IP addresses and The host name matching item can reduce the login waiting time. In the case where there is no domain name server, all network programs on the system are parsed by querying the file, otherwise, other host names usually use DNS to solve, DNS client partial configuration in file / Etc / resolv.conf. ◆ / etc / services

/ etc / services contains mappings between service names and port numbers, and a lot of system programs use this file. The following is the first few lines in the default / etc / service when the RedHat is installed:

TCPMUX 1 / TCP # TCP Port Service Multiplexer

ECHO 7 / TCP

ECHO 7 / UDP

Discard 9 / TCP Sink Null

Discard 9 / UDP Sink Null

SYSTAT 11 / TCP USERS

The leftmost list is the host service name, the middle one is the port number, "/" is the port type, which can be TCP or UDP. Any back columns are the alias for the previous service. There is also an alias in this file, which appears behind the port number, in the above examples, SINK and NULL are the alias of the Discard service.

◆ /etc/host.conf configuration name parser

There are two file declaration systems to find name information to configure the library of UNIX name parsers. File /etc/host.conf is used by the libc library of version 5, and /etc/nsswitch.conf is used by version 6 (GLIBC). The problem is that some programs use one, and some use one, so it is necessary to configure both files.

The /etc/host.conf file specifies how to resolve the host name, Linux obtains the IP address corresponding to the host name through the parser library. Below is the default "/etc/host.conf" after the RedHat installation:

ORDER HOSTS, BIND

Multi on

※ "Order" Specifies the host name query order, which is a comma-separated lookup method, supported findings are Bind, Hosts, and NIS, represent DNS, / ETC / HOSTS, and NIS, respectively, and set first query "/ etc / hosts file then use DNS to resolve domain names.

* "Trim" indicates that when the address to the host name is performed via DNS, the domain name will be cropped from the host name, and Trim can be included in multiple domains multiple times, and the / etc / hosts and NIS query methods do not work. Note that the host name is listed appropriately (with or without all domain names) in the / etc / hosts and nis tables.

※ "Multi" Specifies whether the host specified in the "/ etc / hosts" file can have multiple addresses, the value is ON means allowing, the host with multiple IP addresses is generally referred to as having multiple network interfaces.

※ "NOSPOOF" refers to whether the server is allowed to deceive the server, and the value is not allowed. IP spoof is a means of attacking system security, and the trust of other computers is achieved by disguise the IP address into other computers.

※ "Alert" When the NospooF command is ON, the Alert controls whether the deceived attempt is recorded with the syslog tool, and the value is ON, the default is OFF.

※ "RCCORDER" If set to ON, all queries will be reordered, so the host in the same subnet will be first selected, the default is OFF. ◆ /etc/nsswitch.conf configuration name parser

The /etc/nsswitch.conf file is developed by S u n and is used to manage multiple configuration files in the system, which provides more features than /etc/host.conf files. Each row in /etc/nsswitch.conf or comments (starting with ##) or a keyword and a series of sequential methods to trial. Each keyword is the name of the / etc file that can be controlled by / ETC / directory. Below is the keyword that can be included:

※ Aliases mail alias;

※ Passwd system user;

※ Group user group;

※ Shadow hidden password;

※ Hosts host name and I p address;

※ NetWorks network name and number;

※ Protocols network protocol;

※ SERVICES port number and service name;

※ Ethers Ethernet number;

※ Name and number of RPC remote process call

※ NETGROUP network group

The following is also the keyword that can be included:

※ Files is valid for other keywords in addition to NetGroup. Looking for records in the corresponding / etc file

※ DB is valid for other keywords in addition to NetGroup. Look for records in the corresponding / var / dB database. Very effective for long files, such as the Passwd file has exceeded 500. To generate these files from the standard / etc file, you should change the directory to / var / dB and run the run command.

※ Compat compatibility mode is valid for Passwd, Group, and Shadow files. In this mode, you will look up in the corresponding / etc file. If you want to make NIS lookup, you need the first value (username or group name) to plus a plus ( ), followed by the corresponding quantity colon (:) (/ etc / passwd is 6, / etc / group is 3 , / Etc / shadow is 8). As in the / etc / passwd file, the following line should be included in the file tail: : *::::::

※ DNS is only meaningful for Hosts. Like in / etc / resolvconf configuration, look for DNS

※ NIS is meaningful for all keywords. If NIS is available, look for in the NIS server

※ [status = action] Controls the behavior of the name service. Status is Success (operation is successful), NOTFOUND (not found), unavail (the selected service is not available) and the Tryagain (temporary is not available, please try again). Action is Return (terminating finding and returning the current state) or one of the Continue (other items to continue this line). Such as Hosts: DNS NIS [NOTFOUND = RETURN] FILES will first in DNS and then look up in NIS. Use files only when both current are not available, ETC / HOSTS

◆ /etc/resolv.conf Configure DNS customers

File /etc/resolv.conf Configure DNS customers, which contains the domain name search order of the host and the address of the DNS server, and each line should contain a keyword and one or more parameters separated by spaces. Here is an example file:

Search mydom.edu.cn

Nameserver 210.34.0.14

Nameserver 210.34.0.2

The legal parameters and its significance are as follows:

※ Nameserver indicates the IP address of the DNS server. There are many rows of Nameserver, each with an I P address. Press Nameserver in the order in this document in the query and only queries the following NAMESERVER. ※ Domain declares the domain name of the host when the first NAMSERVER does not respond. Many programs are used in it, such as a mail system; when DNS queries are performed for hosts without a domain name, it is also used. If there is no domain name, the host name will be used, delete all the contents in front of the first point (.).

※ Search Its multiple parameters refers to the order of domain name query. When you want to query the host without a domain name, the host will find separately in the domain declared by the Search. Domain and Search cannot coexist; if there is at the same time, will be used later.

※ Sortlist allows specific sorting to get the domain name results. Its parameters are network / mask pairs, allowing any arrangement order. The default / e t C / R E S O L V. C O N f file is provided in the Red Hat, which is dynamically created based on the options given during installation.

◆ /etc/init.d/network host address, subnet mask and gateway

Unlike many other UNIX and Linux operating systems, Red Hat does not automatically configure networks through the / etc / hostname, and / etc / hosts files. In order to change the host's default IP address, you must edit the /etc/init.d/network script to reflect the correct network configuration. This file includes variables that declare an IP address, mask, network, broadcast address, and default router. Below is the appropriate part of this file:

Ipaddr = 192.168.1.100

Netmask = 255.255.255.0

Broadcast = 192.168.1.255

Gateway = 192.168.1.1