Skip to content

Instantly share code, notes, and snippets.

@lsloan
Last active September 21, 2022 13:53
Show Gist options
  • Star 17 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lsloan/6f4307a2cab2aaa16feb323adf8d7959 to your computer and use it in GitHub Desktop.
Save lsloan/6f4307a2cab2aaa16feb323adf8d7959 to your computer and use it in GitHub Desktop.
Vagrant: host IP address from guest perspective

Unless specified otherwise in Vagrantfile, the IP address of the host (the computer running Vagrant) from the perspective of the guest (the VM being run by Vagrant) is: 10.0.2.2

If that IP address doesn't work, then examination of Vagrantfile should reveal directives that changed it from its default value.

If an IP address can't be found in Vagrantfile, then the following command will probably reveal it:

route -A inet

For example, the output may be:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         10.0.2.2        0.0.0.0         UG    0      0        0 eth0
10.0.2.0        *               255.255.255.0   U     0      0        0 eth0
192.168.33.0    *               255.255.255.0   U     0      0        0 eth1

The desired IP address is the Gateway address of the default destination, which in this case is 10.0.2.2.

@marchrius
Copy link

marchrius commented Mar 31, 2017

Don't forget to specify * as root

@wmcmurray
Copy link

Oh god, thank you !

@contrun
Copy link

contrun commented Jul 8, 2022

You may also just use the magic host _gateway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment