1 Problem Description
CentOS VMS cannot display local IP addresses, as shown in the following figure:
2 Tried methods
Change ONBOOT to YES as shown here:
However, the original nic configuration is also YES, so the modification method is useless. I tried to restart the NIC service:
systemctl restart network
Copy the code
The IP still doesn’t work.
3 reasons
There are two common Linux network management services:
network
serviceNetworkManager
service
NetworkManager is a basic service that is usually used on servers and also on the GUI. NetworkManager is usually installed on the GUI to facilitate IP configuration. Note that only one of the two services takes effect. In this case, there should be a conflict between the two, resulting in the normal display of local IP, can be used
systemctl status network
systemctl status NetworkManager
Copy the code
Check the status of the two services. If the two services are not in conflict, it should be the cause of the configuration error.
4 Solutions
4.1 the use ofnetwork
Disable NetworkManager:
systemctl stop NetworkManager
systemctl status NetworkManager
Copy the code
Restart network after disabling:
systemctl restart network
Copy the code
This will show the local IP.
/etc/sysconfig/network-scripts /etc/sysconfig/network-scripts /etc/sysconfig/network-scripts/ifcfg-ens33
4.2 the use ofNetworkManager
To use NetworkManager, disable NetworkManager:
systemctl stop network
systemctl status network
Copy the code
Start NetworkManager again:
systemctl start NetworkManager
Copy the code
Next, use nmCLI.
4.2.1 Hosting status
First look at the managed status:
nmcli n
Copy the code
If disabled is displayed:
Open:
nmcli n on
Copy the code
4.2.2 equipment
View device:
nmcli d
Copy the code
The author’s machine shows as follows:
Next, you can create a connection in two ways: dynamic/static IP:
Create a connection using a static IP address
nmcli c add typeEthernet con-name connect_name_1 ifname ens33 ipv4.addr 192.168.126.151/24 ipv4.gateway 192.168.126.1 ipv4.method manualCreate a connection using a dynamic IP address
nmcli c add type ethernet con-name connect_name_2 ifname ens33 ipv4.method auto
Copy the code
Holdings of staticip
way
nmcli c add typeEthernet con-name connect_name_1 ifname ens33 ipv4.addr 192.168.126.151/24 ipv4.gateway 192.168.126.1 ipv4.method manualCopy the code
Parameter Description:
nmcli c add
: Create a connectiontype
: Connection typecon-name
: Connection nameifname
: the network card nameipv4.addr
:ipv4
staticip
And here is the192.168.126.151
.24
Indicates the subnet maskipv4.gateway
: gateway, put the lastip
The last place1
All right, so here it is192.168.126.1
ipv4.method
: The following parametersmanual
Static configurationip
, it is important to note that this parameter is the defaultauto
, that is, if this parameter is not specified, two will appearip
One static + one dynamic
After the connection is created, the IP should be displayed:
If the IP still cannot be displayed, you can manually connect to the device:
nmcli d connect ens33
Copy the code
4.2.4 dynamicip
way
nmcli c add type ethernet con-name connect_name_2 ifname ens33 ipv4.method auto
Copy the code
The parameter is the same as the preceding parameter. The difference is auto, which indicates that the IP address is configured dynamically. In this way, the configuration is complete.
If there is still no IP, try manually connecting to the device:
nmcli d connect ens33
Copy the code