macoshostingvagrantfiledomain-mapping

Changing domain mapping on Mac OSX etc/hosts to Vagrant Virtual Machine


I've been trying to change the mapping for a domain and forward it to a Vagrant machine that I've forwarded a port to.

The config in Vagrantfile:

Vagrant.configure("2") do |config| config.vm.network :forwarded_port, host: 4567, guest: 80 end

I've updated /etc/hosts on my Mac OSX with the following:

127.0.0.1:4567 example.com

Yet when I access from my browser example.com nothing changes, I have also tried to map example.com to go to the Google IP without any luck.

What am I overlooking?


Solution

  • I would just add a static ip, or try removing the port number:

    Vagrant.configure("2") do |config|
      config.vm.network "private_network", ip: "192.168.50.4"
    end
    

    Then in your hosts file change it to read:

    192.168.50.4 example.com
    

    More info is available here: https://docs.vagrantup.com/v2/networking/private_network.html