Multicasting with `socat` in Vagrant & VirtualBox Env - udp

The problem: Each machine in the same network should be able to broadcast to all the members, including itself.
This is an attempt to get working multicast with socat with VMs created in Vagrant & VirtualBox Envrionment. It seems things are working differently here, so I first tried to see how multicast working on physical machines.
I've 3 physical machines with ubuntu 12.04 server installed on them and named as pc0, pc1 and pc2.
On each machine I run:
socat STDIO UDP-DATAGRAM:224.0.0.1:2200,bind=:2200
...and when I typed hi from pc0 from pc0, it has broadcasted to itself and other 2 machines and this is what I wanted (and I hope this is how multicast supposed to work):
ubuntu#pc0:~$ socat STDIO UDP-DATAGRAM:224.0.0.1:2200,bind=:2200
hi from pc0
hi from pc0
ubuntu#pc1:~$ socat STDIO UDP-DATAGRAM:224.0.0.1:2200,bind=:2200
hi from pc0
ubuntu#pc2:~$ socat STDIO UDP-DATAGRAM:224.0.0.1:2200,bind=:2200
hi from pc0
I'm using the IP 224.0.0.1 as this is used by default for multicast on every machine.
Next, I have tried to implement same stuff with 3 VMs, vb0, vb1 and vb2. Github repo is here.
Now I tried to broadcast from vb0:
vagrant#vb0:~$ socat STDIO UDP-DATAGRAM:224.0.0.1:2200,bind=:2200
hello from vb0
hello from vb0
...and it doesn't broadcast to the other members (as in case of the physical machines above) except itself.
It seems, there are additional settings should be done prior to have this working...
Vagrantfile:
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu-12.04-x64"
config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.provider "virtualbox" do |vb|
vb.cpus = "2"
vb.memory = "4096"
end
config.vm.provision "chef_apply" do |chef|
chef.recipe = File.read("recipe.rb")
end
config.vm.define "vb0" do |vb0|
vb0.vm.hostname = "vb0"
vb0.vm.network "private_network", ip: "10.20.30.100"
end
config.vm.define "vb1" do |vb1|
vb1.vm.hostname = "vb1"
vb1.vm.network "private_network", ip: "10.20.30.101"
end
config.vm.define "vb2" do |vb2|
vb2.vm.hostname = "vb2"
vb2.vm.network "private_network", ip: "10.20.30.102"
end
end

Running on each device (i.e. vb01, vb1 and vb2):
sudo ip route add 224.0.0.0/4 dev eth1
solved the issue.
On physical environment it's working without doing this.
No idea why we have to run this in Virtual Environment like this one.
vagrant#vb0:~$ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 10.0.2.2 0.0.0.0 UG 100 0 0 eth0
10.0.2.0 * 255.255.255.0 U 0 0 0 eth0
10.20.30.0 * 255.255.255.0 U 0 0 0 eth1
224.0.0.0 * 240.0.0.0 U 0 0 0 eth1
Helpful reference http://troglobit.github.io/multicast-howto.html

Related

Hitting port 80 on a local virtualbox server

I have a virtualbox server running on my local machine on port 2222.
I'm using it to test deploying my web app, so I'd love to be able to see if it was successfull on the virtual machine.
How do I hit port 80 on the virtual machine when the machine itself is running on port 2222 on my host laptop? Is there a way to specify a "double port" of sorts?
e.g.
# On my laptop host
curl localhost:2222:80
Thanks!
You can solve this by using port forwarding from your laptop to your virtual machine. In your Vagrantfile, forward 80 from your guest to your host. For example:
Vagrant.configure("2") do |config|
config.vm.define "vagrant" do |c|
c.vm.network "forwarded_port", guest:80, host:80
end
end
Then you should be able to curl localhost:80. Or you can forward it to a different port on your laptop:
Vagrant.configure("2") do |config|
config.vm.define "vagrant" do |c|
c.vm.network "forwarded_port", guest:80, host:8080
end
end
and curl localhost:8080

connecting to a remote lisp without SSH

