Solve “connect: Network is unreachable” issue with VirtualBox
2 min readJun 22, 2018
Hello,
Today, I had a very annoying problem with VirtualBox: network hardly ever works, but sometimes it works and I can’t know why… It’s very strange. I found a solution when it doesn’t work. If I do on the VM:
> sudo ifconfig
eth0 Link encap:Ethernet HWaddr 08:00:27:87:e5:ec
inet6 addr: fe80::a00:27ff:fe87:e5ec/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:73 errors:0 dropped:0 overruns:0 frame:0
TX packets:93 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:10049 (9.8 KiB) TX bytes:8638 (8.4 KiB)lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
I can see that strangely I don’t have an IPv4 address. So it means that I’m not able to connect to internet. We can easily verify this:
> ping [An IP of Google]
connect: Network is unreachable
So my solution is simply to restart networking service until ifconfig show an IPv4 address:
> sudo service networking restart
So we do:
> sudo ifconfig
eth0 Link encap:Ethernet HWaddr 08:00:27:87:e5:ec
inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe87:e5ec/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:237 errors:0 dropped:0 overruns:0 frame:0
TX packets:234 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:27938 (27.2 KiB) TX bytes:23963 (23.4 KiB)lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
If ifconfig show an IPv4 address like here, everythings is OK. If not, restart networking service again.
Thanks for reading!