分配静态 IP 后,Raspberry Pi DNS 解析失败

分配静态 IP 后,Raspberry Pi DNS 解析失败

我有一台 Raspberry Pi 3 Model B(运行 Ubuntu 16.04),我希望能够通过我们公司的内部网以静态 IP 地址访问它。我通过创建一个包含/etc/network/interfaces.d以下内容的文件来实现这一点:

auto enxb827ebf9dfb5
iface enxb827ebf9dfb5 inet static
address 172.16.100.1
netmask 255.255.0.0
gateway 172.16.0.4
dns-nameserver 8.8.8.8
dns-nameserver 8.8.4.4

我的/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

# The loopback network interface
auto lo
iface lo inet loopback

我可以通过这个地址正常连接到我的 RPi。但是,在进行此更改后,我发现它似乎无法正确执行 DNS 解析。例如,我可以通过运行nslookup另一台计算机来 ping Google 以找到其地址之一并ping <that_address>在 RPi 上运行,但ping www.google.com在 RPi 上运行则不起作用。

如果在每次启动后运行,我可以修复 DNS 解析sudo systemctl restart networking,但我希望 DNS 解析能够像配置为使用 DHCP 时一样自动工作。

这是当前的输出ifconfig

docker0   Link encap:Ethernet  HWaddr 02:42:e3:eb:ae:57
          inet addr:172.17.0.1  Bcast:0.0.0.0  Mask:255.255.0.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

enxb827ebf9dfb5 Link encap:Ethernet  HWaddr b8:27:eb:f9:df:b5
          inet addr:172.16.100.1  Bcast:172.16.255.255  Mask:255.255.0.0
          inet6 addr: fe80::ba27:ebff:fef9:dfb5/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:56384 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2734 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:3299020 (3.2 MB)  TX bytes:449072 (449.0 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:2332 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2332 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:184536 (184.5 KB)  TX bytes:184536 (184.5 KB)

编辑

运行systemctl list-unit-files | grep enabled后输出如下:

cups.path                                  enabled
accounts-daemon.service                    enabled
anacron-resume.service                     enabled
anacron.service                            enabled
[email protected]                            enabled
avahi-daemon.service                       enabled
avahi-dnsconfd.service                     enabled
binfmt-support.service                     enabled
bluetooth.service                          enabled
brltty.service                             enabled
cron.service                               enabled
cups-browsed.service                       enabled
cups.service                               enabled
dbus-org.bluez.service                     enabled
dbus-org.freedesktop.Avahi.service         enabled
dbus-org.freedesktop.ModemManager1.service enabled
dbus-org.freedesktop.nm-dispatcher.service enabled
display-manager.service                    enabled
docker.service                             enabled
fake-hwclock.service                       enabled
friendly-recovery.service                  enabled
[email protected]                             enabled
hciuart.service                            enabled
lightdm.service                            enabled
ModemManager.service                       enabled
network-manager.service                    enabled
networking.service                         enabled
NetworkManager-dispatcher.service          enabled
NetworkManager-wait-online.service         enabled
NetworkManager.service                     enabled
pppd-dns.service                           enabled
resolvconf.service                         enabled
rsyslog.service                            enabled
snapd.autoimport.service                   enabled
snapd.core-fixup.service                   enabled
snapd.service                              enabled
snapd.system-shutdown.service              enabled
ssh.service                                enabled
sshd.service                               enabled
sshdgenkeys.service                        enabled
syslog.service                             enabled
systemd-timesyncd.service                  enabled
tlp-sleep.service                          enabled
tlp.service                                enabled
ufw.service                                enabled
unattended-upgrades.service                enabled
ureadahead.service                         enabled
whoopsie.service                           enabled
apport-forward.socket                      enabled
avahi-daemon.socket                        enabled
cups.socket                                enabled
docker.socket                              enabled
snapd.socket                               enabled
uuidd.socket                               enabled
default.target                             enabled
graphical.target                           enabled
remote-fs.target                           enabled
runlevel5.target                           enabled
apt-daily-upgrade.timer                    enabled
apt-daily.timer                            enabled
snap-repair.timer                          enabled
snapd.refresh.timer                        enabled

答案1

/etc/resolv.conf 是否已填充?

示例配置:

search home
nameserver 8.8.8.8
nameserver 8.8.4.4
options enxb827ebf9dfb5

相关内容