Ubuntu 服务器无法访问互联网

Ubuntu 服务器无法访问互联网

在我的 Ubuntu Server 16.04(它是一个虚拟机)上,我将 IP 设置为静态,如下所示:

# The primary network interface
auto ens33
iface ens33 inet static
  address 192.168.70.10
  netmask 255.255.255.0
  gateway 192.168.70.1
  dns-nameservers 8.8.8.8 8.8.4.4

我无法访问互联网。以下 ping 不起作用:

dockerize@containerize:~$ ping www.google.ch
ping: unknown host www.google.ch

然后我重新设置 DHCP,ping 就可以了:

dockerize@containerize:~$ ping www.google.ch
PING www.google.ch (216.58.213.195) 56(84) bytes of data.
64 bytes from ham02s15-in-f195.1e100.net (216.58.213.195): icmp_seq=1 ttl=128 time=29.8 ms
64 bytes from ham02s15-in-f195.1e100.net (216.58.213.195): icmp_seq=2 ttl=128 time=30.1 ms
^C
--- www.google.ch ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 29.882/30.001/30.121/0.210 ms

我从 DHCP 获得了以下 IP:

dockerize@containerize:~$ ifconfig
ens33     Link encap:Ethernet  HWaddr 00:0c:29:bf:cf:78  
          inet addr:192.168.70.135  Bcast:192.168.70.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:febf:cf78/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:230 errors:0 dropped:0 overruns:0 frame:0
          TX packets:111 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:22864 (22.8 KB)  TX bytes:14513 (14.5 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:160 errors:0 dropped:0 overruns:0 frame:0
          TX packets:160 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1 
          RX bytes:11840 (11.8 KB)  TX bytes:11840 (11.8 KB)

我可以通过 ssh 访问服务器。出了什么问题?

更新

DHCP 的网络信息:

dockerize@containerize:~$ cat /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.70.2
search localdomain

dockerize@containerize:~$ ip route
default via 192.168.70.2 dev ens33 
192.168.70.0/24 dev ens33  proto kernel  scope link  src 192.168.70.135 

然后我将接口更改为:

# The primary network interface
auto ens33
iface ens33 inet static
address 192.168.70.10
netmask 255.255.255.0
gateway 192.168.70.1
dns-nameservers 192.168.70.2

答案1

根据您根据 terdons 问题提供的信息,我得出以下问题:

您预期默认网关为 ,但192.168.70.1实际上可用时为192.168.70.2

要修复此问题,请尝试以下配置/etc/network/interfaces

# The primary network interface
auto ens33
iface ens33 inet static
address 192.168.70.10
netmask 255.255.255.0
gateway 192.168.70.2
dns-nameservers 192.168.70.2

注意:您仍然可以使用 Google 的 DNS IP 作为 中的值dns-nameservers。如果您想这样做,请使用以下配置:

# The primary network interface
auto ens33
iface ens33 inet static
address 192.168.70.10
netmask 255.255.255.0
gateway 192.168.70.2
dns-nameservers 8.8.8.8 8.8.4.4

相关内容