I am trying to connect to a remote lisp, which is running on a virtual machine on my laptop. In the slime manual, I found this line
there is a way to connect without an ssh tunnel, but it has the side-effect of giving the entire world access to your lisp image, so we’re not going to talk about it
This seems a bit dated. I would imagine that running the lisp on a virtual machine will not allow any one else to access the lisp.
My question is, how do I connect to a remote lisp without SSH?
[EDIT]
I have seen the question here, but when I forward the port, slime is not able to connect to swank and gives me the following error
Lisp connection closed unexpectedly: connection broken by remote peer
You could use quicklisp and swank in the virtual machine then forward the port you open the lisp following this tutorial or the one for the environment you use for virtualization.
In your lisp on the virtual machine:
Welcome to Clozure Common Lisp Version 1.11-r16635 (DarwinX8664)!
CCL is developed and maintained by Clozure Associates. For more information
about CCL visit http://ccl.clozure.com. To enquire about Clozure's Common Lisp
consulting services e-mail info#clozure.com or visit http://www.clozure.com.
? (ql:quickload :swank)
To load "swank":
Load 1 ASDF system:
swank
; Loading "swank"
.....
(:SWANK)
? (swank:create-server)
;; Swank started at port: 4005.
4005
?
then use slime-connect to connect to your virtual machine ip and the port you choose for the swank-server.
In other case for ssh is also easy.if you want to connect to one port in one remote machine using ssh the easy way is using the -L option like this
ssh user#ip -p22 -L local_port:localhost:remote_port
then you use slime-connect and connect to localhost and the local_port
This is a setup using vagrant, only connect to ssh to the machine to startup swank, but you can automatize it.
1) Vagrantfile: with the forwarding port and the ip, and the roswell setup, you can install directly sbcl, it is not important but with roswell is easy to get lisp up and running in a minute, the important thing here is having quicklisp running.
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/trusty64"
config.vm.network "forwarded_port", guest: 4005, host: 4005
config.vm.network "private_network", ip: "192.168.33.24"
config.vm.provider "virtualbox" do |vb|
vb.name = "lisp_host"
vb.gui = false
vb.memory = "1024"
end
config.vm.provision "shell",
inline: "apt-get update
if which apt-get > /dev/null; then sudo apt-get -y install git build-essential automake libcurl4-openssl-dev;fi
git clone -b release https://github.com/roswell/roswell.git
cd roswell
sh bootstrap
./configure
make
sudo make install
sudo ros setup"
# SHELL
end
2) vagrant up amd vagrant ssh to go inside the machine
3) ros run -Q #after installing the sbcl you can use quicklisp in the REPL
4) Preparing swank
2016-06-06 12:32:55 ☆ |ruby-2.2.3#laguna| Antonios-MBP in ~/learn/lisp/stackoverflow/vagrant-env
○ → vagrant ssh
Welcome to Ubuntu 14.04.4 LTS (GNU/Linux 3.13.0-79-generic x86_64)
* Documentation: https://help.ubuntu.com/
System information as of Mon Jun 6 10:26:56 UTC 2016
System load: 0.41 Processes: 84
Usage of /: 4.7% of 39.34GB Users logged in: 0
Memory usage: 12% IP address for eth0: 10.0.2.15
Swap usage: 0% IP address for eth1: 192.168.33.24
Graph this data and manage this system at:
https://landscape.canonical.com/
Get cloud support with Ubuntu Advantage Cloud Guest:
http://www.ubuntu.com/business/services/cloud
Last login: Mon Jun 6 10:26:56 2016 from 10.0.2.2
vagrant#vagrant-ubuntu-trusty-64:~$ ros run -Q
WARNING: Setting locale failed.
Check the following variables for correct values:
LC_CTYPE=UTF-8
LANG=en_US.UTF-8
* (ql:quickload :swank)
To load "swank":
Load 1 ASDF system:
swank
; Loading "swank"
.
(:SWANK)
* (setf swank::*loopback-interface* "192.168.33.24") ;Important to listen throught the internet IP
"192.168.33.24"
* (swank:create-server)
;; Swank started at port: 4005.
4005
5) Then go to you emacs environment:
slime-connect
host 192.168.33.24
port 4005
6) maybe the version is different accept it and go on
Finally you can use it
I believe that this tricks could work for you the most important is the swank::loopback-interface

Vagrant remote box with libvirt issue

