VM apt-get install - 网络无法访问

VM apt-get install - 网络无法访问

我有一台 Vagrant 支持的 Ubuntu VM,我想在上面做一些性能测试。为了做到这一点,我尝试安装 gdb

当我运行 apt-get install 时,我看到以下内容:

vagrant@ubuntu-1204:~$ sudo apt-get install gdb
sudo: /etc/sudoers.d/vagrant is mode 0644, should be 0440
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  libpython2.7 python2.7 python2.7-minimal
Suggested packages:
  gdb-doc gdbserver python2.7-doc binfmt-support
The following NEW packages will be installed:
  gdb libpython2.7
The following packages will be upgraded:
  python2.7 python2.7-minimal
2 upgraded, 2 newly installed, 0 to remove and 74 not upgraded.
Need to get 7,915 kB of archives.
After this operation, 9,836 kB of additional disk space will be used.
Do you want to continue [Y/n]? y
WARNING: The following packages cannot be authenticated!
  python2.7 python2.7-minimal libpython2.7 gdb
Install these packages without verification [y/N]? y
Err http://us.archive.ubuntu.com/ubuntu/ precise-updates/main python2.7 amd64 2.7.3-0ubuntu3.8
  Could not connect to 192.168.0.0:59875 (192.168.0.0). - connect (101: Network is unreachable)
Err http://us.archive.ubuntu.com/ubuntu/ precise-updates/main gdb amd64 7.4-2012.04-0ubuntu2.1
  Unable to connect to 192.168.0.0:59875:
Err http://security.ubuntu.com/ubuntu/ precise-security/main python2.7 amd64 2.7.3-0ubuntu3.8
  Could not connect to 192.168.0.0:59875 (192.168.0.0). - connect (101: Network is unreachable)
Err http://security.ubuntu.com/ubuntu/ precise-security/main python2.7-minimal amd64 2.7.3-0ubuntu3.8
  Unable to connect to 192.168.0.0:59875:
Err http://security.ubuntu.com/ubuntu/ precise-security/main libpython2.7 amd64 2.7.3-0ubuntu3.8
  Unable to connect to 192.168.0.0:59875:
Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/p/python2.7/python2.7_2.7.3-0ubuntu3.8_amd64.deb  Could not connect to 192.168.0.0:59875 (192.168.0.0). - connect (101: Network is unreachable)
Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/p/python2.7/python2.7-minimal_2.7.3-0ubuntu3.8_amd64.deb  Unable to connect to 192.168.0.0:59875:
Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/p/python2.7/libpython2.7_2.7.3-0ubuntu3.8_amd64.deb  Unable to connect to 192.168.0.0:59875:
Failed to fetch http://us.archive.ubuntu.com/ubuntu/pool/main/g/gdb/gdb_7.4-2012.04-0ubuntu2.1_amd64.deb  Unable to connect to 192.168.0.0:59875:
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?

据我所知,缺少一些网络配置,但我有点不知所措。我可以 ping google.com 并得到成功的响应,所以我有点困惑为什么 security.ubuntu.com 似乎在 192.168.0.0 上

这是我所看到的ifconfig

eth0      Link encap:Ethernet  HWaddr 08:00:27:0a:49:50  
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe0a:4950/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1134 errors:0 dropped:0 overruns:0 frame:0
          TX packets:914 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:147105 (147.1 KB)  TX bytes:523962 (523.9 KB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:208 errors:0 dropped:0 overruns:0 frame:0
          TX packets:208 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:10871 (10.8 KB)  TX bytes:10871 (10.8 KB)

任何帮助将非常感激!

更新

尝试添加

config.vm.network "public_network", bridge: [
    "en0: Wi-Fi",
    "en3: Thunderbolt"
]

但问题仍然存在。

这是路由表:

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

我也尝试 ping Ubuntu 服务器,结果一切正常:

PING us.archive.ubuntu.com (91.189.91.24) 56(84) bytes of data.
64 bytes from economy.canonical.com (91.189.91.24): icmp_req=1 ttl=63 time=84.5 ms
64 bytes from economy.canonical.com (91.189.91.24): icmp_req=2 ttl=63 time=84.8 ms
64 bytes from economy.canonical.com (91.189.91.24): icmp_req=3 ttl=63 time=84.5 ms
64 bytes from economy.canonical.com (91.189.91.24): icmp_req=4 ttl=63 time=85.1 ms
64 bytes from economy.canonical.com (91.189.91.24): icmp_req=5 ttl=63 time=83.9 ms
64 bytes from economy.canonical.com (91.189.91.24): icmp_req=6 ttl=63 time=84.3 ms
64 bytes from economy.canonical.com (91.189.91.24): icmp_req=7 ttl=63 time=84.3 ms
64 bytes from economy.canonical.com (91.189.91.24): icmp_req=8 ttl=63 time=84.4 ms
64 bytes from economy.canonical.com (91.189.91.24): icmp_req=9 ttl=63 time=84.5 ms
64 bytes from economy.canonical.com (91.189.91.24): icmp_req=10 ttl=63 time=84.5 ms
64 bytes from economy.canonical.com (91.189.91.24): icmp_req=11 ttl=63 time=83.9 ms
64 bytes from economy.canonical.com (91.189.91.24): icmp_req=12 ttl=63 time=84.7 ms
64 bytes from economy.canonical.com (91.189.91.24): icmp_req=13 ttl=63 time=84.8 ms
64 bytes from economy.canonical.com (91.189.91.24): icmp_req=14 ttl=63 time=83.8 ms
^C
--- us.archive.ubuntu.com ping statistics ---
15 packets transmitted, 14 received, 6% packet loss, time 14024ms
rtt min/avg/max/mdev = 83.827/84.460/85.102/0.499 ms

答案1

Vagrant 使用 VirtualBox。因此,请转到您的实例并检查您的网卡是否正确桥接。您可以在 Vagrantfile 中配置它。例如,我的 Macbook 的线路用于将网络桥接到我的 WLAN 卡。

server.vm.network "public_network", bridge:'en0: WLAN (AirPort)'

也许这对您的问题有帮助。

http://docs.vagrantup.com/v2/networking/public_network.html

检查你的 VBox 设置。是否有正确的网络桥接。 在此处输入图片描述

您是否设置了另一个网关?也许创建一个新实例并检查它是否正常工作。也许您的包管理器中存在任何错误配置。

答案2

奇怪的是 apt-get 正在连接 192.168.0.0:59875。

您对 apt-get 使用了代理吗?

检查一下:

$ apt-config dump Acquire::http::Proxy
$ echo $http_proxy

相关内容