Troubleshooting Linux network configuration, starting with familiarity with network configuration files

Source: Internet
Author: User
Tags aliases echo 7 domain name server nameserver

If you have access to Linux, network configuration is a tricky issue.
But Linux is a file-based system, including our Windows devices, and Linux is also considered a file. So as long as we understand the role of the document. Can be more familiar with Linux, network configuration is also. So in order to familiarize and solve the Linux network configuration, first start with the network configuration file.
This inside organize and gather more information, from multi-angle, many articles, hope to be able to read patiently.
I. A brief overview
DNS configuration file
[Email protected] etc]# cat/etc/resolv.conf
NameServer 210.36.16.33
NameServer 202.103.224.68
Search Localdomain
IP configuration file
[Email protected] etc]# Cat/etc/sysconfig/network-scripts/ifcfg-eth0
Device=eth0
Bootproto=static
hwaddr=00:04:23:c4:9d:0c
ipaddr=192.168.2.86
netmask=255.255.255.0
Onboot=yes
Type=ethernet
Gateway
[Email protected] etc]# cat/etc/sysconfig/network
Networking=yes
Hostname=localhost.localdomain//Command-line display name, such as [[email protected] ~]#
gateway=192.168.2.254//can also be placed in Ifcfg-eth0
Host Name
[Email protected] patches]# cat/etc/hosts
# don't remove the following line, or various programs
# that require network functionality would fail.
127.0.0.1 localhost.localdomain localhost


Two detailed introduction
In a Linux system, TCP/IP networks are configured with several text files that need to be edited to complete the networking effort. Important Network configuration files 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

We'll talk about each of these files, which can be modified while the system is running, without starting or stopping any daemons, and the changes will take effect immediately (except/etc/sysconfig/network). In addition, these files support comments that begin with "#", and each file has one of the 5th parts of the UNIX man page, which can be obtained with the man command, such as Man 5 hosts and man 5 services.

/etc/sysconfig/network Network Settings
This file is used to specify the network configuration information on the server and contains parameters for controlling the behavior of the network-related files and daemons. Here is an example file:

Networking=yes
Hostname=machine1
gateway=210.34.6.2
Forward_ipv4=yes
gatewaydev=

Where network=yes/no indicates whether the network is configured;
Hostname=hostname HOSTNAME represents the host name of the server;
Gateway=gw-ip Gw-ip represents the IP address of the network gateway;
Forward_ipv4=yes/no whether the IP forwarding function is turned on;
Garewaydev=gw-dev GW-DW represents the device name of the gateway, such as: eth0, etc.;
In order to be compatible with some old software, the "/etc/hostname" file should use the same hostname as hostname=hostname.

/etc/hostname Host Name

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

192.168.0.1 Machine1.domain Machine1

This file is obtained at startup from the HOSTNAME line in the file/etc/sysconfig/network, and is used to set the hostname of the system at startup.

/etc/hosts IP Address and host name mappings

/etc/hosts includes the mapping between IP address and host name, including the alias of hostname, IP address design makes the computer easy to recognize, but it is difficult for people to remember them, in order to solve this problem, created/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, the native name is Machine1, OTHERPC also has an alias Otheralias, which can point to Otheralias. Once you have configured your machine's network configuration file, you should restart the network for the changes to take effect and use the following command to restart the network:

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

/etc/hosts files typically contain host names, localhost, and system aliases that are often used by system administrators, and sometimes telnet to a Linux machine waits a long time, and by adding a match to the IP address and hostname of the client's machine at "/etc/hosts", you can To reduce the logon wait time. In the absence of a domain name server, all network programs on the system resolve the IP address corresponding to a host name by querying the file, otherwise, the other hostname is usually resolved with DNS, and the DNS client portion is configured in file/etc/resolv.conf.

/etc/services mapping between service name and port number

/etc/services contains the service name and port number mapping between the number of system programs to use this file, the following is the RedHat installation of the default/etc/services in the first few lines:

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 column is the host service name, the middle column is the port number, and the "/" is followed by the ports type, either TCP or UDP. Any subsequent column is an alias for the preceding service. There are also aliases in this file, which appear after the port number, in the above example sink and null are aliases for the discard service.

/etc/host.conf Configuring the name resolver

There are two files declaring the system where to look for the name information to configure the UNIX name Parser Library. File/etc/host.conf is used by version 5 of the LIBC library, and/etc/nsswitch.conf is used by version 6 (GLIBC). The problem is that some programs use one, and some use the other, so it is necessary to configure two files correctly.

The/etc/host.conf file specifies how to resolve the hostname, and Linux uses the parser library to obtain the IP address of the host name. The following is the default "/etc/host.conf" content after Redhat installation:

Order Hosts,bind
Multi on

