我是一名 Linux 新手,正在尝试在Pine64在Ubuntu 16.04。我正在尝试使用本地 Bind9 DNS 服务器设置静态 IP 地址。我已按照此操作很棒的教程,并查看了其他几个。
但是,我无法使更改生效/etc/resolv.conf
。/:当我重新启动时,中的设置/etc/network/interfaces
没有写入/etc/resolv.conf
。
这是我的/etc/network/interfaces
:
# interfaces(5) file used by ifup(8) and ifdown(8)
# Include files from /etc/network/interfaces.d:
source-directory /etc/network/interfaces.d
# Disable wlan1 by default (8723bs has two intefaces)
iface wlan1 inet manual
# Loopback interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.0.18
netmask 255.255.255.0
gateway 192.168.0.1
dns-nameservers 192.168.0.18
dns-search green.intra
这是我的/etc/default/bind9
:
# run resolvconf?
RESOLVCONF=yes
# startup options for the server
OPTIONS="-4 -u bind"
从这两个文件中,我的印象是/etc/resolv.conf
应该变成这样(启动时自动):
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 192.168.0.18
search green.intra
...但实际上却变成了这样:
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 83.255.255.1
nameserver 83.255.255.2
search home
如果我将我想要的设置添加到/etc/resolv.conf
,一切都会按我预期的方式工作,直到我重新启动。
我究竟做错了什么?
编辑:我已经阅读手册并试图弄清楚这一点:
https://help.ubuntu.com/14.04/serverguide/dns-troubleshooting.html
https://help.ubuntu.com/12.04/serverguide/network-configuration.html
https://help.ubuntu.com/14.04/serverguide/dns-configuration.html
编辑:ifup
并ifdown
失败:正如对建议的重复问题的回答中所建议的那样,service networking restart
在这种情况下使用可能不可靠。相反,我尝试了以下方法:
ubuntu@pinex:~$ sudo ifdown -v eth0
Reading directory /etc/network/interfaces.d
Parsing file /etc/network/interfaces.d/eth0
ifdown: interface eth0 not configured
和:
ubuntu@pinex:~$ sudo ifdown -v eth0
Reading directory /etc/network/interfaces.d
Parsing file /etc/network/interfaces.d/eth0
ifdown: interface eth0 not configured
ubuntu@pinex:~$ sudo ifup -v eth0
Reading directory /etc/network/interfaces.d
Parsing file /etc/network/interfaces.d/eth0
Configuring interface eth0=eth0 (inet)
/bin/run-parts --exit-on-error --verbose /etc/network/if-pre-up.d
run-parts: executing /etc/network/if-pre-up.d/wpasupplicant
/sbin/dhclient -1 -v -pf /run/dhclient.eth0.pid -lf /var/lib/dhcp/dhclient.eth0.leases -I -df /var/lib/dhcp/dhclient6.eth0.leases eth0
Internet Systems Consortium DHCP Client 4.3.3
Copyright 2004-2015 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/eth0/36:c9:e3:f1:b8:05
Sending on LPF/eth0/36:c9:e3:f1:b8:05
Sending on Socket/fallback
DHCPREQUEST of 192.168.0.18 on eth0 to 255.255.255.255 port 67 (xid=0x79b015c0)
DHCPACK of 192.168.0.18 from 192.168.0.1
RTNETLINK answers: File exists
bound to 192.168.0.18 -- renewal in 5280 seconds.
/bin/run-parts --exit-on-error --verbose /etc/network/if-up.d
run-parts: executing /etc/network/if-up.d/000resolvconf
run-parts: executing /etc/network/if-up.d/bind9
run-parts: executing /etc/network/if-up.d/openssh-server
run-parts: executing /etc/network/if-up.d/upstart
run-parts: executing /etc/network/if-up.d/wpasupplicant
Configuring interface eth0=eth0 (inet)
/bin/run-parts --exit-on-error --verbose /etc/network/if-pre-up.d
run-parts: executing /etc/network/if-pre-up.d/wpasupplicant
/bin/ip addr add 192.168.0.18/255.255.255.0 broadcast 192.168.0.255 dev eth0 label eth0
RTNETLINK answers: File exists
Failed to bring up eth0.
...这让我找到了答案(见下文)。
答案1
正如我的问题所述,根据 Ubuntu 文档,配置是准确的。但是,ifdown
并ifup
没有奏效。经过半天的谷歌搜索,我收集了足够的线索来找到解决方案。
TL;DR;
注释掉(或删除)/etc/network/interfaces.d/eth0
原来的行:
auto eth0
iface eth0 inet dhcp
长答案:
抱歉,我无法解释为什么我会遇到这个问题。我对 Linux 了解得太少了。/:问题似乎是resolvconf
,在启动时触发的(我认为),无法正确更新,/etc/resolv.conf
因为它两次发现相同的界面:一次在我的自定义配置中/etc/network/interfaces.d/eth0
,一次在我的自定义配置中/etc/network/interfaces
。
重新启动网络服务出现此问题:
ubuntu@pinex:~$ sudo service networking restart
Job for networking.service failed because the control process exited with error code. See "systemctl status networking.service" and "journalctl -xe" for details.
ubuntu@pinex:~$ systemctl status networking.service
● networking.service - Raise network interfaces
Loaded: loaded (/lib/systemd/system/networking.service; enabled; vendor preset: enabled)
Drop-In: /run/systemd/generator/networking.service.d
└─50-insserv.conf-$network.conf
Active: failed (Result: exit-code) since Mon 2016-12-19 13:59:48 CET; 10s ago
Docs: man:interfaces(5)
Process: 2433 ExecStart=/sbin/ifup -a --read-environment (code=exited, status=1/FAILURE)
Process: 2428 ExecStartPre=/bin/sh -c [ "$CONFIGURE_INTERFACES" != "no" ] && [ -n "$(ifquery --read-environm
Main PID: 2433 (code=exited, status=1/FAILURE)
Dec 19 13:59:47 pinex ifup[2433]: DHCPACK of 192.168.0.18 from 192.168.0.1
Dec 19 13:59:47 pinex ifup[2433]: RTNETLINK answers: File exists
Dec 19 13:59:47 pinex dhclient[2446]: bound to 192.168.0.18 -- renewal in 4214 seconds.
Dec 19 13:59:47 pinex ifup[2433]: bound to 192.168.0.18 -- renewal in 4214 seconds.
Dec 19 13:59:48 pinex ifup[2433]: RTNETLINK answers: File exists
Dec 19 13:59:48 pinex ifup[2433]: Failed to bring up eth0.
Dec 19 13:59:48 pinex systemd[1]: networking.service: Main process exited, code=exited, status=1/FAILURE
Dec 19 13:59:48 pinex systemd[1]: Failed to start Raise network interfaces.
Dec 19 13:59:48 pinex systemd[1]: networking.service: Unit entered failed state.
Dec 19 13:59:48 pinex systemd[1]: networking.service: Failed with result 'exit-code'.
我记得/etc/network/interfaces.d/eth0
在谷歌上搜索时看到了一些关于的内容。注释掉这些行后,重新启动网络服务就可以了。然而,/etc/resolv.conf
仍然和以前一样……
我必须做以下事情:
ubuntu@pinex:~$ sudo resolvconf -u
/etc/resolvconf/update.d/libc: Warning: /etc/resolv.conf is not a symbolic link to /run/resolvconf/resolv.conf
ubuntu@pinex:~$ sudo rm /etc/resolv.conf
ubuntu@pinex:~$ sudo ln -s /run/resolvconf/resolv.conf /etc/resolv.conf
这已更新/etc/resolv.conf
为我的预期值!设备重启后,文件会自动正确填充!
我希望这对其他人也有帮助!如果有人能解释这个问题,我将不胜感激。(: