How to find the Vagrant IP?

2020-05-12 11:48发布

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 into it".

I tried ifconfig and got the IP but it looks like it is not the exact vagrant IP.

Can anybody help me to get the Vagrant IP?

12条回答
爷的心禁止访问
2楼-- · 2020-05-12 12:22

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
查看更多
成全新的幸福
3楼-- · 2020-05-12 12:24

run:

vagrant ssh-config > .ssh.config

and then in config/deploy.rb

role :web, "default"     
role :app, "default"
set :use_sudo, true
set :user, 'root'
set :run_method, :sudo

# Must be set for the password prompt from git to work
default_run_options[:pty] = true
ssh_options[:forward_agent] = true
ssh_options[:config] = '.ssh.config'
查看更多
一纸荒年 Trace。
4楼-- · 2020-05-12 12:24

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!

查看更多
叛逆
5楼-- · 2020-05-12 12:26

In the terminal type:

ip addr show
查看更多
不美不萌又怎样
6楼-- · 2020-05-12 12:32

I needed to know this to tell a user what to add to their host machine's host file. This works for me inside vagrant using just bash:

external_ip=$(cat /vagrant/config.yml | grep vagrant_ip | cut -d' ' -f2 | xargs)
echo -e "# Add this line to your host file:\n${external_ip}     host.vagrant.vm"
查看更多
Emotional °昔
7楼-- · 2020-05-12 12:37

open terminal, come to 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

查看更多
登录 后发表回答