Update VM's bridged MAC address with Vagrant - macos

Is it possible to dynamically change the MAC address of a VM, using Vagrant?
My host is MacOsX, my guest is Debian8,
and I want to test the following commands (learning about network):
/etc/init.d/networking stop
ifconfig eth0 down
ifconfig eth0 hw ether aa:aa:aa:aa:aa:aa
ifconfig eth0 up
dhclient eth0
The problem is that the first command (/etc/init.d/networking stop) freezes the ssh terminal, so I can't really go forward (I have to vagrant halt, and up again).
And if I remove the first command, then the networking system automatically assigns an IP address to the VM machine as soon as "ifconfig eth0 up" is executed, which defeats the purpose of testing the "dhclient eth0" command (which is actually the one I would like to test).
I'm aware that one can statically change the MAC address at startup (with config.vm.network "public_network" , :mac => "5CA1AB1E0001" for instance), but that's not what I want to do here.
So is dynamic update of the MAC address in a public network with Vagrant possible at all?

You cannot run this command from vagrant ssh as vagrant will use the NAT (eth0) interface to ssh into the VM so if you shut it down the interface, you're cutting your ssh connection.
If you want to run this command you will need to login to the VM directly from VirtualBox (or VMWare if you use this provider) and you will be able to run this command

Related

How to bind the VM docker-machine creates to OSX IP address?

I'm developing locally with Docker on OSX using the latest Docker toolkit. I have a node server running in a docker container, bound to port 9999 of the VM. I can hit this server from a browser on my mac, and I would like to hit from another device on the same network. Is there a way to bind the VM to the machine's IP address? Or otherwise expose it?
I just figured this one out today! I am using docker-machine with virtualbox on Mac OS 10.10.5. The first thing I tried was to change the network interface from NAT to Bridged. This just breaks docker-machine's ability to communicate with the VM.
Instead I ADDED another network adapter running in bridged mode.
After starting the docker-machine I get this:
$ docker-machine ip redis-test
10.222.11.242
That is a local network address accessible from anyone else in my office or on my VPN.
Then if I run something like:
$ docker run -p 6379:6379 -d redis
I get a containerized redis service running on port 6379 of the 10.222.11.242 address.
So I can do this from anywhere else on the network:
$ telnet 10.222.11.242 6379
Trying 10.222.11.242...
Connected to 10.222.11.242.
Escape character is '^]'.
info
$1827
# Server
redis_version:2.8.19
...
And as a cool bonus of this we can remap the ports like this:
$ docker run -p 8080:6379 -d redis
e7cc53d9c157a658041c3bee5967dd3678b4d35e6146a02220a87bfebfc919ad
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e7cc53d9c157 redis "/entrypoint.sh redis" 7 seconds ago Up 6 seconds 0.0.0.0:8080->6379/tcp goofy_yonath
bf1dc6c7c6b5 redis "/entrypoint.sh redis" 51 minutes ago Up 51 minutes 0.0.0.0:6379->6379/tcp redis
Now I have two redis instances listening on different ports (6379 and 8080) of the same IP.
EDIT: Here are some details to help those confused about adding a NIC to the VM in VirtualBox. I have only used VirtualBox for this and cannot advise about other virtualization system configurations.
Stop the VM by selecting it in the VM Manager and using the right-click menu or pressing 'command-F'.
Click "Settings".
Click "Network".
Select one of the Adapters that is not currently enabled.
Enable it.
Select "Bridged Adapter" in the "Attached to" selection.
Click OK.
Start your VM and try it out.
NOTE: I am sure there are some clever command line options for doing this setup, but since I only ever needed to set it once I have never bothered to automate it.
You could setup port forwarding on the VirtualBox NAT adaptor.
Bridging it to the local network (in the answer above) is not the same as using the OSX IP address. Bridging can sometimes cause extra headaches if you are on laptop and move to different internet connections. The VM may not automatically pull a new IP from the new network, etc.
In the UI go to Settings --> Network --> Port Forwarding or from the commandline something like this:
VBoxManage controlvm "default" natpf1 "tcp-port9999,tcp,,9999,,9999";
where "default" is the name of the VM ("default" is normally used for docker-machine) and 9999 is the port you want to map.
More info at: https://github.com/boot2docker/boot2docker/blob/master/doc/WORKAROUNDS.md
https://www.virtualbox.org/manual/ch06.html (Configuring Port forwarding with NAT)
Did you put the expose command in Dockerfile?
EXPOSE 9999
Based on #e.thompsy answer, here is the command line version.
First, figure out the interface name you need using:
vboxmanage list bridgedifs
For me it was en1.
Then:
docker-machine create ...
docker-machine stop $VM
vboxmanage modifyvm "$VM" --nic3 bridged --bridgeadapter3 en1
docker-machine start $VM

