How To Resolve Ubuntu Virtualbox Network Is Unreachable Error

My host machine OS is Windows 10, and I install oracle VirtualBox on it. The guest OS in the VirtualBox 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 does not work correctly.

I can not access the network, the error message is ubuntu connection failed, activation of network connection failed, I can not ping the domain name, when I  ping a domain name (for example www.google.com), it will return the error message Name or service not known. And I can not ping the IP address of the domain even, the error message is network is unreachable. I struggled with all these errors for almost several hours, and I resolve this problem by following the below steps finally.

1. Enable Network Connection To Fix Activation Of Network Connection Failed.

  1. If you encounter a 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.
  2. Open a terminal and run the 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
  3. If you can not find the inet address in the console output, this means the network is not enabled correctly. You need to follow the below steps to enable the network first.
  4. Click Show Applications —> Settings icon to open the Ubuntu configuration panel.
  5. Click the Network menu item in the left panel. Then toggle the Wired button to ON in the right panel.
  6. Now run $ifconfig command in terminal again, you should find the IP address that the DHCP server assigned to you.

2. Fix Name Or Service Not Known Issue.

  1. After configurations in step 1, you should get your virtual machine IP address, and you can also ping other IP addresses in your local network or internet website.
  2. But you may find you can not ping the domain name. When you ping a domain name you get an error message Name or service not known like below.
    ~$ ping www.google.com
    ping: www.google.com:
    Name or service not known
  3. When you turn on / off the wired network in step 1. Below DNS record will be written to /etc/resolve.conf, and the DNS record is invalid.
    # Generated by NetworkManager
    nameserver 127.0.0.53
  4. This leads to the error Name or service not know when you ping the website domain in the terminal. And this DNS record is generated by the NetworkManager automatically.
  5. To resolve this problem, just run $ sudo gedit /etc/resolve.conf to change the nameserver IP to a valid one such as 8.8.8.8 ( google provide ). Then save the resolve.conf file.
  6. Now you can ping the website domain successfully.

3. Fix Invalid DNS Record nameserver 127.0.0.53 Permanently.

  1. After step 1 and step 2, you can ping the website domain name now.
  2. To avoid this error happening again, you can remove the invalid DNS record 127.0.0.53  and add a valid DNS record permanently in /etc/resolve.conf when you reboot the OS again.
  3. Run the below command to install Ubuntu resolvconf package.
    $ sudo apt install resolvconf
  4. Modify file /etc/resolvconf/resolv.conf.d/tail and add a valid DNS record ( such as nameserver 8.8.8.8 ) in it. If the tail file does not exist then create it.
    $ sudo gedit /etc/resolvconf/resolv.conf.d/tail
  5. Now when you boot the Ubuntu OS, the DNS record ( nameserver 8.8.8.8) 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.

4. How To Fix VirtualBox Virtual Machine connect: Network is unreachable” Error.

4.1 Question.

  1. I use the Oracle VirtualBox to create a virtual machine.
  2. My host os is Windows7, and the guest os is Ubuntu 18.
  3. I open the VM settings dialog, click the Network tab and select NAT in the Enable Network Adapter Attached to the drop-down list.
  4. But when I ping an IP address that exists on the internet, it shows the error message connect: Network is unreachable.
  5. Below is the output when I run the command ifconfig on the guest Ubuntu OS.
    $ ifconfig
    enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet6 fe80::7bb4:e4e0:dc7d:16a9  prefixlen 64  scopeid 0x20<link>
            ether 08:00:27:c6:c0:0d  txqueuelen 1000  (Ethernet)
            RX packets 32987  bytes 45350863 (45.3 MB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 11336  bytes 856368 (856.3 KB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
            inet 127.0.0.1  netmask 255.0.0.0
            inet6 ::1  prefixlen 128  scopeid 0x10<host>
            loop  txqueuelen 1000  (Local Loopback)
            RX packets 196  bytes 17046 (17.0 KB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 196  bytes 17046 (17.0 KB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

4.2 Answer1.

  1. You can get the reason from the output text of the ifconfig command.
  2. We can see that there is not the inet info in the ifconfig output, which means the enp0s3 interface does not have an IP address.
  3. So you can run the command sudo ifconfig enp0s3 <an_ip_address> to assign a static IP address to the interface enp0s3.
  4. If you want the enp0s3 interface to get a dynamic IP address from a DHCP server, you can run the command sudo dhclient enp0s3.
0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments
Clicky
0
Would love your thoughts, please comment.x
()
x