Go to Linux02-Network Configuration
Linux has many methods to configure the network, such as the GUI, nmtui in CentOS 7, or direct command line. However, in the final analysis, the configuration file is being modified.
Before modifying the configuration file, you should first understand the structure. In Linux, each physical network card is called a device. Each device can have multiple logical interfaces. The modified configuration file is the interface file, centOS 7 is called connection ).
Take CentOS 7 as an example. You can use the nmcli command to view the device and connection.
View DevicesNmcli dev show
View connectionsNmcli con show
You can see that my network adapter is called enp5s0, and the connection name is also called enp5s0. You can create multiple connections. One device can correspond to multiple connections. After creating multiple connections, you can switch between them.
Add a connection (for example, add a connection called eth-my)Nmcli con add type ethernet con-name eth-my ifname enp5s0
Delete A connection (for example, deleting a connection called eth-my)Nmcli con delete id eth-my
View device status
Nmcli dev status
My enp5s0 connection is working
After learning about the structure, let's take a look at how to configure the network and modify the ip address. Each connection has a configuration file corresponding to it. Let's modify this configuration file. File Location:/Etc/sysconfig/network-scripts/ifcfg-connection nameGenerally Linux is/etc/sysconfig/network-scripts/ifcfg-eth0 this way, but CentOS7 has changed, for example, my name is enp5s0, you can also view through the ls command
Directly modify this file. The parameter values are case-insensitive and do not distinguish between single quotation marks and double quotation marks. You can even ignore the quotation marks in key = value format.
Configuration parameters:
TYPE: TYPE of the configuration file interface. There are multiple network configuration files in the/etc/sysconfig/network-scripts/directory, including Ethernet and IPsec, and the network interface type is Ethernet.
DEVICE: DEVICE Name
BOOTPROTO: system startup address protocol, none: Do not use the startup address protocol, bootp: BOOTP protocol, dhcp: DHCP Dynamic Address protocol, static: static address protocol
ONBOOT: whether the network interface is activated when the system starts. yes: the network interface is activated when the system starts. no: the network interface is not activated when the system starts.
IPADDR: IP Address
NETMASK: Subnet Mask
GATEWAY: GATEWAY address
BROADCAST: BROADCAST address
HWADDR/MACADDR: MAC address. You only need to set one of them.
PEERDNS: Specifies whether to use DNS. If DHCP is used, the default value is yes. yes: If DNS is set, modify DNS in/etc/resolv. conf. no: do not modify DNS in/etc/resolv. conf.
DNS {1, 2}: DNS address. When PEERDNS is set to yes, it is written to/etc/resolv. conf.
NM_CONTROLLED: whether the Network interface is controlled by Network Manager. The changes take effect immediately after they are saved. You do not need to restart them. It is recommended that it be set to no. Yes: Controlled by Network Manager
USERCTL: user permission control. yes: Non-root users are allowed to control this network interface. no: Non-root users are not allowed to control this network interface.
IPV6INIT: whether to execute IPv6. yes: IPv6 is supported. no: IPv6 is not supported.
IPV6ADDR: IPv6 address/prefix length
CentOS 7 and traditional parameters have changed. For example, the subnet mask of a static IP address is represented by a PREFIX. PREFIX0 = 24 --> 24-bit prefix (equivalent to 24 in total for the subnet mask, that is, the subnet mask is 255.255.255.0) The IP address, subnet mask, and gateway address of CentOS 7 must be followed by a value of 0.
After the configuration file is modified, the two methods take effect:
1. Run the service network restart command to restart the network service (recommended)
2. restart the computer
You can use ifconfig to view