Host-only adapter not set up correctly in Centos 7 Virtual Box VM

Bug #1744479 reported by Ross Gammon
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
vagrant (Ubuntu)
Fix Committed
Undecided
Unassigned

Bug Description

Following the "Ansible for DevOps" book (Chapter 3) to set up 3 machines on a host-only adaptor, the guests were not reachable from the host, and they were not reachable from each other.

Ubuntu Desktop 17.10 Artful
Vagrant 1.9.1

The command in the book that failed (in case someone searches on that):
$ ansible multi -a "hostname"
192.168.60.5 | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: ssh: connect to host 192.168.60.5 port 22: No route to host\r\n",
    "unreachable": true
}
192.168.60.4 | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: ssh: connect to host 192.168.60.4 port 22: Connection timed out\r\n",
    "unreachable": true
}
192.168.60.6 | UNREACHABLE! => {
    "changed": false,
    "msg": "Failed to connect to the host via ssh: ssh: connect to host 192.168.60.6 port 22: Connection timed out\r\n",
    "unreachable": true
}

$ ping 192.168.60.4 etc. also failed to reach the guest from the host.
$ vagrant ssh app1 etc. also found that the other guests could be pinged from inside a guest.

For reference the Vagrantfile is:
# -*- mode: ruby -*-
# vi: set ft=ruby :

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  # General Vagrant VM configuration
  config.vm.box = "geerlingguy/centos7"
  config.ssh.insert_key = false
  config.vm.synced_folder ".", "/vagrant", disabled: true
  config.vm.provider :virtualbox do |v|
    v.memory = 256
    v.linked_clone = true
  end

  # Application server 1.
  config.vm.define "app1" do |app|
    app.vm.hostname = "orc-app1.dev"
    app.vm.network "private_network", ip: "192.168.60.4"
  end

  # Application server 2.
  config.vm.define "app2" do |app|
    app.vm.hostname = "orc-app2.dev"
    app.vm.network :private_network, ip: "192.168.60.5"
  end

  # Database server.
  config.vm.define "db" do |db|
    db.vm.hostname = "orc-db.dev"
    db.vm.network :private_network, ip: "192.168.60.6"
  end
end

I tried clearing out all my firewall settings with iptables (on the host), but this did not help. A reboot put them all back to the way they were. I tried manually deleting all the virtual box host only adapters (e.g. vboxnet0) and letting vagrant recreate them, but this did not work. I deleted the virtual box host only adapter again, and recreated it manually myself. But this did not fix it either.

By "vagrant ssh app1" and using "ip add", I could see that the NAT adapter was set up OK, but not the host-only adaptor:
[vagrant@orc-app1 ~]$ ip add
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:8a:70:6a brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic enp0s3
       valid_lft 86210sec preferred_lft 86210sec
    inet6 fe80::a00:27ff:fe8a:706a/64 scope link
       valid_lft forever preferred_lft forever
3: enp0s8: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
    link/ether 08:00:27:34:6d:75 brd ff:ff:ff:ff:ff:ff

Editing the /etc/sysconfig/network-scripts/ifcfg-enp0s8 file in the CentOS guest, I found that the BOOTPROTO parameter was set to "none" (I think), and there was no gateway parameter set. I am not sure which one is critical (or both), but changing the BOOTPROTO parameter to "static" and adding a GATEWAY parameter set to 192.168.60.1 fixed it for me (after restarting the network service with $ sudo systemctl restart network.service). See the example file for app1 below:

#VAGRANT-BEGIN
# The contents below are automatically generated by Vagrant. Do not modify.
NM_CONTROLLED=no
BOOTPROTO=static
ONBOOT=yes
IPADDR=192.168.60.4
GATEWAY=192.168.60.1
NETMASK=255.255.255.0
DEVICE=enp0s8
PEERDNS=no
#VAGRANT-END

Doing a similar manual change to all of the guest VMs, got the ansible command working:
$ ansible multi -a "hostname"
192.168.60.5 | SUCCESS | rc=0 >>
orc-app2.dev

192.168.60.4 | SUCCESS | rc=0 >>
orc-app1.dev

192.168.60.6 | SUCCESS | rc=0 >>
orc-db.dev

Revision history for this message
Ross Gammon (rosco2) wrote :

Why did searches not find the upstream bug for me. It would have saved a lot of time:
https://github.com/hashicorp/vagrant/issues/8250

Apparently, the work-around is just to restart the network service inside each guest (no need to edit the file as I did):
$ sudo systemctl restart network

The issue was fixed upstream in vagrant 1.9.2.

Changed in vagrant (Ubuntu):
status: New → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.