How to find the Vagrant IP?

前端 未结 12 1270
余生分开走
余生分开走 2021-01-30 08:17

I have been developing an automated deployment using Capistrano and using Vagrant as my test virtual server.

The thing is, I need the IP of Vagrant to \"ssh

相关标签:
12条回答
  • 2021-01-30 08:59

    Open a terminal, cd to the path of your Vagrantfile and write this

    (Linux)

    vagrant ssh -c "hostname -I | cut -d' ' -f2" 2>/dev/null
    

    (OS X)

    vagrant ssh -c "hostname -I | cut -d' ' -f2" 2>/dev/null | pbcopy
    

    The command for Linux also works for windows. I have no way to test, sorry.

    source: https://coderwall.com/p/etzdmq/get-vagrant-box-guest-ip-from-host

    0 讨论(0)
  • 2021-01-30 08:59

    I've developed a small vagrant-address plugin for that. It's simple, cross-platform, cross-provider, and does not require scripting.

    https://github.com/mkuzmin/vagrant-address

    0 讨论(0)
  • 2021-01-30 09:05

    Because I haven't seen it here yet... When you vagrant ssh into the box, I realized it actually tells you the ip addresses of the interfaces. You can get it there. For example.

     {~/Documents/jupyterhub-ansible} (features *%)$  vagrant ssh
    Welcome to Ubuntu 18.04.2 LTS (GNU/Linux 4.15.0-50-generic x86_64)
    
     * Documentation:  https://help.ubuntu.com
     * Management:     https://landscape.canonical.com
     * Support:        https://ubuntu.com/advantage
    
      System information as of Wed May 22 12:00:34 UTC 2019
    
      System load:  0.12              Processes:             101
      Usage of /:   56.5% of 9.63GB   Users logged in:       0
      Memory usage: 19%               IP address for enp0s3: 10.0.2.15
      Swap usage:   0%                IP address for enp0s8: 192.168.33.10
    
    
    10 packages can be updated.
    1 update is a security update.
    
    
    Last login: Wed May 22 12:00:04 2019 from 192.168.33.1
    vagrant@ubuntu-bionic:~$ 
    

    In my vagrant file I assigned the address like this:

    config.vm.network "private_network", ip: "192.168.33.10"

    and as you can see, IP address for enp0s8: 192.168.33.10

    0 讨论(0)
  • 2021-01-30 09:09

    We are using VirtualBox as a provider and for the virtual box, you can use VBoxManage to get the IP address

    VBoxManage guestproperty get <virtual-box-machine-name> /VirtualBox/GuestInfo/Net/1/V4/IP
    
    0 讨论(0)
  • 2021-01-30 09:09

    I know this post is old but i want to add a few points to this!

    you can try

    vagrant ssh -c "ifconfig | grep inet" hostname 
    

    this will be easy if you have setup a name to your guests individually!

    0 讨论(0)
  • 2021-01-30 09:10

    Terminating a connection open with vagrant ssh will show the address, so a dummy or empty command can be executed:

    $ vagrant ssh -c ''
    Connection to 192.168.121.155 closed.
    
    0 讨论(0)
提交回复
热议问题