How to use Putty to connect to a virtual machine?

I am running a virtual machine on Virtual Box
On running ifconfig eth1, I get
inet addr: 192.168.56.11 and many more values.
How do I use Putty (ssh) here?
I entered 192.168.56.11 on the Host Name and 80 on the Port Number, but Putty can't connect.
I am trying to follow the guidelines from this course:
https://s3-us-west-2.amazonaws.com/cs144-misc/instructions/vm.html
What exactly does Putty do? I don't understand why I need to do this.
PuTTY will open a "network" between both machines. You'll get a console (like the shell) when you'll be connected. Really useful to administrate remote server from your computer.
Usually, the port is not 80, but 22.
For oracle vm virtual box:
1)Power of your machine
2)goto Settings -> Network -> Adapter1 -> Enable Network Adapter -> select "Bridge Adapter" in Attache To tab and click 'ok" button
3) open terminal in virtual box and type" ifconfig"
in first paragraph
eth0 Link encap:Ethernet HWaddr 08:00:27:fb:d1:28
inet addr:172.16.2.199
4) Here ip address is "172.16.2.199" using this ip and port 22 ,you can login through putty and winscp also
Try opening terminal through VMWare's console on Ubuntu and then run below given code:
sudo apt-get install openssh-server
I had faced the same issue.
Note: I assume you have already started the VM, importing the ISO image, and tried to access the machine with 10.X.X.X or 172.X.X.X range IP address from the Putty agent and got an time-out message.
Before making any changes to the network configuration on the VM or trying bridge-adapters, as suggested by many of the articles online, I suggest you to check 2 robust points which forms the bus for your VM on VirtualBox and Putty agent installed on your system.
1st Point:
Opening Host Network Manager in File section of your Oracle VirtualBox
Adding a host-only ethernet network (I suggest to keep a 192.X.X.X range)
2nd Point: Adding a host-only adapter, under the network settings of your VM.
Host-Only Adapter settings
If you follow these steps before booting up the VM for the first time, your VM will be allocated with a 192 range IP address (by the dhcp) the moment it boots up and starts running. Now all you need to do is, install and openssh-server and use the 192-range IP address with the Putty agent and Voila!!
Hope this help! Greetings!

Using gitlab-vagrant-vm from OSX host

