Host-only adapter not set up correctly in Centos 7 Virtual Box VM
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_
Vagrant.
# General Vagrant VM configuration
config.vm.box = "geerlingguy/
config.
config.
config.
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,
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,
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:
valid_lft forever preferred_lft forever
3: enp0s8: <BROADCAST,
link/ether 08:00:27:34:6d:75 brd ff:ff:ff:ff:ff:ff
Editing the /etc/sysconfig/
#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=
NETMASK=
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
Why did searches not find the upstream bug for me. It would have saved a lot of time: /github. com/hashicorp/ vagrant/ issues/ 8250
https:/
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.