I am trying to make vagrant work with the following setup
Two machines - One controller and one host
Installed vagrant + vagrant-nodemaster plugin in controller (1.5.4 vagrant)
Installed vagrant + vagrant-node + vagrant-libvirt in host machine
After installation I started nodeserver in host machine in an unused port.
With the following configuration pushed from controller to host (using vagrant remote config upload )
config.vm.define :vm3 do |vm3|
vm3.vm.network :private_network,
:ip => "192.168.170.57",
:libvirt__network_name => "vagrantnw",
:libvirt__dhcp_enabled => false
end
config.vm.provider :libvirt do |libvirt|
libvirt.driver = "qemu"
# leave out host to connect directly with qemu:///system
#libvirt.host = "localhost"
libvirt.connect_via_ssh = false # aeso needed
libvirt.username = "root"
libvirt.storage_pool_name = "default"
end
config.ssh.username = 'vagrant'
config.ssh.password = 'vagrant'
config.ssh.insert_key = 'true'
config.ssh.private_key_path = '/home/kk/ssh_privkey'
I am expecting that with the above configuration libvirt will create a vm with ip address as 192.168.170.57 with a valid nfs which can be mapped to host. Now, following are the issues I am facing
VM is always created in 192.168.121.xx network with a dynamic ip address assigned in the same subnet. I am not able to create vm in the specific network which I want.
I would like to remotely ssh into the vm using command 'vagrant remote ssh '. Or from a different host I would like to connect to the VM created above.
I would like to ftp a file to the guest once remote ssh is working fine. I believe we can do this using ansible . But wanted to check if a quick and dirty way to do it through vagrant .
Thanks
You can change the management network by adding the following lines in the provider definition:
config.vm.provider :libvirt do |libvirt|
...
libvirt.management_network_name = "vagrant-libvirt"
libvirt.management_network_address = "10.75.250.0/25"
end

Vagrant: can not ping guest machine from the host

