Skip to content

Instantly share code, notes, and snippets.

@mauriballes
Created February 15, 2019 22:06
Show Gist options
  • Save mauriballes/14b9eb8df1278aaf9a8e3ad8d2419008 to your computer and use it in GitHub Desktop.
Save mauriballes/14b9eb8df1278aaf9a8e3ad8d2419008 to your computer and use it in GitHub Desktop.
Vagrant file for Create Vagrant Machines match an IP Address
Vagrant.configure("2") do |config|
config.vm.provider "virtualbox" do |v|
v.name = "machine-name-virtualbox"
end
config.vm.synced_folder ".", "/vagrant", disabled: true
config.vm.provider "virtualbox" do |v|
v.memory = 2048
v.cpus = 2
end
config.vm.box = "ubuntu/xenial64"
config.vm.hostname = "machine-hostname"
config.vm.define "machine-name"
# Your internal IP could be: 192.168.0.12 or 10.1.10.12 etc...
# Your bridge cold be: eth0 or enp1s0f1 etc...
config.vm.network "public_network", ip: "internal-ip", bridge: "your-machine-bridge"
# remove default shell
config.vm.provision "shell",
run: "always",
inline: "eval `route -n | awk '{ if ($8 ==\"enp0s3\" && $2 != \"0.0.0.0\") print \"route del default gw \" $2; }'`"
# default router static ip
# 10.1.10.1 -> Replace with your default gateway from your router
# 10.1.10.12 -> Replace with your the ip address you want to give the virtual machine
config.vm.provision "shell",
run: "always",
inline: "ip route add default via 10.1.10.1 dev enp0s8 proto dhcp src 10.1.10.12 metric 100"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment