Linux-related network configuration files __linux

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

In Linux systems, TCP/IP networks are configured with several text files that need to be edited to complete the networking effort. The 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
Next 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 a comment that starts with "#" and each file has one of the 5th parts of the Unix man page, which can be obtained by using the Man command.
/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 files and daemons associated with the network. 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 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 indicates the device name of the gateway, such as: eth0;
In order to be compatible with older software, the "/etc/hostname" file should use the same hostname as hostname=hostname.
[NextPage]
/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 file/etc/sysconfig/network, which is used to set the system's hostname at startup.
/etc/hosts IP address and host name Mapping
The/etc/hosts contains mappings between IP addresses and host names, as well as aliases of host names, which are designed to make computers easy to recognize, but difficult for people to remember, and to solve this problem, create a/etc/hosts 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 and alias Otheralias, which can point to Otheralias. Once the network profile for the machine is configured, you should restart the network for the modifications to take effect and restart the network using the following command:
/etc/rc.d/init.d/network restart
/etc/hosts files usually contain the host name, localhost, and system administrator frequently used system alias, sometimes telnet to the Linux machine to wait for a long time, through the "/etc/hosts" to join the client's machine IP address and host name of the match, You can reduce the logon wait time. In the absence of a domain name server, all network programs on the system query the file to resolve the IP address corresponding to a host name, otherwise, other host names are usually used by DNS to resolve, the DNS client part of the configuration in file/etc/resolv.conf.
/etc/services
The/etc/services contains a mapping between the service name and the port number, and many system programs use this file, and the following is the first few lines of the default/etc/services in the Redhat installation:
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 columns are aliases to the previous service. Aliases also exist in this file, which appear after the port number, in which sink and null are aliases for the discard service.
[NextPage]
/etc/host.conf Config name resolver
There are two file declaration systems where to find the name information to configure the UNIX name Parser library. The 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 the other, so it is necessary to configure all two files correctly.
The/etc/host.conf file specifies how the host name is resolved, and Linux obtains the IP address of the host name by using the parser library. The following is the default "/etc/host.conf" content after Redhat installation:
Order Hosts,bind
Multi on
※ "Order" specifies the sequence of host name queries, which are comma-separated lookup methods, supported lookup methods for BIND, hosts, and NIS, respectively, for DNS,/etc/hosts, and NIS, which are required to first query "/etc/hosts" File and then use DNS to resolve the domain name.
※ "Trim" indicates that the domain name will be cropped from the hostname when the address to hostname is converted through DNS, the trim can be included multiple domains, and the/etc/hosts and NIS query methods do not work, noting that in/etc/hosts and NIS tables The host name is appropriately ( With or without a full domain name) listed.
※ "Multi" Specifies whether the host specified in the "/etc/hosts" file can have multiple addresses, the value on is allowed, and hosts with multiple IP addresses are generally referred to as having more than one network interface.
※ "Nospoof" refers to whether to allow IP address spoofing to this server, the value of "on" is not allowed, IP spoofing is a means of attacking system security, by disguising the IP address as another computer, to obtain the trust of other computers.
※ "Alert" when the nospoof instruction is on, alert controls whether attempts to cheat are logged with the Syslog tool, the value is on, and the default is off.
※ "Rccorder" if set to ON, all queries will be reordered, so hosts on the same subnet will be preferred to be returned with the default value off.
[NextPage]
/etc/nsswitch.conf Config name resolver
The/etc/nsswitch.conf file is developed by S U N and used to manage the order of multiple configuration file lookups in the system, providing more functionality than the/etc/host.conf file. Each line in the/etc/nsswitch.conf is either a comment (beginning with a # sign) or a keyword followed by a colon and a series of sequential methods to try. Each keyword is the name of the/etc file that can be/etc/nsswitch.conf controlled in the/etc/directory. Here are the keywords that can be included:
※aliases Mail alias;
※PASSWD system users;
※group user Group;
※shadow covert 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 Network Group
The following are also the keywords you can include:
※files is valid for other keywords except netgroup. Find a record in the appropriate/etc file
※db is valid for 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 produce 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, you will first find it in the corresponding/etc file. If you want to do NIS lookup, you need the first value (user name or group name) as a plus sign (+) followed by a corresponding number of colons (:) (/etc/passwd 6,/etc/group 3,/etc/shadow 8). As in the/etc/passwd file, the following line should be included at the end of the file: +: *::::
※dns is only meaningful to hosts. As configured in/etc/resolvconf, find in DNS
※nis has meaning for all the keywords. If NIS is available, find in Server for NIS
※[STATUS = Action] controls the behavior of the name service. The status is success (the operation was executed successfully), NotFound (the record was not found), Unavail (the selected service is unavailable), and Tryagain (the service is temporarily unavailable, please retry). The action is one of the return (terminating the lookup and returning to the current state) or continue (the other items that continue this line). such as Hosts:dns NIS [notfound=return] files will be first in DNS and then the host name is found in NIS. Use file/etc/hosts only if both of the current 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 a space. 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:
[NextPage]
※nameserver indicates the IP address of the DNS server. There can be many rows of nameserver, each with an I-P address. In the query, press nameserver in the order in this file, and only if the first nameserver does not respond to query the following nameserver.
※domain declares the domain name of the host. Many programs use it, such as the messaging system, when DNS queries are made for hosts that do not have domain names. If no domain name, host name is used, delete all at the first point (.) The previous content.
※search its multiple parameters to 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 declared by search. Domain and search cannot coexist; if present, the following will be used.
※sortlist allows the result of the domain name to be given a specific sort. Its parameters are network/mask pairs, allowing arbitrary order of arrangement. Red Hat does not provide the default/E t c/r e s o L v. C o n f file, and its content is dynamically created based on the options given at installation.
/etc/init.d/network host address, subnet mask, and gateway
Unlike many other Unix and Linux operating systems, Red hat does not currently automatically configure the network with/etc/hostname and/etc/hosts files. In order to change the host default IP address, the/etc/init.d/network script must be edited directly to reflect the correct network configuration. This file includes variables that declare IP addresses, masks, networks, broadcast addresses, and default routers. The following are the corresponding sections in this file:
ipaddr=192.168.1.100
netmask=255.255.255.0
broadcast=192.168.1.255
gateway=192.168.1.1

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.