How To Use Vagrant Networking

In this article, I will discuss some of the ways to configure virtual machines using Vagrant networking.

Vagrant is a favorite among developers and operating alike, as it brings a free solution for managing the testing of applications, servers and configurations. One of the great features of Vagrant is that users are never tied to one virtualization platform (Virtualbox, VMware, Hyper-V etc.), rather they can create workflows that work with any or all of these simultaneously.

To do this, Vagrant offers a way to manage configurations at a higher level that provides roughly the same features to each virtualization provider.

Port Forwarding

The default way to access a Vagrant box is via SSH with the command vagrant ssh. For this to occur, Vagrant forwards port 22 from the guest to an open port on your local machine, such as 2222. Vagrant actually handles this automatically, but users also have the ability to set port forwarding in the Vagrantfile not only SSH but any protocol or port.

For instance, in this example, I want to perform port forwarding for Remote Desktop to the guest. I set the host port to 33390 and the guest to 3389, which is the default RDP port in Windows.

Now if I run vagrant rdp on my local machine, Vagrant will try to establish a connection on port 33390 of your local host to 3389 of your guest VM as illustrated below. Even better, RDP works from my Mac host to my Windows Vagrant box.

vagrant

Public and Private Networking

Enhance your IT career by learning how to automate with Python. Get started with this free Python guide.

Generally speaking, the use cases for Vagrant would not be to open up your virtual machines for public accessibility, but the option is there for certain providers. In this scenario, you are effectively bridging the network connection on your guest virtual machine so that it appears physically connected to your hosts network.

With private network, virtual machines are given a private network address, and if you have multiple machines on the same subnet, they can communicate with each other.

For example, in this Vagrantfile we have a Puppet master and two nodes. Since the IP addresses are stated to be in the same range, all of the virtual machines can communicate with each other.

Continue at ipswitch.com

Leave a Reply

Your email address will not be published. Required fields are marked *