I followed the instructions here and was able to succesfully (I think) install the gitlab vagrant virtual machine on OSX 10.8 using virtualbox.
I can do vagrant up to get the VM running, and everything seems to work fine. After that I can do vagrant ssh without a problem. Also, after sshing into the VM I was able to do bundle exec rake gitlab:test, which completed with results being 1584 examples, 0 failures.
I would like to see the gitlab web interface from my OSX host machine. I thought I could just direct my browser to the IP indicated in the VagrantFile (http://192.168.3.14), but that didn't work.
Any ideas?
Also any other usage tips for this setup would be appriciated (things like where the repositories are stored on my host machine so I can back them up, if anyone set the gitlab-vagrant-vm up for external access from either another computer on the network or a remote source, ect.)
You have to connect a second interface for vagrant. To do this you've to edit the VagrantFile.
For example if you want to conenct to the host wifi add the following line after 192.168.3.14
config.vm.network :bridged, bridge: "en0: Wi-Fi (AirPort)"
You also can bridge to the ethernet interface. Use ifconfig on the host machine to determine the right interface. After that the dyndns-server of the host network will assign an IP to the Vagrant-Box. Then you can access GitLab on that IP.
Did you actually start the server? You can do that with
bundle exec foreman start -p 3000
This will start the server on port 3000, you would then access it from the host with
http://192.168.3.14:3000/
Hope this helps,
Chris

Docker container - how to configure so it gets a viable IP address when running in vagrant?

Docker (www.docker.io) looks terrific. However, after installing VirtualBox, Vagrant
... and finally Docker on a Mac, I'm finding it's not possible to access the service running in the Docker container from another computer (or from a terminal session on the Mac). The service I'm trying to access is Redis.
The problem appears to be that there's no route to the IP address assigned to the Docker container. In this case the container's IP is 172.16.42.2 while the Mac's IP is 196.168.0.3.
A couple notes:
It IS possible to access it - but only from within the VirtualBox session. This can be done using redis-cli -h 172.16.42.2 -p 6379.
I have added "config.vm.network :bridged" to the VagrantFile in an attempt to get the, but that didn't solve the problem.
The VM generated by vagrant is indeed isolated, in order to access it from your host, you can allocate a private network to it.
Instead of doing config.vm.network :bridged, try config.vm.network :private_network, ip: "192.168.50.4", It should do the trick
However, this will only allow you to access the VM itself, not the containers.
In order to do so, when running the container, you can add the -p option
ex: docker run -d -p 8989 base nc -lkp 8989
This will run a netcat listening on 8989 within a container and expose the port publicly. As it is also run with -d, the container will be in detached mode and the only output will be the container's ID
In order to expose the port, Docker do a simple NAT. In order to know the real port, you can
do docker port <ID of the container> 8989
Netcat will be available from the mac at 192.168.50.4:<result>
I just wrote a tutorial of how to use a host-only network and TCP routing to make this pretty easy. This way you don't have to map every specific port.
http://ispyker.blogspot.com/2014/04/accessing-docker-container-private.html
Important points ...
1) Add host-only network to Virtual Box
2) Tell the boot2docker VM to have an adapter on the host-only network
3) Add an IP for the new boot2docker VM host-only networking adapter
4) Route all Mac OS X traffic for the docker container subnet to that boot2docker VM host-only networking IP
Actual steps are on the blog with output so you can compare to what you see as you follow them.
I have installed tomcat from my Dockerfile and forwarded that to 6060 using vagrant`s port forwarding. These are the steps worked for me:
vagrant provision
vagrant up
vagrant ssh
box_name$ docker run -i -t -p 8080:8080 bsb_tomcat6 /bin/bash
Able to see tomcat up & running on localhost:6060, as I have done port forwarding to 6060 in my Vagrantfile
you also can define PRIVATE_NETWORK and FORWARD_DOCKER_PORTS environment variables to access your services that are running in docker containers:
$ vagrant halt
$ export PRIVATE_NETWORK=192.168.50.4
$ export FORWARD_DOCKER_PORTS=1
$ vagrant up
In my case i can access postgres from Mac using
$ telnet 192.168.50.4 49154
to find out actual application port you can use
$ sudo docker port 1854499c6547 5432
0.0.0.0:49154

Vagrant not running on 33.33.33.10

The first time I started up vagrant, the VM was running on 33.33.33.10. After a "vagrant destroy", every time I start up vagrant it runs on 127.0.0.1 even though my Vagrantfile has the following configuration:
config.vm.network :hostonly, "33.33.33.10"
How do I get vagrant to run on 33.33.33.10 again?
127.0.0.1 is loopback interface's home address. Your current machine is always 127.0.0.1.
When you're looking for the proper IP address, run command ifconfig (on UNIX), and look for eth interface.
I guess it's still running at the same address, you just missed the correct IP.
Would you please try running ifconfig eth0 on your virtual machine?
HTH.

Resources