Nur Rony
Polyglot Programmer. Blindly love JS. An automation freak who love to cook code in React, Redux, RxJS and serve them using Docker. Married to the most beautiful girl.

Vagrant: Common Settings Tips

Customize vagrant according to your choice

Vagrant: Common Settings Tips

I heard about Vagrant in 2013. I am playing with Vagrant about a year. It is really an awesome tool. It totally changed the way of my development. From the beginning I faced some problem and solved it by googling. Today I would like to summarize the common problem and how I got rid of them.

Change Vagrant Box Name

config.vm.define 'nurrony-devbox' do |devbox|  
end 

Change Provider Box Name:

config.vm.provider 'virtualbox' do |vb|  
  vb.name = 'devbox'
end  

Change Hostname of Vagrant box:

config.vm.hostname = 'YourBoxHostname'  

Or

config.vm.define 'nurrony-devbox' do |devbox|  
  devbox.vm.hostname = 'devbox'
end  

The above configuration also change the name of Vagrant box from default to nurrony-devbox

Private Networking:

config.vm.network 'private_network', type: 'dhcp'  

Or with specific IP

config.vm.network 'private_network', ip: '192.168.10.236'  

Public Networking

Vagrant.configure('2') do |config|  
  #DHCP
  config.vm.network 'public_network'
  #STATIC
  config.vm.network 'public_network', ip: '192.168.10.236';
  #Defining Default Network interface
  config.vm.network 'public_network', bridge: 'wlan0'
end  

Disabling Auto config:

config.vm.network 'private_network', ip: '192.168.50.4', auto_config: false  

Resolve Vagrant Box Slow Internet Issue:

config.vm.provider 'virtualbox' do |vb|  
  vb.customize ['modifyvm', :id, '--natdnshostresolver1', 'on']
  vb.customize ['modifyvm', :id, '--natdnsproxy1', 'on']
end  

Packaging a box:

vagrant package --base SPECIFIC_NAME_FOR_VM --output /yourfolder/OUTPUT_BOX_NAME.box  

Sending Command to Vagrant

vagrant ssh -c 'sudo service httpd restart'

I will update this list eventually... 😉