※ "Order" specifies the hostname query order, whose parameters are comma-separated lookup methods, supported by BIND, hosts, and NIS, respectively, representing DNS,/etc/hosts, and NIS, which specifies that the "/etc/hosts" file is queried before use DNS to resolve domain names.
※ "Trim" indicates that when the address to hostname conversion through DNS, the domain name will be clipped from the host name, trim can be contained multiple domains, the/etc/hosts and NIS query methods do not work, note that in the/etc/hosts and NIS table in the host name is properly (with or without a full domain name) listed.
※ "Multi" Specifies whether the host specified in the "/etc/hosts" file can have more than one address, the value is on to allow, hosts with multiple IP addresses are generally referred to as having multiple network interfaces.
※ "Nospoof" refers to whether IP address spoofing is allowed on the server, the value is on means no, IP spoofing is an attack system security means, by the IP address disguised as another computer, to obtain the trust of other computers.
※ "Alert" when the nospoof instruction is on, the alert control spoofing attempt is logged with the Syslog tool, the value is on for use, and the default value is off.
※ If "Rccorder" is set to ON, all queries will be reordered, so hosts in the same subnet will prefer to be returned, the default value is off.

/etc/nsswitch.conf Configuring the name resolver

The/etc/nsswitch.conf file is developed by S U N Company and is used to manage the order of multiple profile lookups in the system, which provides more functionality than the/etc/host.conf file. Each line in the/etc/nsswitch.conf is either a comment (beginning with a # number) or a keyword followed by a colon and a series of sequential methods to try. Each keyword is the name of the/etc file in the/etc/directory that can be controlled by/etc/nsswitch.conf. Here are the keywords that can be included:

※aliases Mail aliases;
※PASSWD system users;
※group user Group;
※shadow secret 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;
※RPC the name and number of the remote process call
※netgroup in-Network group

The following are also keywords that can be included:

※files is valid for all other keywords except netgroup. Find records in the corresponding/etc file
※DB is valid for all other keywords except netgroup. Look for records in the appropriate/var/db database. Works well for long files, such as the passwd file has more than 500 items. To generate these files from a standard/etc file, you should change the directory to/var/db and run the running command
※compat compatibility mode, valid for passwd, group, and shadow files. In this mode, the corresponding/etc file will be searched first. If you want to do an NIS lookup, you need the first value (user or group name) as a plus sign (+) followed by the corresponding number of colons (:) (/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 end of the file: +: *:::::
※dns only has meaning for the hosts. As configured in/etc/resolvconf, find in DNS
※nis has meaning for all the keywords. If NIS is available, look in Server for NIS
※[STATUS = Action] controls the behavior of the name service. STATUS is one of the SUCCESS (the operation was executed successfully), NOTFOUND (the record was not found), UNAVAIL (the selected service is not available), and Tryagain (the service is temporarily unavailable, please try again). The action is one of the return (terminating the lookup and returning the current state) or continue (another item that continues this line). For example, Hosts:dns NIS [notfound=return] files will first be in DNS and then find the hostname in NIS. Use file/etc/hosts only if the current two items are not available

/etc/resolv.conf Configuring DNS Clients

File/etc/resolv.conf configures a DNS client that contains the domain name search order of the host and the address of the DNS server, each of which should contain one 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 valid parameters and their meanings are as follows:

※nameserver indicates the IP address of the DNS server. There can be many rows of nameserver, each with an I-P address. At query time, the order of nameserver in this file is performed, and the following nameserver is queried only if the first nameserver is unresponsive.
※domain declares the domain name of the host. Many programs use it, such as a mail system, and are used when DNS queries are made for hosts that do not have a domain name. If there is no domain name, the host name is used, and all the contents in front of the first point (.) are deleted.
※search its multiple parameters indicate the order of the domain name query. When you want to query a host that does not have a domain name, the host is found separately in the domain that is declared by search. Domain and search cannot coexist, and if they exist at the same time, subsequent occurrences will be used.
※sortlist allows a specific sort of domain results to be obtained. Its parameters are network/mask pairs that allow arbitrary order of arrangement. Red Hat does not provide a default/E t c/r e s o L v. C o n f file, which is created dynamically based on the options given at the time of installation.

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

Unlike many other UNIX and Linux operating systems, Red Hat is not currently able to automatically configure the network through/etc/hostname and/etc/hosts files. In order to change the host default IP address, you must edit the/etc/init.d/network script directly to reflect the correct network configuration. This file includes variables that declare the IP address, mask, network, broadcast address, and default router. Here is the corresponding section in this file:

ipaddr=192.168.1.100
netmask=255.255.255.0
broadcast=192.168.1.255
gateway=192.168.1.1

Troubleshooting Linux network configuration, starting with familiarity with network configuration files

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.