I have the following Vagrantfile which defines many (multi-machine) VMs:
Vagrant.configure(2) do |config|
for i in 1..3 do
config.vm.define "vm#{i}" do |c|
c.vm.box = "ubuntu/xenial64"
c.vm.network "public_network", ip: "192.168.0.#{i + 100}"
c.vm.network :forwarded_port, guest: 22, host: rand(2000...4000), id: 'ssh'
end
end
end
After performing vagrant up, each VM has the same eth1 interface:
eth1 Link encap:Ethernet HWaddr 08:00:27:43:e7:4f
inet addr:192.168.0.103 Bcast:192.168.0.255 Mask:255.255.255.0
inet6 addr: 2607:b400:26:0:a00:27ff:fe43:e74f/64 Scope:Global
inet6 addr: fe80::a00:27ff:fe43:e74f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:59 errors:0 dropped:0 overruns:0 frame:0
TX packets:38 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:10065 (10.0 KB) TX bytes:3832 (3.8 KB)
I would like each VM to have a separate IP, but each one strangely adopts the IP 192.168.0.103. If I omit the ip specification to public_network, each VM's eth1 IP is different.
How can I configure multiple bridge IPs in a multi-machine Vagrantfile?
I guess its one of ruby caveat (you can read Closures and for loops in Ruby and probably other good resources on the net)
basically replace you for loop
for i in 1..3 do
with equivalent
(1..3).each do |i|
Related
Sorry for the naive question but I am new to using travis and read the docs thoroughly but I can't figure out what exactly I need to put in my .travis.yml or use as an IP address.
I have setup my server on local host in travis. For client testing I need the ip address of the local host to test my client app.
Any help is highly appreciated. Thanks :)
This works:
language: generic
addons:
apt:
packages:
- net-tools
script:
- /sbin/ifconfig
That installs the net-tools package, then calls the ifconfig command that package adds.
In the output from that command, you want to look at the information for the eth0 interface:
eth0 Link encap:Ethernet HWaddr 02:42:ac:11:00:08
inet addr:172.17.0.8 Bcast:0.0.0.0 Mask:255.255.0.0
inet6 addr: fe80::42:acff:fe11:8/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1245 errors:0 dropped:0 overruns:0 frame:0
TX packets:1083 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:17000256 (17.0 MB) TX bytes:122513 (122.5 KB)
But it’s better these days to instead use the ip command from the iproute2 package:
dist: trusty
language: generic
addons:
apt:
packages:
- iproute2
script:
- ip a
Sample output:
10: eth0#if11: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
link/ether 02:42:ac:11:00:05 brd ff:ff:ff:ff:ff:ff
inet 172.17.0.5/16 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::42:acff:fe11:5/64 scope link
valid_lft forever preferred_lft forever
I have a raspberry 3 connected by ethernet and wifi to my router.
So I understand I should have 2 IP address referring to it.
But I wrote hostname -I and get 3 different IP addresses:
192.168.1.100, 192.168.1.33 and 192.168.1.35
Where does the third IP come from?
if I disconnect the ethernet cable from the RPI and write again hostname -I I get:
192.168.1.100 and 192.168.1.33
this does not make sense with 'ifconfig' result:
eth0 Link encap:Ethernet HWaddr b8:27:eb:d6:xx:xx
inet addr:192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::ba27:ebff:fed6:xxxx/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:23152 errors:0 dropped:6 overruns:0 frame:0
TX packets:51977 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:12371346 (11.7 MiB) TX bytes:58608891 (55.8 MiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:416 errors:0 dropped:0 overruns:0 frame:0
TX packets:416 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1
RX bytes:47205 (46.0 KiB) TX bytes:47205 (46.0 KiB)
wlan0 Link encap:Ethernet HWaddr b8:27:eb:83:xx:xx
inet addr:192.168.1.33 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::8df4:f4d0:xxxx:115/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:28407 errors:0 dropped:23070 overruns:0 frame:0
TX packets:4040 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:7492811 (7.1 MiB) TX bytes:4725779 (4.5 MiB)
update:
As Bugfinger pointed out the use of ip addr show shows which device the address is assigned to:
2: eth0: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether b8:27:eb:d6:fb:5a brd ff:ff:ff:ff:ff:ff
inet 192.168.1.100/24 brd 192.168.1.255 scope global eth0
valid_lft forever preferred_lft forever
inet 192.168.1.35/24 brd 192.168.1.255 scope global secondary eth0
valid_lft forever preferred_lft forever
inet6 fe80::ba27:ebff:fed6:fb5a/64 scope link
valid_lft forever preferred_lft forever`
I have 2 different addresses to eth0:
scope global eth0 and scope global secondary eth0
Recent Raspbian versions (since Jessie) are using DHCP Client Daemon (DHCPCD) to configure network devices. So static IP addresses are to be configured in /etc/dhcpcd.conf. If you configured them to be static manually or via /etc/network/interfaces, you end up with one static and one dynamic IP address on the same device. As far as I read about it, it's not clear yet, if that's a bug in DHCPCD or an expected behaviour after mis-configuration.
Anyway, to change that, you have to do as follows.
To see if it is running, check the output of:
sudo service dhcpcd status
If it is not running, start it with:
sudo service dhcpcd start
sudo systemctl enable dhcpcd
If you did already changed /etc/network/interfaces, you need to revert those changes. The original contents of that file (in Jessie) is:
# Please note that this file is written to be used with dhcpcd
# For static IP, consult /etc/dhcpcd.conf and 'man dhcpcd.conf'
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
auto lo
iface lo inet loopback
iface eth0 inet manual
allow-hotplug wlan0
iface wlan0 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
allow-hotplug wlan1
iface wlan1 inet manual
wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
Now all interfaces should be configured through DHCP again. If you now want to set a static IP address for eth0, edit /etc/dhcpcd.conf and put in:
interface eth0
static ip_address=192.168.1.100/24
static routers=192.168.1.1 # or whatever your router is
static domain_name_servers=192.168.1.1 # same as router
After saving the file and sudo reboot, your Raspi should reboot with a static eth0 and a dynamic wlan0 and without the extra IP address hanging around.
My vagrant box stop working for unknown reason and even if a reinstall all the box trough my ansible script, it don't want to be reached by http://192.168.33.10/.
here my vagrant file :
Vagrant.configure(2) do |config|
config.vm.box = "centos67vm"
config.vm.synced_folder "../../pjt" , "/var/www/pjt", owner: "pjt", group: "pjt", mount_options: ["dmode=777,fmode=777"]
config.vm.synced_folder "../../library" , "/var/library"
config.vm.network :private_network, ip: "192.168.33.10"
config.vm.provision :shell, path: "ansible.sh"
config.vm.provider :virtualbox do |vb|
vb.name = "dev-pjt"
end
end
when i ping the ip i got :
ping 192.168.33.10
PING 192.168.33.10 (192.168.33.10): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2
Request timeout for icmp_seq 3
Request timeout for icmp_seq 4
^C
--- 192.168.33.10 ping statistics ---
6 packets transmitted, 0 packets received, 100.0% packet loss
the ifconfig in the box give me that :
ifconfig
eth0 Link encap:Ethernet HWaddr 08:00:27:1B:2F:CC
inet adr:10.0.2.15 Bcast:10.0.2.255 Masque:255.255.255.0
adr inet6: fe80::a00:27ff:fe1b:2fcc/64 Scope:Lien
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:967 errors:0 dropped:0 overruns:0 frame:0
TX packets:635 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 lg file transmission:1000
RX bytes:100532 (98.1 KiB) TX bytes:85600 (83.5 KiB)
eth1 Link encap:Ethernet HWaddr 08:00:27:2A:FE:79
inet adr:192.168.33.10 Bcast:192.168.33.255 Masque:255.255.255.0
adr inet6: fe80::a00:27ff:fe2a:fe79/64 Scope:Lien
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:27 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 lg file transmission:1000
RX bytes:0 (0.0 b) TX bytes:1974 (1.9 KiB)
lo Link encap:Boucle locale
inet adr:127.0.0.1 Masque:255.0.0.0
adr inet6: ::1/128 Scope:Hôte
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 lg file transmission:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
i'm don't know where do i need to dig in to find a solution (my mac or virtualbox ?) , hope somebody can help me.
Finally resolve the problem... but don't know how... so here the steps that i did :
sudo route -n flush
rebooted the macbook
deactivated little snitch and nod32 antivirus
vagrant up
successfully ping and go to http://192.168.33.10/
vagrant halt
reactivated little snitch and nod32 antivirus
vagrant up
successfully ping and go to http://192.168.33.10/
i don't know if it's the "sudo route -n flush" or the reboot that made the connection work again.
hope it will help somebody ;)
So in trying to convert manual installation instructions to Vagrant on setting up the VM, I'm stumped on how I make the /etc/network/interfaces file have the following:
auto eth1
iface eth1 inet static
address 192.168.56.101
netmask 255.255.255.0
auto eth1:1
iface eth1:1 inet static
address 192.168.56.102
netmask 255.255.255.0
auto eth1:2
iface eth1:2 inet static
address 192.168.56.103
netmask 255.255.255.0
These interfaces are all using a host-only adapter on the VM in VirtualBox.
I know I can just create three separate adapters and use the same host-only adapter doing something like this:
config.vm.network "private_network", ip: "192.168.56.101"
config.vm.network "private_network", ip: "192.168.56.102"
config.vm.network "private_network", ip: "192.168.56.103"
But that doesn't obviously match the above file. I'd rather not have some hacky solution of rewriting /etc/network/interfaces on boot-up/shutdown, but I can't seem to get Vagrant to work and can't find anything else on it beyond very simple tutorials.
I am not sure you can do that just using default network config.
I tried a few options using some parameters as
config.vm.network "private_network", ip: "192.168.50.101", :device => "eth1", :adapter => 1, :netmask => "255.255.255.0"
config.vm.network "private_network", ip: "192.168.50.102", :device => "eth1:1", :adapter => 1, :netmask => "255.255.255.0"
config.vm.network "private_network", ip: "192.168.50.103", :device => "eth1:2", :adapter => 1, :netmask => "255.255.255.0"
but this will either VM will not boot or each interface has its own interface.
Then looking at https://docs.vagrantup.com/v2/networking/public_network.html / DISABLE AUTO-CONFIGURATION, you can do the following
# manual ip
config.vm.network "public_network", auto_config: false
config.vm.provision "shell",
run: "always",
inline: "ifconfig eth1 192.168.50.101 netmask 255.255.255.0 up"
config.vm.provision "shell",
run: "always",
inline: "ifconfig eth1:1 192.168.50.102 netmask 255.255.255.0 up"
config.vm.provision "shell",
run: "always",
inline: "ifconfig eth1:2 192.168.50.103 netmask 255.255.255.0 up"
when running ifconfig -a on the VM you get
eth0 Link encap:Ethernet HWaddr 00:0c:29:e5:fe:e1
inet addr:172.16.42.238 Bcast:172.16.42.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fee5:fee1/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:766 errors:0 dropped:0 overruns:0 frame:0
TX packets:489 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:83256 (83.2 KB) TX bytes:69904 (69.9 KB)
eth1 Link encap:Ethernet HWaddr 00:0c:29:e5:fe:eb
inet addr:192.168.50.101 Bcast:192.168.50.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fee5:feeb/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:125 errors:0 dropped:20 overruns:0 frame:0
TX packets:17 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:10180 (10.1 KB) TX bytes:1478 (1.4 KB)
eth1:1 Link encap:Ethernet HWaddr 00:0c:29:e5:fe:eb
inet addr:192.168.50.102 Bcast:192.168.50.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
eth1:2 Link encap:Ethernet HWaddr 00:0c:29:e5:fe:eb
inet addr:192.168.50.103 Bcast:192.168.50.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
I am using kitchen to test my cookbook and I made a network configuration in the Vagrantfile but the kitchen instance not see this configuration.
This is my Vagrantfile configuration.
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.hostname = "demo-berkshelf"
config.vm.box = "ubuntu-12.04"
config.vm.network :private_network, ip: "33.33.33.10"
config.berkshelf.enabled = true
config.vm.provision :chef_solo do |chef|
chef.json = {
:mysql => {
:server_root_password => 'rootpass',
:server_debian_password => 'debpass',
:server_repl_password => 'replpass'
}
}
chef.run_list = [
"recipe[demo::default]"
]
end
end
And it is my .kitchen.yml configuration.
---
driver:
name: vagrant
provisioner:
name: chef_solo
platforms:
- name: ubuntu-12.04
driver_config:
box: "ubuntu-12.04"
suites:
- name: default
run_list:
- recipe[demo::default]
attributes:
When i login into kitchen show me a network configuration that i don't expect
roberto#rcisla-pc:~$ kitchen login default-ubuntu-1204
Welcome to Ubuntu 12.04 LTS (GNU/Linux 3.2.0-23-generic-pae i686)
* Documentation: https://help.ubuntu.com/
Welcome to your Vagrant-built virtual machine.
Last login: Wed Jan 22 14:02:59 2014 from 10.0.2.2
vagrant#default-ubuntu-1204:~$ ifconfig
eth0 Link encap:Ethernet HWaddr 08:00:27:12:96:98
inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe12:9698/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:360 errors:0 dropped:0 overruns:0 frame:0
TX packets:365 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:49328 (49.3 KB) TX bytes:42004 (42.0 KB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Where is the 33.33.33.10 that i configured in Vagrantfile?
Thanks beforehand for any help.
Test Kitchen won't use your Vagrantfile by default; it generates its own based on the .kitchen.yml. See the README for instructions how to configure networking via it. For example:
driver:
name: vagrant
network:
- ["private_network", { ip: "192.168.33.10" }]
You can use a custom Vagrantfile template too, but normally it shouldn't be needed. See the default template for an example.
And finally, don't use 33.33.33.* addresses. That is a valid network owned by somebody. Use IPs from private networks like 10.0.0.0/8 or 192.168.0.0/16 instead. 192.168.33.* seems to be quite common with Vagrant.