导致 apt-get 错误的静态 IP 配置

jpe*_*sen 6 server apt networking 12.04

运行apt-get update或安装新软件包时出现错误。尽管这仅在服务器配置为静态 IP 地址时才会发生。将配置改回 DHCP 并重新启动网络可以解决问题,尽管我想要一个静态 IP。一旦它工作,我可以改回我的静态 IP 地址并重新启动网络。虽然这只在我重新启动服务器之前有效(重新启动路由器是可以的),然后我开始遇到相同的错误并且必须切换回 DHCP。

关于可能导致此问题的任何想法或有关故障排除的提示?提前致谢。

  • 这是我的静态 IP 配置:

    auto eth0
    iface eth0 inet static
        address 192.168.2.2
        netmask 255.255.255.0
        gateway 192.168.2.1
    
    Run Code Online (Sandbox Code Playgroud)
  • apt-get update错误是否是这样的:

    其中一些

    Ign http://us.archive.ubuntu.com precise-backports InRelease
    
    Run Code Online (Sandbox Code Playgroud)

    那么很多这些

    Err http://security.ubuntu.com precise-security Release.gpg   Something wicked happened resolving 'security.ubuntu.com:http' (-5 - No address associated with hostname)
    
    Run Code Online (Sandbox Code Playgroud)

    和很多这些

    W: Failed to fetch http://us.archive.ubuntu.com/ubuntu/dists/precise-backports/universe/i18n/Translation-en  Something wicked happened resolving 'us.archive.ubuntu.com:http' (-5 - No address associated with hostname)
    
    Run Code Online (Sandbox Code Playgroud)

Ale*_*zel 8

听起来您无法通过 DNS 解析域。假设是这种情况,您可能可以通过添加一行来修复它dns-nameservers/etc/network/interfaces

auto eth0
iface eth0 inet static
    address 192.168.2.2
    netmask 255.255.255.0
    gateway 192.168.2.1
    dns-nameservers 192.168.2.1
Run Code Online (Sandbox Code Playgroud)

然后运行

resolvconf -u
Run Code Online (Sandbox Code Playgroud)

以 root 身份更新/etc/resolv.conf。随意包含 DNS 搜索域记录(通常也通过 DHCP 分发)。有关详细信息,请参阅resolvconf(8)