最近刚将 /etc/network/interfaces 更改为静态 IP,apt-get 无法正常工作。如何检查错误?

最近刚将 /etc/network/interfaces 更改为静态 IP,apt-get 无法正常工作。如何检查错误?

我最近刚刚更新了我的/etc/network/interfaces文件以设置静态 IP 地址。似乎其他计算机可以使用网络 IP 地址访问该计算机,但我可能破坏了某些东西 -now apt-get updateapt-get install ...给我以下信息:

Err ...//jp.archive.ubuntu.com precise Release.gpg
  Temporary failure resolving 'jp.archive.ubuntu.com'
Err http://security.ubuntu.com precise-security Release.gpg
  Temporary failure resolving 'security.ubuntu.com'
Err ...//jp.archive.ubuntu.com precise-updates Release.gpg
  Temporary failure resolving 'jp.archive.ubuntu.com'
Err ...//jp.archive.ubuntu.com precise-backports Release.gpg
  Temporary failure resolving 'jp.archive.ubuntu.com'
Reading package lists... Done
W: Failed to fetch ...//jp.archive.ubuntu.com/ubuntu/dists/precise/Release.gpg  Temporary failure resolving 'jp.archive.ubuntu.com'

W: Failed to fetch ...//jp.archive.ubuntu.com/ubuntu/dists/precise-updates/Release.gpg  Temporary failure resolving 'jp.archive.ubuntu.com'

W: Failed to fetch ...//jp.archive.ubuntu.com/ubuntu/dists/precise-backports/Release.gpg  Temporary failure resolving 'jp.archive.ubuntu.com'

W: Failed to fetch ...//security.ubuntu.com/ubuntu/dists/precise-security/Release.gpg  Temporary failure resolving 'security.ubuntu.com'

W: Some index files failed to download. They have been ignored, or old ones used instead.

As another simple test I tried `ping www.yahoo.com` and it told me host not found (but works fine on another computer on the same router).

有人知道我可能输入了错误的内容/etc/network/interfaces吗?(我假设它在那里,但不确定如何检查)

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
 address ...
 netmask ...
 network ...
 broadcast ...
 gateway ...

# This is an autoconfigured IPv6 interface
iface eth0 inet6 auto

(......我已经设置了地址)

或者用另一种方法检查我可能设置错误的地方(如上所述,我将 eth0 设置为静态 IP - 设置地址、网关、子网等)。谢谢

更新:

我已将以下内容添加到 /etc/networking/interfaces 文件中:

auto eth0
iface eth0 inet auto static
 .
 .
 .
 dns-nameservers 192.168.24.1

顺便说一句,这是我执行 时获得的 DNS nm-tool。它看起来像一个内部 IP 地址,这是我此处 DNS 设置的正确 IP 地址吗?

..无论如何,当我尝试时,/etc/init.d/networking restart出现以下错误:

/etc/init.d/networking restart
 * Running /etc/init.d/networking restart is deprecated because it may not enable again some interfaces
 * Reconfiguring network interfaces...                                                                                   ifdown: failed to open lockfile /run/network/.ifstate.lock: Permission denied
ifup: failed to open lockfile /run/network/.ifstate.lock: Permission denied

ping另外我也无法做到nslookup(对于不像我这样的非初学者来说,这可能很明显:)

答案1

您是否设置了 DNS 地址?如果您运行 DHCP,DNS 会自动配置,但当您使用静态 IP 运行时,则不会。

iface eth0 inet static您可以通过在文件部分下方添加以下内容来配置 DNS /etc/network/interfaces

dns-nameservers 10.100.0.11 10.100.2.11
dns-search int.mtak.nl

将 IP 地址替换为您网络的 DNS 服务器,将搜索域替换为您的搜索域(如果不需要,则删除它)。使用 重新启动网络sudo /etc/init.d/networking restart(或重新启动),然后通过检查 来验证它是否正常工作/etc/resolv.conf

答案2

您需要将 DNS 服务器添加到您的系统。最简单的方法是将此行添加到您的接口文件中。

dns 名称服务器 8.8.8.8 4.2.2.2

您也可以按照此处的说明添加它们: https://wiki.debian.org/NetworkConfiguration#Defining_the_.28DNS.29_Nameservers

相关内容