Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set up gateway of public network in vagrant

I am setting up my Virtualbox Centos VM with vagrant. I am setting up with a public network.

config.vm.network :public_network, ip: "10.135.15.137"

How do I setup the GATEWAY along with this?

like image 680
deDishari Avatar asked Feb 10 '14 12:02

deDishari


People also ask

Which network should the network bridge to vagrant?

Default Network InterfaceIf more than one network interface is available on the host machine, Vagrant will ask you to choose which interface the virtual machine should bridge to. A default interface can be specified by adding a :bridge clause to the network definition.

How do I make my vagrant network private?

The easiest way to use a private network is to allow the IP to be assigned via DHCP. This will automatically assign an IP address from the reserved address space. The IP address can be determined by using vagrant ssh to SSH into the machine and using the appropriate command line tool to find the IP, such as ifconfig .

How do I set DHCP to private network?

Open a browser and go to https://192.168.0.1 (default) or the IP address you have assigned to the Gateway appliance private user interface. Click Manage Gateway appliance and then click the Private network tab. Select Run DHCP server (recommended) and reconfigure the settings for the private network if necessary.

How do I connect my vagrant box to SSH?

Simply CMD-SHIFT-P then "Remote-SSH: Connect to Host..." and the ssh . config entry you just added is automatically listed - you simply select it and voila, vscode connects to your remote vagrant vm!


3 Answers

According to the (new) documentation, setting up a gateway, can be done by instructing the following, inside the Vagrantfile:

# default router
config.vm.provision "shell",
  run: "always",
  inline: "route add default gw 192.168.0.1"

Read the complete example titled Default Router at http://docs.vagrantup.com/v2/networking/public_network.html.

like image 66
Nikos Alexandris Avatar answered Sep 28 '22 14:09

Nikos Alexandris


Unfortunately Vagrant doesn't support this at the moment.

But there are requests for adding it, for example GH-2832 and GH-2389. The latter one also has some shell provisioner examples you could use to work around it.

like image 40
tmatilai Avatar answered Sep 28 '22 16:09

tmatilai


Vagrant 2.0.1 has a configuration option for this which is explained in the documentation:

Vagrant → Networking → Public Networks → Using the DHCP Assigned Default Route

For your convenience, here is the relevant section (retrieved 2018-05-15):

Using the DHCP Assigned Default Route

Some cases require the DHCP assigned default route to be untouched. In these cases one may specify the use_dhcp_assigned_default_route option. As an example:

Vagrant.configure("2") do |config|
  config.vm.network "public_network",
   use_dhcp_assigned_default_route: true
end
like image 26
RobM Avatar answered Sep 28 '22 16:09

RobM