I have Mac OS with installed vagrant. On guest machine I have Ubuntu 12. So, what I would like to do is ping guest machine from host.
Guest machine attached to NAT (according to VirtualBox settings)
I found only one interface on guest machine (except lo):
eth0 Link encap:Ethernet HWaddr 08:00:27:88:0c:a6
inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe88:ca6/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:581 errors:0 dropped:0 overruns:0 frame:0
TX packets:410 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:61376 (61.3 KB) TX bytes:51599 (51.5 KB)
The thing is that there is not ip address in 10.0.2.* network on the host. Host machine has several vboxnet interfaces, but they all don't have any ip addresses:
vboxnet0: flags=8842<BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether 0a:00:27:00:00:00
vboxnet1: flags=8842<BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether 0a:00:27:00:00:01
vboxnet2: flags=8842<BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether 0a:00:27:00:00:02
vboxnet3: flags=8842<BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether 0a:00:27:00:00:03
Have you got any idea why ip address is not assigned to host machine by VirtualBox? What can I do to be able to ping gust machine?
Here is my vagrant file (I removed some commented lines which I do not use):
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# All Vagrant configuration is done here. The most common configuration
# options are documented and commented below. For a complete reference,
# please see the online documentation at vagrantup.com.
# Every Vagrant virtual environment requires a box to build off of.
config.vm.box = "hashicorp/precise64"
# The url from where the 'config.vm.box' box will be fetched if it
# doesn't already exist on the user's system.
# config.vm.box_url = "http://domain.com/path/to/above.box"
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network "forwarded_port", guest: 3306, host: 8086
config.vm.network "forwarded_port", guest: 27017, host: 27017
config.vm.synced_folder "/Users/KoulSlou/Documents/Cloudware12.10", "/vagrant", owner: "www-data", group: "www-data"
config.vm.synced_folder "/Users/KoulSlou/Documents/Cloudware/public","/cloudware", owner: "www-data", group: "www-data"
# Create a private network, which allows host-only access to the machine
# using a specific IP.
#config.vm.network "private_network", ip: "192.168.1.2"
# Create a public network, which generally matched to bridged network.
# Bridged networks make the machine appear as another physical device on
# your network.
# config.vm.network "public_network"
# If true, then any SSH connections made will enable agent forwarding.
# Default value: false
# config.ssh.forward_agent = true
...
end
By default (i.e. when not touching any network configurations), Vagrant configures VMs in VirtualBox to attach their first interface (eth0) to "NAT" (don't confuse it with "NAT Network" which is different option in VirtualBox).
When your VM interface is attached to NAT, the guest will get 10.0.2.15 IP. On the host side you will only see vboxnet# interface without IP. You can think about this interface as a private router for that guest.
VMs that are connected to NAT are not routable from the outside world. This is by design and that's one of the reasons why vboxnet# interface has no IP. VMs are able to access the "outside world" such as the internet and host machine but cannot be accessed from the outside world without port forwarding.
If default behaviour is not what you looking for, Vagrant provides high level abstraction of networking config:
Private network - This will create new subnet that shouldn't collide with host's subnet (or any other subnets the host might have route to). In VirtualBox this will be configured by attaching additional interface to "Host-Only".
Public network - Your VMs will get IP from the same subnet as your host. Basically this is like creating new machine on the same network as your host. In VirtualBox this will be configured by attaching additional interface to "Bridged Adapter".
More advanced networking configurations are possible by configuring networking via provider specific configuration.
Each config has it's own pros and cons and it's really depends on what you plan to achieve.
For additional info check VirtualBox's docs about networking.
I was exactly in the same case, here is a solution that worked for me.
If your vm was up, stop it with:
vagrant halt
Then go to your vagrant box, and open the VagrantFile.
Uncomment (or manually add) the following line inside of it
config.vm.network "public_network"
This will make sure that the next time you "vagrant up" your vm, it will make sure that your vm will get IP from the same subnet as your host (see #m1keil's answer for more details).
Then make your vm up again:
vagrant up
In my case it asked me which interface I should use for the network bridge, here is an excerpt of what I had:
==> default: Available bridged network interfaces:
1) en0: Ethernet
2) en1: Wi-Fi (AirPort)
==> default: When choosing an interface, it is usually the one that is
==> default: being used to connect to the internet.
default: Which interface should the network bridge to? 1
==> default: Preparing network interfaces based on configuration...
Notice that it tells you what your available interfaces are.
Type the number corresponding to the interface that you want, in my case I typed 1 (for en0: Ethernet).
And lastly, connect to your vagrant box.
In my case:
vagrant ssh
Then from the host, if you type ifconfig, you still won't be able to see the ip address of your vm, BUT, if you type ifconfig from your vm, it will give you an ip address that you can ping/access from your host.
Note: If you want to ping/access your host from your guest, be sure that your firewall is off (System>Preferences>Security). The firewall doesn't affect pings from the host to the vm though.
I'm not sure why you are seeing an IP address on the guest but you are not configuring any virtualbox networking at all given that vagrant file. You will want to uncomment the config.vm.network "private network" line and then configure the IP address.
The default setup for virtualbox is to put the host at 10.0.0.2 and expose the whole 10.0.0.0/8 range as a local address so I think anything in the 10.x.x.x range will work for the client vm.

Can't `ssh` onto Private Network

Given the following Vagrantfile:
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "centos_64"
config.vm.host_name = 'web'
config.vm.network "private_network", ip: "192.168.50.4"
end
Why can't I ssh onto the guest from the host?
$ ssh vagrant#web -p 22
ssh: connect to host web port 22: Connection timed out
But using vagrant ssh works:
$ vagrant ssh
Last login: Tue Mar 4 21:29:24 2014 from 10.0.2.2
[vagrant#web ~]$
As expected, I can ping the IP Address from the guest. But I can't ping from the host.
I'm confused as to why it's happening since my setup does not look different from this configuration.
First, vagrant ssh uses the forwarded port and not the private network address. You can get the configuration with vagrant ssh-config.
Is the name "web" really resolving to the specified IP? Can you ping/connect using the IP instead of the name? If not, verify that you don't have other VMs or external networks with the same address. Also some VPN products mess up the routing.
I managed to change the ssh address with
config.ssh.host = '192.168.0.13'
config.ssh.port = '22'`
as mentioned in https://superuser.com/questions/920536/how-to-change-the-ssh-host-in-vagrantfile/921728#921728
Just because the guest host has a defined hostname does not mean that the host machine will resolve its ip.
You should be able to ssh into the machine by doing:
ssh vagrant#192.168.50.4 <==== vagrant is the default password,
but you can avoid typing it alway by doing:
ssh-copy-id vagrant#192.168.50.4
here is my configuration and it's working for me
config.vm.box = "ubuntu/xenial64"
config.vm.network "private_network", ip: "192.168.88.88"
config.ssh.host = "192.168.88.88"