VirtualBox Centos7 host cannot ping Centos 7 guest

Discussions related to using VirtualBox on Linux hosts.
Post Reply
mgoblue0970
Posts: 2
Joined: 30. Jun 2020, 05:16

VirtualBox Centos7 host cannot ping Centos 7 guest

Post by mgoblue0970 »

I'm running a Centos 7 host with VirtualBox 6.1. I have a Centos 7 guest too. I want to be able to ping back and forth between the guest and the host.

In the VirtualBox Manager -> File -> Host Network Manager I have a network (it's the default) named vboxnet0 with 192.168.56.1/24 as the address.

In the guest Settings -> Network:

Adapter 1, Attached to: NAT

Adapter 2, Attached to: Host-only Adapter, Name: vboxnet0

The host ifconfig is:

Code: Select all

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 28  bytes 2064 (2.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 28  bytes 2064 (2.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

virbr0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
        inet 192.168.122.1  netmask 255.255.255.0  broadcast 192.168.122.255
        ether 52:54:00:c6:9c:7c  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlp2s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.11  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::2bc1:a2d1:4bcd:c3ff  prefixlen 64  scopeid 0x20<link>
        ether 38:ba:f8:fa:5f:64  txqueuelen 1000  (Ethernet)
        RX packets 1318482  bytes 1822389690 (1.6 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 440532  bytes 78704767 (75.0 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
The guest ifconfig is:

Code: Select all

enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.0.2.15  netmask 255.255.255.0  broadcast 10.0.2.255
        inet6 fe80::a00:27ff:fe52:a4bd  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:52:a4:bd  txqueuelen 1000  (Ethernet)
        RX packets 502  bytes 40521 (39.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 664  bytes 51094 (49.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.56.10  netmask 0.0.0.0  broadcast 255.255.255.255
        inet6 fe80::e7ac:941e:79fa:15bd  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:da:7b:e0  txqueuelen 1000  (Ethernet)
        RX packets 19  bytes 3546 (3.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 110  bytes 17546 (17.1 KiB)
        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 13896  bytes 48543578 (46.2 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 13896  bytes 48543578 (46.2 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
If I go guest TO host, this is the terminal output:

Code: Select all

$ ping -c 4 192.168.0.11
PING 192.168.0.11 (192.168.0.11) 56(84) bytes of data.
64 bytes from 192.168.0.11: icmp_seq=1 ttl=63 time=2.70 ms
64 bytes from 192.168.0.11: icmp_seq=2 ttl=63 time=0.513 ms
64 bytes from 192.168.0.11: icmp_seq=3 ttl=63 time=0.638 ms
64 bytes from 192.168.0.11: icmp_seq=4 ttl=63 time=0.466 ms

--- 192.168.0.11 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3001ms
rtt min/avg/max/mdev = 0.466/1.079/2.700/0.938 ms
Yay!

If I try to go host TO guest, I cannot connect:

Code: Select all

$ ping -c 4 192.168.56.10
PING 192.168.56.10 (192.168.56.10) 56(84) bytes of data.
From 192.168.56.1 icmp_seq=1 Destination Host Unreachable
From 192.168.56.1 icmp_seq=2 Destination Host Unreachable
From 192.168.56.1 icmp_seq=3 Destination Host Unreachable
From 192.168.56.1 icmp_seq=4 Destination Host Unreachable

--- 192.168.56.10 ping statistics ---
4 packets transmitted, 0 received, +4 errors, 100% packet loss, time 3000ms
pipe 4
[dogzilla@localhost ~]$ ping -c 4 10.0.2.15
PING 10.0.2.15 (10.0.2.15) 56(84) bytes of data.

--- 10.0.2.15 ping statistics ---
4 packets transmitted, 0 received, 100% packet loss, time 2999ms
I know there are a number of topics on this but there's no Windows in the mix... I'm using both CentOS 7 for both the host and the guest. Both firewalls are disabled for troublehsooting. Guest to host is working. How can I get host to guest working?
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: VirtualBox Centos7 host cannot ping Centos 7 guest

Post by scottgus1 »

For an overview of Virtualbox networks, see Virtualbox Networks: In Pictures.

You have NAT and Host-Only in your guest. Your guest's ifconfig shows enp0s3 at 10.0.2.15, that is the NAT adapter. enp0s8 is the only other adapter besides the loopback, so enp0s8 is the Host-Only adapter.

On the host's ifconfig, ignoring the loopback, there is a wlp2s0 at 192.168.0.11, probably the physical adapter connected to your LAN (maybe Wi-fi?) There is also virbr0, which is probably the Host-Only adapter.

Now note the host virbr0's IP address, at 192.168.122.1 netmask 255.255.255.0, and the guest's enp0s8 at 192.168.56.10 netmask 0.0.0.0. Ain't no way those adapters will talk to each other, the IP's and netmasks are in the wrong range.

I suspect a static IP setting on the guest at one time or another, or possibly a change in the host's Host-Only adapter IP range that the guest did not notice.

So Host-Only is dead with these settings. And NAT does not allow Ping through by default (or at all?) so the host cannot ping the guest. NAT acts just like a basic router, so the host appears to be part of the internet, and the guest can ping the host through NAT, if the host's firewall allows Ping.
fth0
Volunteer
Posts: 5677
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: VirtualBox Centos7 host cannot ping Centos 7 guest

Post by fth0 »

The VirtualBox host-only adapter is usually named vboxnet0 on a Linux host, and it is only started when the first VM needing it is run. So it probably wasn't running when executing ifconfig.

The virbr0 interface is created by a different virtualization solution, on CentOS probably gnome-boxes with libvirt.
Last edited by fth0 on 4. Jul 2020, 15:16, edited 1 time in total.
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: VirtualBox Centos7 host cannot ping Centos 7 guest

Post by scottgus1 »

Thanks, fth0, for the info! So, the host adapter for Host-Only on a Linux host does not appear in 'ifconfig' if no guests are using it.... Ok, it looks like a rephrase is in order.

mgoblue0970, please disregard my previous post. I did not identify the 'virbr0' information correctly.

Please do the whole test again. And this time please have the guest running when you do 'ifconfig' on the host PC....
fth0
Volunteer
Posts: 5677
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: VirtualBox Centos7 host cannot ping Centos 7 guest

Post by fth0 »

scottgus1 wrote:So, the host adapter for Host-Only on a Linux host does not appear in 'ifconfig' if no guests are using it.
Approximately. ;)

To be more exact: The vboxnet0 interface is not created when booting the Linux host, but when starting the first guest using it. Afterwards, it usually keeps running, with or without running guests.
mgoblue0970
Posts: 2
Joined: 30. Jun 2020, 05:16

Re: VirtualBox Centos7 host cannot ping Centos 7 guest

Post by mgoblue0970 »

scottgus1 wrote:Thanks, fth0, for the info! So, the host adapter for Host-Only on a Linux host does not appear in 'ifconfig' if no guests are using it.... Ok, it looks like a rephrase is in order.

mgoblue0970, please disregard my previous post. I did not identify the 'virbr0' information correctly.

Please do the whole test again. And this time please have the guest running when you do 'ifconfig' on the host PC....
Thanks all for the replies.

Looks like there was a problem with the script file. When I use what are the defaults from the network manager, it doesn't work. When I manually clobber ifcfg-enp0s8 to just the following, it works:

DEVICE=enp0s8
BOOTPROTO=none
NM_CONTROLLED=no
ONBOOT=yes
IPADDR=<insert address here>
NETMASK=255.255.255.0
Post Reply