2

I have 2 CentOS 7 guests running in VirtualBox on a Ubuntu host.

I want to be able to:

  1. Connect using ssh from host to guest
  2. Download/install packages from the Internet on the guest.

I currently have following two virtual network interfaces

  • Host Only, mapped as 'enp0s3' on guest
  • NAT, mapped as 'enp0s8' on 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 info:

$ 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 my Ubuntu host to my 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...

Lot of other posts and samples suggested that I remove the default gateway from 'enp0s3'. If I remove the default gateway from 'enp0s3', I cannot ssh from the Ubuntu host to the CentOS guest.

How can I make this work?

  • Not an answer but you could probably save yourself time and just use vagrant images if it fits your needs. – jordanm Mar 26 '15 at 20:49
3

So I finally got it to work

I was missing netmask value in the configuration

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 NIC 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 above values it works the way I need it

  • ssh from host to guest
  • Internet access from guest
  • DB access from host to guest
  • This solution worked for me as well. I suggest you expand your answer slightly to say that you added the Netmask to the Host Only adapter config just to be more explicit and add a comment in the example. I also experimented with making the NAT network the default gateway but that killed my SSH too. I think a IP routing table entry may be used as well but this seems like a very clean solution. Thanks for sharing. – Mark Edington May 5 '16 at 0:01
  • Are you able to ssh from host to guest machine? – Yogesh Darji Mar 12 '17 at 19:35
0

Simply configure a network adapter to 'bridged' mode, bridging it to your physical ethernet adapter enp0s3 (assuming that is the one connected to the Internet).

Bridged mode will allow guest-host connectivity and guest-internet connectivity.

  • That does not let me run local code to connect to db running in VM. I rather need to have a static IP bound to it – Reg Mem Mar 26 '15 at 21:35
  • @RegMem - You can assign a static IP to the VMs. – garethTheRed Mar 26 '15 at 21:38
  • Will that network IP have to change if I change my network? I work from home and take the same laptop to workplace too. – Reg Mem Mar 26 '15 at 21:43
  • @RegMem - Yes, you'll have to be careful if you're connecting to different networks I'm afraid, unless you're lucky enough that both use the same network address AND that the static IP addresses you choose for your VMs are free on both networks. – garethTheRed Mar 26 '15 at 21:48
  • No That does not work – Reg Mem Mar 26 '15 at 21:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.