Multiple static addresses on same interface via Vagrant - vagrant

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

Related

Configure Multiple Bridge IPs in Vagrant

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|

How can I find the host machine network ip address on travis?

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

3 IP address from RPI3 eth + wlan +?

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.

broadcast address not found using cat /etc/hosts in console

i have been trying to install edX ,one of its command line instruction is
cat /etc/hosts
i am getting the response as
cat /etc/hosts
127.0.0.1 localhost
127.0.1.1 precise64
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
broadcast ip is missing ,why is it so?
You don't typically list a broadcast address in /etc/hosts file. Why would you expect to see it there?
What is 'edX' anyway? Got a url for its README file?
Come to think of it, if you really need the broadcast mask for your host, you're
better off using a variant of ifconfig. Here are some examples:
(Solaris 11.x)
enter code here
$ ipadm show-addrprop -p broadcast e1000g0/v4
ADDROBJ PROPERTY PERM CURRENT PERSISTENT DEFAULT POSSIBLE
e1000g0/v4 broadcast r- 192.168.1.255 -- 192.168.1.255 --
limoncello:jmcp $ ifconfig e1000g0
e1000g0: flags=100001100943<UP,BROADCAST,RUNNING,PROMISC,MULTICAST,ROUTER,IPv4,PHYSRUNNING> mtu 1500 index 2
inet 192.168.1.20 netmask ffffff00 broadcast 192.168.1.255
Alternatively, on linux (Debian Jessie):
jmcp#debiant:~$ /sbin/ifconfig eth0
eth0 Link encap:Ethernet HWaddr 08:00:27:cd:61:7c
inet addr:192.168.1.249 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fecd:617c/64 Scope:Link
inet6 addr: 2001:44b8:2188:f000:a00:27ff:fecd:617c/64 Scope:Global
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:258 errors:0 dropped:0 overruns:0 frame:0
TX packets:208 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:44119 (43.0 KiB) TX bytes:29635 (28.9 KiB)
On the Solaris host, the broadcast addr for the interface I'm interested in is 192.168.1.255; on the Debian vm, it's the same.

Kitchen can't see the network configuration into Vagrantfile

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.

Resources