Linux network configuration related files

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

network Interface (interface) is the network hardware device in the operating system representation method, such as NIC in the Linux operating system with EthX, is a positive integer starting from 0, such as eth0, eth1 ... ethX. And the common cat and ADSL interface is pppx, such as ppp0 and so on;

all available NICs and names in the machine:
Reference: Linux network configuration related commands, virtual network interface eth0:0

Gateways Gateway configuration address:
/etc/sysconfig/network gateway=192.168.1.250
/etc/sysconfig/network-scripts/ifcfg-eth0 gateway=192.168.1.250

DNS configuration address:
/etc/resolv.conf
When the general DHCP method obtains the IP address, the gateway, the route, the IP address and so on do not need to set manually!

network configuration related files:

    • /etc/sysconfig/network-scripts/ifcfg-ethx:configuration The configuration file for the file for Network Interfaces Networking Interface (NIC) (Configure IP, mask, Broadcast address, MAC address, gateway address, DHCP, etc.)   If you add a network card, you can manually copy the Ifcfg-eth0 and name it ifcfg-eth1, after modifying the configuration, restart the network
    • /etc/sysconfig/ network  Network Base settings file (configure host name, network availability, etc.)
    • /etc/resolv.conf        Configure the DNS domain name resolution server
    • /etc/networks network definition file: Displays known network name information (typically not modified by default)
    • /etc/hosts               Configure the mapping of IP addresses and hostnames (typically no modification is required by default)
    • /etc/services            Network Service list and mapping between service and port number (typically no modification is required by default)
    • /etc/host.conf           Configure domain name lookup order 1 (typically no modification is required by default)
    • /etc/nsswitch.conf       Configure domain name lookup order 2 (typically no modification is required by default)


These files 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 and/etc/sysconfig/network-scripts/ IFCFG-ETHX). In addition, these files support comments that begin with "#", and each file has one of the 5th parts in the Linux Help man page, which can be obtained by using the Man command.  

/etc/sysconfig/network-scripts/ifcfg-ethx: Configuration file for network interface (NIC) (Configure IP, mask, broadcast address, MAC address, gateway address, DHCP, etc.) , you need to restart the network after modification.  
configuration dhcp: 
device=eth0 
bootproto=dhcp 
Onboot=yes (DHCP configuration method is so simple)  

Configure static Address:  
device=eth0 
Bootproto=static (or none)  
ipaddr=192.168.0.1 
netmask=255.255.255.0 
gateway=192.168.0.254 
onboot=yes 

parameter explanation:  
Complete parameter Description reference: Linux Certif-man ifcfg (5)  

    • device=eth0# NIC Device name-Required field
    • bootproto=static# system gets the IP protocol type DHCP BOOTP none-must field
    • onboot=yes# Activate Yes at startup | No-required fields
    • ipaddr=192.168.1.90# Network IP address-static IP must be
    • netmask=255.255.255.0# Network Subnet mask address-static static IP must be
    • type=ethernet# network card type is Ethernet
    • hwaddr=00:0c:29:fe:1a:09# Network card MAC address
    • broadcast=192.168.1.255# broadcast address-can be computed based on IP address and subnet mask address
    • gateway=192.168.1.1# Gateway Address
    • Userctl=answer, whether a non-root user can control the device: yes | No no no No


/etc/sysconfig/network Network Infrastructure settings file (configure host name, network availability, etc.)
This file is used to specify the network configuration information on the server, including information such as whether the network is available, host name, etc. Here is an example file:

HTML code
    1. networking=Yes
    2. Hostname=machine1
    3. gateway=210.34.6.2
    4. forward_ipv4=Yes
    5. gatewaydev=

    • 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.;


/etc/resolv.conf Configuring DNS domain name Resolution server
File/etc/resolv.conf Configure the DNS domain name resolution server, which 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:

HTML code
    1. Search mydom.edu.cn
    2. NameServer 210.34.0.14
    3. 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 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 hostname is used, removing all at the first point (.) The previous content.
    • 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. The default/etc/resolv.conf file is not available in Red hat, and its content is created dynamically based on the options given at the time of installation.


/etc/networks Network definition file: Displays known network name information
The file is a plain text file that describes the known DARPA network and name. Each row represents a network

/etc/hosts Configuring the mapping of IP addresses and host names
The/etc/hosts contains the mapping between the IP address and host name, in the format: IP address standard hostname [multiple optional aliases]. Here is an example file:

HTML code
    1. 127.0.0.1 localhost localhost.localdomain machine1
    2. 192.168.1.100 Machine7
    3. 192.168.1.101 Otherpc Otheralias



/etc/services: Network Service list and mapping between service and port number
/etc/services contains all of the network service name and port number mapping between, a lot of system programs to use this file. Linux System Port Classification: Universal Port: 0-1023 can be registered port: 1024-49151 Dynamic or Private port: 49152-65535. The following are the first few lines of the default/etc/services in Redhat installation:

HTML code
    1. Tcpmux 1/tcp # TCP Port Service multiplexer
    2. Echo 7/tcp
    3. Echo 7/UDP
    4. Discard 9/tcp sink NULL
    5. Discard 9/udp sink NULL
    6. Systat 11/TCP Users


The leftmost column is the network 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 Domain name lookup Order 1
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:

HTML code
    1. Order Hosts,bind
    2. Multi on

    • "Order" specifies the host name query order, whose parameters are comma-separated lookup methods, supported by BIND, hosts, and NIS, respectively, representing DNS,/etc/hosts, and Nis, where "/etc/hosts" is specified first File and then use DNS to resolve the domain name.
    • "Trim" indicates that when the address-to-hostname conversion is done through DNS, the domain name is clipped from the host name, trim can be contained multiple times in several domains, and the/etc/hosts and NIS query methods do not work, noting that the hostname in the/etc/hosts and NIS tables is properly ( With or without a full domain name) listed.
    • "Multi" Specifies whether the host specified in the "/etc/hosts" file can have multiple addresses, with a value of 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 not allowed, IP spoofing is a means of attacking the system security, 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, with the default value off.



/etc/nsswitch.conf Configuring Domain name Lookup order 2
The/etc/nsswitch.conf file is a sequence developed by sun and used to manage 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 groups;
    • Shadow secret password;
    • Hosts hostname 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 the RPC remote process call
    • Netgroup in-Network group


The following are also keywords that can be included:

      • Files are valid for other keywords in addition to netgroup. Find records in the corresponding/etc file
      • DB is valid for other keywords in addition to 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 is only meaningful for 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

Linux network configuration related files

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.