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?
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.
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 .
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.
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!
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With