Table of contents
foreword
I haven’t used the computer virtual machine for a long time. Today I opened ubuntu and found that there is no network icon in the upper right corner. I opened the terminal to ping different Baidus, and then entered ifconfig and found that the network card information was not displayed. So I started to try various methods, various network services down and up, and finally solved it under the article of Felix, come to record!
My virtual machine is in NAT mode
Entering ifconfig does not display the network card, as shown in the figure below (borrowing the picture of Mr. Felix)
Method 1 (temporary)
ifconfig ens33
sudo dhclient ens33
ifconfig
or
sudo /sbin/dhclient
sudo ifconfig
It should be noted that the above two methods are only temporary and not permanent, and the phenomenon that ifconfig has no network card will still appear next time you restart
dhclient (DHCP client) is a Dynamic Host Configuration Protocol client.
The DHCP client dhclient provides a way to configure one or more network interfaces using the Dynamic Host Configuration Protocol and the BOOTP protocol. If these protocols fail, configure by statically assigning addresses. Detailed reference https://blog.csdn.net/K346K346/article/details/127639954
Method Two
first step
nmcli con show
If there is no information output, switch to the administrator mode, that is, sudo nmcli con up 'ifname' ens33
If the following picture (borrowed from teacher Felix's picture) error occurs, go to the second step for hosting
second step
Check the hosting status: nmcli n
If it shows disabled, enable it with the following command
Enable hosting: nmcli n on
nmcli is a command-line tool of NetworkManager, which provides a method of using the command line to configure network connections managed by NetworkManager. Detailed reference https://blog.csdn.net/weixin_44863237/article/details/121899374
If enabled is displayed, but the IP cannot be automatically obtained every time you restart (enter ifconfig after the second step to check whether the network card information is displayed, it is no problem under normal circumstances), you can try the third step
third step
Check whether dhclient is running: ps -ef |grep dhclient
Check whether NetworkManager is running
If the status of NetworkManager is Active: inactive (dead), NetworkManager is not started
# 查看是否自启
systemctl is-enabled NetworkManager
# 如果为 disabled 则没有启动
# 允许自启,并启动
systemctl enable NetworkManager && systemctl start NetworkManager
If the status of NetworkManager is Active: active (running), check whether the network card device is managed by NetworkManager
Input: nmcli device status
If the STATE of the network card ens33 is displayed as unmanaged, then the network card device is not managed by NetworkManager, restore management (the picture above is managed)
input: nmcli device set ifname ens33 managed yes
restart NetworkManager: systemctl restart NetworkManager
Remember to check ifconfig after each step to see if the network card is displayed. If it can be displayed, try rebooting again, and you're done!