In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >
Share
Shulou(Shulou.com)05/31 Report--
This article will explain in detail the example analysis of Redhat network-related configuration files. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
In the linux system, the TCP/IP 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/sysconfig/network
◆ / etc/HOSTNAME
◆ / etc/hosts
◆ / etc/services
◆ / etc/host.conf
◆ / etc/nsswitch.conf
◆ / etc/resolv.conf
◆ / etc/rc.d/init.d/network [@ more@]
We'll talk about these files one by one, all of which can be modified while the system is running, without starting or stopping any daemons, the changes will take effect immediately (except / etc / sysconfig/network). In addition, these files support comments starting with "#", and each file has an entry in part 5 of the UNIX man page, which can be obtained with the man command.
◆ / etc/sysconfig/network network settings
This file is used to specify network configuration information on the server and contains parameters that control the behavior of 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 hostname of the server
GATEWAY=gw-ip gw-ip represents the IP address of the network gateway
Whether FORWARD_IPV4=yes/no enables IP forwarding
GAREWAYDEV=gw-dev gw-dw indicates the device name of the gateway, such as eth0, etc.
In order to be compatible with some older software, the "/ etc/HOSTNAME" file should have the same hostname as HOSTNAME=hostname.
◆ / etc/HOSTNAME hostname
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 from the HOSTNAME line in the file / etc/sysconfig/network at startup and is used to set the hostname of the system at startup.
Mapping between ◆ / etc/hosts IP address and hostname
/ etc/hosts contains the mapping between IP addresses and host names, as well as aliases for host names. IP addresses are designed to make it easy for computers to recognize them, but it is difficult for people to remember them. In order to solve this problem, the file / etc/hosts is created. 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 the alias otheralias, which can point to otheralias. Once you have configured the machine's network profile, you should restart the network for the changes to take effect, using the following command to restart the network:
/ etc/rc.d/init.d/network restart
/ etc/hosts files usually contain hostnames, localhost, and system aliases that are often used by system administrators. Sometimes it takes a long time to wait from telnet to linux machines, and you can reduce the login wait time by adding a match between the IP address and hostname of the customer's machine in "/ etc/hosts". In the absence of a domain name server, all network programs on the system resolve the IP address corresponding to a hostname by querying the file, otherwise, other hostnames are usually solved using DNS, and the configuration of the DNS client part is in the file / etc / resolv.conf.
◆ / etc/services
The mapping between service name and port number is included in / etc/services, which is used by many system programs. Here are the first few lines in / etc/services, the default for 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 "/" is followed by the port type, which can be TCP or UDP. Any subsequent column is an alias for the previous service. There are also aliases in this file, which appear after the port number, and in the above example sink and null are aliases for the discard service.
◆ / etc/host.conf configuration name parser
There are two files that declare where the system can find name information to configure the library of the UNIX name parser. The file / etc/host.conf is used by the version 5 libc library, while / 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 both files correctly.
The / etc/host.conf file specifies how to resolve the hostname, and linux obtains the IP address corresponding to the hostname through the parser library. The following is the default "/ etc/host.conf" content after RedHat installation:
Order hosts,bind
Multi on
Query "order" specifies the query order of the hostname. Its parameters are comma-separated lookup methods. The supported lookup methods are bind, hosts and nis, which represent DNS, / etc/hosts and NIS, respectively. It is stipulated that the "/ etc/hosts" file is queried first and then DNS is used to resolve the domain name.
Address "trim" indicates that when address to host name translation is done through DNS, the domain name will be trimmed from the host name, trim can be included in multiple domains, and the / etc/hosts and NIS query methods will not work. Note that the host name is listed appropriately (with or without the full domain name) in the / etc/hosts and NIS tables.
"multi" specifies whether the host specified in the "/ etc/hosts" file can have multiple addresses. A value of on means allowed. Hosts with multiple IP addresses are generally referred to as having multiple network interfaces.
Spoofing "nospoof" refers to whether IP address spoofing is allowed on the server. A value of on indicates that it is not allowed. IP spoofing is a means of attacking system security by disguising the IP address as another computer to gain the trust of other computers.
Spoofing "alert" when the nospoof instruction is on, alert controls whether spoofing attempts are recorded with the syslog tool. The value on indicates use, and the default value is off.
Query "rccorder" if set to on, all queries will be reordered, so hosts in the same subnet will be returned first, with the default value of off.
◆ / etc/nsswitch.conf configuration name parser
/ etc/nsswitch.conf file is developed by S u n company and used to manage the order of multiple profile lookups in the system. It provides more functions than / etc/host.conf file. Each line in / etc/nsswitch.conf is either a comment (starting 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 controlled by / etc/ nsswitch.conf in the / etc/ directory. Here are the keywords that can be included:
"aliases mail alias
"passwd system user
"group user group
Hidden shadow password
"hosts hostname and IP address
"networks network name and number
Protocols network protocol
"services port number and service name
Ethers Ethernet number
The name and number of the remote process call to rpc
Intra-netgroup network group
The following are also keywords that can be included:
Invalid files is valid for all keywords except netgroup. Look for records in the corresponding / etc file
Invalid db is valid for all keywords except netgroup. Look for records in the corresponding / var/db database. It is effective for long files, such as passwd files, which have more than 500 entries. To generate these files from the standard / etc file, change the directory to / var/db and run the run command
"compat compatibility mode, valid for passwd, group, and shadow files. In this mode, you will first look in the corresponding / etc file. If you want to do a NIS lookup, you need the first value (user name or group name) to be a plus sign (+), followed by a 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 at the end of the file: +: *:
The dns is only meaningful to hosts. As configured in / etc/resolvconf, look for it in DNS
"nis" means something to all keywords. If NIS is available, look for it in the NIS server.
Naming [STATUS = action] controls the behavior of the name service. STATUS is one of SUCCESS (operation performed successfully), NOTFOUND (record not found), UNAVAIL (selected service is not available), and TRYAGAIN (service is temporarily unavailable, please try again). Action is one of return (terminates the search and returns the current state) or continue (other items that continue this line). For example, hosts: dns nis [NOTFOUND=return] files will look up the hostname first in DNS and then in NIS. Use the file / etc/hosts only if neither of the current items is available
◆ / etc/resolv.conf configuration DNS customer
The file / etc/resolv.conf configures the DNS client, 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 their meanings are as follows:
The IP nameserver indicates the IP address of the DNS server. There can be many lines of nameserver, each with an I / P address. The query is done in the same order as nameserver in this file, and the following nameserver is queried only if the first nameserver does not respond.
"domain declares the domain name of the host. It is used by many programs, such as mail systems, and when performing DNS queries for hosts that do not have a domain name. If there is no domain name, the hostname will be used, delete all at the first point (. ) the previous content.
Multiple parameters of the domains search indicate the order in which the domain name is queried. When you query a host without a domain name, the host will look in the domain declared by search. Domain and search cannot coexist; if they exist at the same time, the latter will be used.
Ordered sortlist allows you to sort the results of the resulting domain name in a specific way. Its parameters are network / mask pairs, allowing for arbitrary ordering. The default e t c r e s o l v. C o n f file is not provided in Red Hat, and its contents are dynamically created based on the options given at installation time.
◆ / etc/init.d/network host address, subnet mask and gateway
Unlike many other UNIX and linux operating systems, Red Hat currently does not automatically configure the network through the / etc/hostname and / etc/hosts files. In order to change the default IP address of the host, the / etc / init.d/network script must be edited 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 of this file:
IPADDR=192.168.1.100
NETMASK=255.255.255.0
BROADCAST=192.168.1.255
Modify hostname (HOSTNAME)
Hostname # View the hostname of the current host
Hostname NEWHOSTNAME # temporarily modify the current hostname
Modify hostname
Vi / etc/sysconfig/network # modify the hostname through the configuration file
NETWORKING=yes
HOSTNAME=NEWHOSTNAME # modify this value as the hostname, such as: NEWPC
Vi / etc/hosts
#
# #
Vi / etc/hosts / / set up the local DNS parsing file
127.0.0.1 localhost.localdomain localhost / / the line strongly recommends keeping
192.168.0.1 rhel.lpwr.net rhel / / must have three fields: IP, FQDN, HOSTNAME
# #
Turn to:
RHEL basic network configuration
# #
# / etc/sysconfig/network-scripts/eth
# #
Vi / etc/sysconfig/network-scripts/eth0 / / Edit the specified network interface profile
DEVICE=eth0 / / specify the interface name
ONBOOT=yes / / load when the system starts
BOOTPROTO=static / / IP address is statically configured. If the value is "dhcp", it can be obtained dynamically.
IPADDR=192.168.0.1 / / set IP address
NETMASK=255.255.255.0 / / set subnet mask
GATEWAY=192.168.0.254 / / set the default gateway
# #
#
# / etc/sysconfig/network
#
# #
Vi / etc/sysconfig/network / / modify the host name through the configuration file
NETWORKING=yes
HOSTNAME=localhost.localdomain / / modify this value as the hostname, such as: rhel.lpwr.net
# #
#
# / etc/hosts
#
# #
Vi / etc/hosts / / set up the local DNS parsing file
127.0.0.1 localhost.localdomain localhost / / the line strongly recommends keeping
192.168.0.1 rhel.lpwr.net rhel / / must have three fields: IP, FQDN, HOSTNAME
# #
#
# / etc/resolv.conf
#
# #
Vi / etc/resolv.conf / / specifies the DNS server of the current host, and a maximum of three can be specified
Search lpwr.net / / sets the default lookup domain for the current host
Nameserver 192.168.0.100 / / specify the preferred DNS server
Nameserver 172.16.254.2
# #
#
# / sbin/ifconfig
#
# #
/ sbin/ifconfig / / display the ifconfig command to view the information of the network interface
Ifconfig eth0 / / displays information about the specified interface
Ifconfig-a / / displays information for all interfaces (whether active or not)
Ifconfig eth0 192.168.0.2 netmask 255.255.255.0 / / temporarily modify the interface IP address (no need to restart the interface)
# #
#
# / sbin/route
#
# #
/ sbin/route / / displays the routing table information in the current Linux host
Route del default gw 192.168.0.1 / / temporarily delete the default gateway 192.168.0.1
Route add-net 192.168.1.0 route add 24 gw 192.168.0.254 / / temporarily add a static route
# #
#
# ping
#
# #
Ping / / Test the network connection to other hosts
Ping-c 4 192.168.0.1 / / specify the number of ICMP packets sent
# #
#
# traceroute
#
# #
Traceroute / / Test the current host-to-destination network connection
# #
#
# hostname
#
# #
Hostname / / View the hostname of the current host
Hostname linsrv / / temporarily modify the current hostname
# #
#
# nslookup
#
# #
Nslookup / / Test DNS domain name resolution
> server / / Show the current DNS server
> server 192.168.0.1 / / temporarily specify the DNS server address
# #
#
# dhclient
#
# #
Dhclient / / apply for network configuration information for the current host
# #
#
# netconfig
#
# #
Netconfig / / modify the network configuration information under the character interface through the wizard
# #
#
# / etc/init.d/network
#
# #
/ etc/init.d/network restart / / restart the network service
/ etc/init.d/network stop / / stop the network service
/ etc/init.d/network start / / start the network service
/ * * whether you modify the network configuration information through netconfig or by modifying the configuration file, you need to restart the network service to take effect * * /
# #
#
# service
#
# #
Service network start / / start the network service
Service network stop / / stop the network service
Service network restart / / restart the network service
Service network status / / View the status of network services
/ * * in RHEL4, you can use the service command to manage the start, stop, restart and check the working status of most services * * /
# #
#
# chkconfig
#
# #
Chkconfig-- list | grep network / / View the automatic startup level of a service
Chkconfig-- level 35 network off / / setting does not automatically start a service at level 35
Chkconfig-- level 3 network on / / sets a service to start automatically at level 3
# #
#
# ntsysv
#
# #
Ntsysv / / modify the self-startup options of the service under the character interface through the wizard
Nameserver 202.106.0.20
This is the end of the article on "sample analysis of Redhat network-related configuration files". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.