Enable ssh host to guest and guest internet on CentOS 7 guest using VirtualBox
Reg Mem
I have 2 CentOS 7 guests running in VirtualBox on an Ubuntu host.
I would like to be able to:
- Connect from host to guest using SSH
- Download/install packages from the Internet on the guest.
I currently have the following two virtual network interfaces
- host only, mapped to "enp0s3" on the guest
- NAT, mapped to "enp0s8" on the guest
My current configuration:
$ cat /etc/sysconfig/network-scripts/ifcfg-enp0s3
TYPE=Ethernet
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
NAME=enp0s3
UUID=fcd0aa44-9ab7-42e6-a637-52c429727195
ONBOOT=yes
HWADDR=08:00:27:BE:DB:11
IPADDR=192.168.56.102
PREFIX=32
GATEWAY=192.168.56.1
and
$ cat /etc/sysconfig/network-scripts/ifcfg-enp0s8
HWADDR=08:00:27:A2:03:29
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=enp0s8
UUID=09acefe7-d513-48f6-b820-0988ac495e5e
ONBOOT=yes
Current route information:
$ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 192.168.56.1 0.0.0.0 UG 1024 0 0 enp0s3
10.0.3.0 0.0.0.0 255.255.255.0 U 0 0 0 enp0s8
192.168.56.1 0.0.0.0 255.255.255.255 UH 1024 0 0 enp0s3
At this point, I can SSH from the Ubuntu host to the CentOS guest, but I cannot successfully connect to the Internet:
$ wget https://github.com/antirez/redis/archive/3.0.0-rc6.tar.gz
Resolving github.com (github.com)... 192.30.252.130
Connecting to github.com (github.com)|192.30.252.130|:443...
Many other posts and examples suggested me to remove the default gateway from "enp0s3". If I remove the default gateway from "enp0s3", I cannot SSH to the CentOS guest from the Ubuntu host.
How can I make this work?
Reg Mem
So I finally got it working
I am missing a netmask value in the config
Host-only NIC enp0s3
TYPE=Ethernet
BOOTPROTO=static
NAME=enp0s3
UUID=71d4200e-199d-4d03-935d-6d2e88c41956
DEVICE=enp0s3
ONBOOT=yes
IPADDR=192.168.56.101
NETMASK=255.255.255.0
NAT invalid enp0s8
HWADDR=08:00:27:49:5A:6C
TYPE=Ethernet
BOOTPROTO=dhcp
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=enp0s8
UUID=56cc4f81-d7a4-465a-badb-0b6120a0d62e
ONBOOT=yes
With the above values it works the way I need it
- ssh from host to guest
- guest online
- Database access from host to guest