can not connect to vagrant private network

31 views
Skip to first unread message

John Zhang

unread,
May 22, 2019, 3:39:44 AM5/22/19
to Vagrant
had a vagrant in my Mac with a private network IP, previously it works properly, I can access its private network IP in the host. But can not access from host since yesterday, I dont remember any change to the Vagrantfile...
Could you help give me some suggestions how to bring it back to work? Thanks a lot!

Vagrantfile piece:

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  # Use Centos 7 64-bit as our operating system
  config.vm.box = "centos/7"

  # Configurate the virtual machine to use 2GB of RAM and 2 CPU
  config.vm.provider :virtualbox do |vb|
    vb.name = "vagrant-jenkins"
    vb.customize ["modifyvm", :id, "--memory", "2048"]
    vb.customize ["modifyvm", :id, "--cpus", "2"]
    vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
  end

  config.vm.network :private_network, ip: "192.168.56.8"
  ...
end
 

Logs when vagrant up:

> ➜  toy vagrant up Bringing machine 'default' up with 'virtualbox'
> provider...
> ==> default: Checking if box 'centos/7' is up to date...
> ==> default: A newer version of the box 'centos/7' for provider 'virtualbox' is
> ==> default: available! You currently have version '1804.02'. The latest is version
> ==> default: '1902.01'. Run `vagrant box update` to update.
> ==> default: Clearing any previously set forwarded ports...
> ==> default: Clearing any previously set network interfaces...
> ==> default: Preparing network interfaces based on configuration...
>     default: Adapter 1: nat
>     default: Adapter 2: hostonly
> ==> default: Forwarding ports...
>     default: 22 (guest) => 2222 (host) (adapter 1)
> ==> default: Running 'pre-boot' VM customizations...
> ==> default: Booting VM...
> ==> default: Waiting for machine to boot. This may take a few minutes...
>     default: SSH address: 127.0.0.1:2222
>     default: SSH username: vagrant
>     default: SSH auth method: private key
> ==> default: Machine booted and ready! [default] GuestAdditions 5.2.14 running --- OK.
> ==> default: Checking for guest additions in VM...
> ==> default: Setting hostname...
> ==> default: Configuring and enabling network interfaces...
>     default: SSH address: 127.0.0.1:2222
>     default: SSH username: vagrant
>     default: SSH auth method: private key
> ==> default: Mounting shared folders...


When trying to ssh to it, it is pending on connecting to the private IP:

➜  toy ssh -v toy
OpenSSH_7.6p1, LibreSSL 2.6.2
debug1: Reading configuration data /Users/abc/.ssh/config
debug1: /Users/abc/.ssh/config line 11: Applying options for toy
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 48: Applying options for *
debug1: Connecting to 192.168.56.8 port 22.


ssh config:

Host toy
        Hostname  192.168.56.8
        User      vagrant
        IdentityFile ~/Vagrant/Toy/.vagrant/machines/default/virtualbox/private_key

Dennis Chang

unread,
May 22, 2019, 3:57:07 PM5/22/19
to Vagrant
Try changing your ssh config to:

Host toy
  HostName 192.168.56.8
  Port 2222
  User vagrant
  IdentityFile ~/Vagrant/Toy/.vagrant/machines/default/virtualbox/private_key
Reply all
Reply to author
Forward
0 new messages