My host machine OS is windows 10, and i install oracle virtual box on it. The guest OS in virtual box virtual machine is Ubuntu 18.04.1. I use the Ubuntu OS normally for example code development. But one day when i start the Ubuntu virtual machine, i find the network do not work correctly.
I can not access network, the error message is ubuntu connection failed, activation of network connection failed, i can not ping domain name (for example www.google .com) the error message is Name or service not known, even i can not ping the ip address of the domain, the error message is network is unreachable. I struggled for all these error for almost several hours, finally i resolve this problem follow below steps.
1. Enable Network Connection To Fix Activation Of Network Connection Failed.
If you encounter network issue in Linux OS such as Ubuntu, the first thing you need to do is to check whether your network configuration is correct or not.
- Open a terminal and run below command.
~$ ifconfig enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.6 netmask 255.255.255.0 broadcast 192.168.1.255
- If you can not find the inet address in the console output, this means the network is not enabled correctly. You need follow below steps to enable the network first.
- Click Show Applications —> Settings icon to open Ubuntu configuration panel. Click Network menu item in left panel. Then toggle Wired button to ON in right panel. Now run
$ifconfigcommand in terminal again, you should find the ip address that DHCP server assigned to you.
2. Fix Name Or Service Not Known Issue.
After configurations in step 1, you should get your virtual machine ip address, and you can also ping other ip address in your local network or internet website, but you may find you can not ping domain name. When you ping a domain name you get error message like below.
~$ ping www.google.com ping: www.google.com: Name or service not known
When you turn on / off wired network in step 1. Below DNS record will be written to /etc/resolve.conf, and the DNS record is invalid. This lead to Name or service not know error when you ping website domain in terminal. And this DNS record is generated by the NetworkManager automatically.
# Generated by NetworkManager nameserver 127.0.0.53
To resolve this problem, just run
$ sudo gedit /etc/resolve.conf to change the nameserver ip to a valid one such as 126.96.36.199 ( google provide ). Then save resolve.conf file now you can ping domain successfully.
3. Fix Invalid DNS Record nameserver 127.0.0.53 Permanently.
After step 1 and step 2, you can ping domain name now. To avoid this error happen again, you can remove the invalid DNS record 127.0.0.53 and add valid DNS record permanently in /etc/resolve.conf when you reboot the OS again.
- Run below command to install Ubuntu resolvconf package.
$ sudo apt install resolvconf
- Modify file /etc/resolvconf/resolv.conf.d/tail and add a valid DNS record ( such as nameserver 188.8.131.52 ) in it. If the tail file do not exist then create it.
$ sudo gedit /etc/resolvconf/resolv.conf.d/tail
- Now when you boot the Ubuntu OS, the DNS record ( nameserver 184.108.40.206) in the tail file will be added at the end of file /run/resolvconf/resolv.conf, and /etc/resolv.conf will be a symbol link to this file.