ssh:连接到主机 github.com 端口 22:将 VM 复制到另一台主机后无法访问网络
ssh: connect to host github.com port 22: Network is unreachable after copying VM to another host machine
我刚刚将我的 Vagrant VM 从一台主机复制到另一台主机。两台机器都是运行Windows7.
在我将 VM 复制到其中的一台机器上,我在尝试访问 Github 时收到以下错误。
回购肯定存在,我在原始机器上有完全相同的 Git 配置。为什么会这样?此错误的最高 SO 答案对我没有影响。
[vagrant@localhost /var/www/wrestlemaniamainevent]# git remote -v
origin git@github.com:crmpicco/wrestlemaniamainevent.git (fetch)
origin git@github.com:crmpicco/wrestlemaniamainevent.git (push)
[vagrant@localhost /var/www/wrestlemaniamainevent]# git fetch origin
ssh: connect to host github.com port 22: Network is unreachable
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
我可以 ping Github,当我将 URL 更改为 https 时,我得到了这个:
[vagrant@localhost /var/www/wrestlemaniamainevent]# ping github.com
PING github.com (192.30.252.129) 56(84) bytes of data.
64 bytes from 192.30.252.129: icmp_seq=23 ttl=51 time=112 ms
64 bytes from 192.30.252.129: icmp_seq=24 ttl=51 time=110 ms
64 bytes from 192.30.252.129: icmp_seq=25 ttl=51 time=112 ms
64 bytes from 192.30.252.129: icmp_seq=26 ttl=51 time=111 ms
64 bytes from 192.30.252.129: icmp_seq=27 ttl=51 time=112 ms
^C
--- github.com ping statistics ---
27 packets transmitted, 5 received, 81% packet loss, time 26010ms
rtt min/avg/max/mdev = 110.904/111.957/112.869/0.756 ms
[vagrant@localhost /var/www/wrestlemaniamainevent]# git fetch origin
fatal: unable to access 'https://github.com/crmpicco/wrestlemaniamainevent.git/': Failed connect to github.com:443; Network is unreachable
我的 Vagrantfile
unless Vagrant.has_plugin?("vagrant-host-shell")
raise 'vagrant-host-shell plugin is not installed!'
end
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
PRIVATE_NETWORK_IP = "10.0.0.200"
SERVER_NAME = "crmpicco.dev"
nfs_setting = RUBY_PLATFORM =~ /darwin/ || RUBY_PLATFORM =~ /linux/
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
config.ssh.forward_agent = true
config.vm.define "local", primary: true do |local|
nfs_setting = RUBY_PLATFORM =~ /darwin/ || RUBY_PLATFORM =~ /linux/
local.vm.network :forwarded_port, guest:4444, host:4444
local.vm.network :private_network, ip: PRIVATE_NETWORK_IP
local.vm.box = "crmpicco-centos7"
local.vm.box_url = "http://crmpicco.com/boxes/crmpicco.box"
# If you want to keep your code local and mount onto your VM, uncomment this.
#
# local.vm.synced_folder "./../www", "/var/www", id: "vagrant-root" , :nfs => nfs_setting,
# mount_options: ["sync,rsize=32768,wsize=32768,rw,proto=tcp"]
local.vm.provider :virtualbox do |v|
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
v.customize ["modifyvm", :id, "--memory", 3072]
v.customize ["modifyvm", :id, "--cpus", 2]
v.customize ["modifyvm", :id, "--name", SERVER_NAME]
end
end
# If you want to keep your code local and mount onto your VM, comment this whole section
if nfs_setting
config.vm.provision :host_shell do |host_shell|
host_shell.inline = 'mkdir -p /Users/Shared/crmpicco'
end
config.vm.provision :host_shell, run: "always" do |host_shell|
host_shell.inline = "echo 'Waiting for NFS to be available, it can take a while'"
end
config.vm.provision :host_shell, run: "always" do |host_shell|
host_shell.inline = "sleep 30"
end
config.vm.provision :host_shell, run: "always" do |host_shell|
host_shell.inline = "mount -t nfs -o 'sync,rsize=32768,wsize=32768,rw' #{PRIVATE_NETWORK_IP}:/var/www/current /Users/Shared/crmpicco"
end
end
end
首先,你确认它不是新主机的网络问题了吗,你能从新主机上的虚拟机 ping github 吗?
其次,如果 ssh 有问题(而且你不是像我这样的网络专家 - 可能是新主机上的防火墙问题......),您可以更改为使用 https 版本
run `git config --local -e`
你应该有一个部分
[remote "origin"]
url = git@github.com:crmpicco/wrestlemaniamainevent.git
您可以将其更改为
[remote "origin"]
url = https://github.com/crmpicco/wrestlemaniamainevent.git
Third,确保两台主机上的 vagrant 版本相同(特别是如果一台主机运行 vagrant 1.6 而另一台主机运行 1.7),如果不同但虚拟框应该没问题但要更新GuestAdditions 如果你有不同版本的虚拟盒子。
我通过在 Virtualbox 设置中创建一个新的 Virtual Box Host-Only Adapter 解决了这个问题,这里:
原来的无法识别,所以我不得不创建一个新的。
其次,正如 FredericHenri 在下面指出的那样 - 在我原来的主机(Win 7 PC)上我是 运行 Virtualbox 4.3.12,而在第二台主机(Win 7 笔记本电脑)上我是 运行 Virtualbox 4.3.16 - 所以我也降级了第二台主机,这解决了问题。
我刚刚将我的 Vagrant VM 从一台主机复制到另一台主机。两台机器都是运行Windows7.
在我将 VM 复制到其中的一台机器上,我在尝试访问 Github 时收到以下错误。
回购肯定存在,我在原始机器上有完全相同的 Git 配置。为什么会这样?此错误的最高 SO 答案对我没有影响。
[vagrant@localhost /var/www/wrestlemaniamainevent]# git remote -v
origin git@github.com:crmpicco/wrestlemaniamainevent.git (fetch)
origin git@github.com:crmpicco/wrestlemaniamainevent.git (push)
[vagrant@localhost /var/www/wrestlemaniamainevent]# git fetch origin
ssh: connect to host github.com port 22: Network is unreachable
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
我可以 ping Github,当我将 URL 更改为 https 时,我得到了这个:
[vagrant@localhost /var/www/wrestlemaniamainevent]# ping github.com
PING github.com (192.30.252.129) 56(84) bytes of data.
64 bytes from 192.30.252.129: icmp_seq=23 ttl=51 time=112 ms
64 bytes from 192.30.252.129: icmp_seq=24 ttl=51 time=110 ms
64 bytes from 192.30.252.129: icmp_seq=25 ttl=51 time=112 ms
64 bytes from 192.30.252.129: icmp_seq=26 ttl=51 time=111 ms
64 bytes from 192.30.252.129: icmp_seq=27 ttl=51 time=112 ms
^C
--- github.com ping statistics ---
27 packets transmitted, 5 received, 81% packet loss, time 26010ms
rtt min/avg/max/mdev = 110.904/111.957/112.869/0.756 ms
[vagrant@localhost /var/www/wrestlemaniamainevent]# git fetch origin
fatal: unable to access 'https://github.com/crmpicco/wrestlemaniamainevent.git/': Failed connect to github.com:443; Network is unreachable
我的 Vagrantfile
unless Vagrant.has_plugin?("vagrant-host-shell")
raise 'vagrant-host-shell plugin is not installed!'
end
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
PRIVATE_NETWORK_IP = "10.0.0.200"
SERVER_NAME = "crmpicco.dev"
nfs_setting = RUBY_PLATFORM =~ /darwin/ || RUBY_PLATFORM =~ /linux/
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# Disable automatic box update checking. If you disable this, then
# boxes will only be checked for updates when the user runs
# `vagrant box outdated`. This is not recommended.
# config.vm.box_check_update = false
config.ssh.forward_agent = true
config.vm.define "local", primary: true do |local|
nfs_setting = RUBY_PLATFORM =~ /darwin/ || RUBY_PLATFORM =~ /linux/
local.vm.network :forwarded_port, guest:4444, host:4444
local.vm.network :private_network, ip: PRIVATE_NETWORK_IP
local.vm.box = "crmpicco-centos7"
local.vm.box_url = "http://crmpicco.com/boxes/crmpicco.box"
# If you want to keep your code local and mount onto your VM, uncomment this.
#
# local.vm.synced_folder "./../www", "/var/www", id: "vagrant-root" , :nfs => nfs_setting,
# mount_options: ["sync,rsize=32768,wsize=32768,rw,proto=tcp"]
local.vm.provider :virtualbox do |v|
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
v.customize ["modifyvm", :id, "--memory", 3072]
v.customize ["modifyvm", :id, "--cpus", 2]
v.customize ["modifyvm", :id, "--name", SERVER_NAME]
end
end
# If you want to keep your code local and mount onto your VM, comment this whole section
if nfs_setting
config.vm.provision :host_shell do |host_shell|
host_shell.inline = 'mkdir -p /Users/Shared/crmpicco'
end
config.vm.provision :host_shell, run: "always" do |host_shell|
host_shell.inline = "echo 'Waiting for NFS to be available, it can take a while'"
end
config.vm.provision :host_shell, run: "always" do |host_shell|
host_shell.inline = "sleep 30"
end
config.vm.provision :host_shell, run: "always" do |host_shell|
host_shell.inline = "mount -t nfs -o 'sync,rsize=32768,wsize=32768,rw' #{PRIVATE_NETWORK_IP}:/var/www/current /Users/Shared/crmpicco"
end
end
end
首先,你确认它不是新主机的网络问题了吗,你能从新主机上的虚拟机 ping github 吗?
其次,如果 ssh 有问题(而且你不是像我这样的网络专家 - 可能是新主机上的防火墙问题......),您可以更改为使用 https 版本
run `git config --local -e`
你应该有一个部分
[remote "origin"]
url = git@github.com:crmpicco/wrestlemaniamainevent.git
您可以将其更改为
[remote "origin"]
url = https://github.com/crmpicco/wrestlemaniamainevent.git
Third,确保两台主机上的 vagrant 版本相同(特别是如果一台主机运行 vagrant 1.6 而另一台主机运行 1.7),如果不同但虚拟框应该没问题但要更新GuestAdditions 如果你有不同版本的虚拟盒子。
我通过在 Virtualbox 设置中创建一个新的 Virtual Box Host-Only Adapter 解决了这个问题,这里:
原来的无法识别,所以我不得不创建一个新的。
其次,正如 FredericHenri 在下面指出的那样 - 在我原来的主机(Win 7 PC)上我是 运行 Virtualbox 4.3.12,而在第二台主机(Win 7 笔记本电脑)上我是 运行 Virtualbox 4.3.16 - 所以我也降级了第二台主机,这解决了问题。