CentOS 7 network environment configuration

CentOS 7 network environment configuration

The configuration of the network environment is the first step for the system to connect to the network, including the configuration of the IP address, subnet mask, gateway, host name, and DNS domain name resolution server. This chapter will introduce the introductory knowledge of network environment configuration, mainly including the following knowledge points. :

Host name configuration;

The configuration of the information of the network card (emphasis, difficulty);

The configuration of the client domain name resolution server (difficulty);

The configuration of the client domain name resolution server (difficulty);

Network troubleshooting method (difficulty);

6.1 Project 1: Network environment configuration

【project description】

In order to better manage and maintain the network, the administrator needs to configure the network environment of the server, and then deploy the server to the network environment. For this he needs to complete the following tasks:

  1. Set the temporary host name Server.
  2. Set the network card information: the IP address is 192.168.137.5, the subnet mask is 255.255.255.0; the client domain name resolution server address is set to 219.216.129.5.
  3. For each step of the setting, the administrator must check accordingly to verify that the setting is successful.

【Project Analysis】

In this project, the root administrator first sets the host name, then configures the information of the network card, including the IP address, subnet mask, and gateway, and finally needs to set the client domain name resolver DNS address. At the same time, verify all settings through related commands or other reliable methods. Related knowledge points are shown in the following table:

Serial number

Knowledge points

1

Host name configuration

2

Network card information configuration

3

Client domain name resolution server configuration

【Operation process】

#hostname Server //Set the temporary hostname Server

#hostname //You can verify that the result is correct

#ifconfig ens33 192.168.137.5 netmask 255.255.255.0 //Configure network card information

#ifconfig //Check whether the network configuration takes effect

#vim /etc/resolv.conf //Edit the content of the file and add the following

nameserver 219.216.129.5

 

 

 

 

6.1.1 Host name configuration

The host name is the unique identification of the host in the network. There are two common methods for setting the host name: one method is to use the hostname command to temporarily set the host name, and the other is to use the hostnamectl command to permanently set the host name.

  1. Use the hostname command to temporarily set the host name

Command format:

hostname [new hostname]

The setting of the hotsname command is temporary and will be restored to the original host name when the system restarts. This is because the setting content of the hostname command has not been updated to the hostname option in the network configuration file /etc/hostname.

  1. Use the hostnamectl command to permanently set the host name

Command format:

hostnamectl set-hostname new hostname

CenOS Linux7 uses the /etc/hosts configuration file to store host name information. However, using the hostname command to set the host name does not modify the content of the /etc/hosts file. The content of the file will be read when the system restarts to configure the host name.

#hostnamectl set-hostname student

#hostname

#cat /etc/hostname

 

6.1.2 Configuration of network card information

  1. Network card configuration file

For the configuration of network card information, it usually includes the configuration of IP address, subnet mask, and gateway. The network card information is stored in the network card configuration file. The network card configuration file is located in the /etc/sysconfig/network-scripts directory. A network card corresponds to a network card configuration file.

CentOS Linux7 provides different naming rules, which are assigned based on firmware, topology, and location information by default. The advantage of this is that the naming is fully automatic and predictable, but the disadvantage is that it is difficult to understand.

Take the network card device name ens33 as an example, the meaning of the first 2 characters:

en: Ethernet

wl: wireless local area network WLAN

ww: Wireless Wide Area Network WWAN

#cd /etc/sysconfig/network-scripts

#pwd

#ls -a

#cat ifcfg-ens33

 

 

ifcfg-ens33 is a network card configuration file.

The meanings of common configuration items in the network card configuration file are as follows:

The meanings of common configuration items are as follows:

DEVICE=ens33 //Define the name of the network card.

BOOTPROTO=dhcp //Indicates how to configure the host network parameters

dhcp means to obtain the IP address dynamically through BOOTP or DHCP protocol, static means to specify manually

ONBOOT=yes //Indicates whether to start the network card when the system starts. Yes means to start, no means not to start

TYPE=Ethernet //Type of network card.

  1. Configure network card information

(1) Modify the network card configuration file directly

 

After the configuration file is modified, you need to execute the #systemctl restart NetworkManager command to make the file modification take effect.

(2) ifconfig command

The ifconfig command is more powerful and can be used to view and set network card information.

①View network card information

Command format:

ifconfig [options]

#ifconfig ens33

 

(3) Use the ifconfig command to set the IP address of the current network card ens33 to 192.168.168.156, and the subnet mask to 255.255.255.0.

#ifconfig ens33 192.168.168.156 netmask 255.255.255.0

#ifconfig ens33

(4) Modify the MAC address

Command format:

ifconfig network card device name hw ether MAC address

Note: Disable the network card before modifying the MAC address of the network card, and then enable the network card after the modification is completed.

Disable network card

#ifdown ens33

Modify the MAC address of the ens33 network card to 00:0C:29:03:F3:76

#ifconfig ens33 hw ether 00:0C:29:03:F3:76

#ifconfig ens33

Restart the network card: ifup

#ifup ens33

(5) Bind IP and MAC addresses

Implementation method: create the /etc/ethers file, the content of the file "IP address mac address", and then execute the arp -f command to make the configuration effective.

Bind the 193.168.168.154 and 00:0C:29:03:F3:75 network cards.

#echo “193.168.168.154 00:0C:29:03:F3:75”>>/etc/ethers

#arp -f

6.1.3 Configuration of client domain name resolution server

In the Linux system, the configuration file of the client domain name resolution server is /etc/resolv.conf. If you want to configure the client domain name resolution server, you can use the vim editor to directly edit the file content.

File content format:

Nameserver specifies the IP address of the DNS server

You can specify the IP addresses of up to 3 DNS servers at the same time, search and resolve them sequentially according to the configuration order of the nameserver. In addition, you can use domain to specify the domain name of the domain where the current host is located.

To prevent the contents of the /etc/resolv.conf file from being modified or overwritten by the system, you need to modify the /etc/NetworkManager/NetworkManager.conf file and add the "dns=none" option in the main section.

The contents of the modified NetworkManager.conf file are as follows:

[main]

plugins=ifcfg-rh

dns=none

After completing the modification, you need to execute the command:

#systemctl restart NetworkManager.service Reload the configuration of NetworkManager, and the client domain name resolution server setting is now complete.

 

Guess you like

Origin blog.csdn.net/weixin_41987016/article/details/108672364