我最近创建了一个云 Ubuntu 18.04 服务器,但无法 ping 外部 IP。我的网络(据我所知)由 netplan 管理。
尝试 ping 或 curl
$ ping google.com
PING google.com (172.217.23.110) 56(84) bytes of data.
^C
--- google.com ping statistics ---
6 packets transmitted, 0 received, 100% packet loss, time 5125ms
$ curl google.com
<hangs>
$ ping -c 4 8.8.8.8
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
^C
--- 8.8.8.8 ping statistics ---
4 packets transmitted, 0 received, 100% packet loss, time 3076ms
路由
default via 135.xxx.48.1 dev ens3 proto dhcp src 135.xxx.48.217 metric 100
135.xxx.48.0/22 dev ens3 proto kernel scope link src 135.xxx.48.217
135.xxx.48.1 dev ens3 proto dhcp scope link src 135.xxx.48.217 metric 100
IP 地址
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether fa:16:3e:31:bc:f8 brd ff:ff:ff:ff:ff:ff
inet 135.xxx.48.217/22 brd 135.171.51.255 scope global ens3
valid_lft forever preferred_lft forever
inet6 fe80::f816:3eff:fe31:bcf8/64 scope link
valid_lft forever preferred_lft forever
路线-n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 135.xxx.48.1 0.0.0.0 UG 100 0 0 ens3
135.xxx.48.0 0.0.0.0 255.255.252.0 U 0 0 0 ens3
135.xxx.48.1 0.0.0.0 255.255.255.255 UH 100 0 0 ens3
iptables -L
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
网上类似的问题和答案经常提到使用ifdown
或,ifup
但这些程序没有安装,而是由我的网络管理netplan
,如下所示。
$ cat /etc/network/interfaces
# ifupdown has been replaced by netplan(5) on this system. See
# /etc/netplan for current configuration.
# To re-enable ifupdown on this system, you can run:
# sudo apt install ifupdown
内容/etc/netplan/50-cloud-init.yaml
:
# This file is generated from information provided by
# the datasource. Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
version: 2
ethernets:
ens3:
dhcp4: true
match:
macaddress: fa:16:3e:31:bc:f8
set-name: ens3
我在看Ubuntu 服务器 16.04 无法 ping 外部 IP 或域或进行更新(以及其他各种问题),但答案不适用于我的 netplan 系统。
答案1
为了解决我的连接问题,我所要做的就是设置并导出我的HTTP_PROXY
、HTTPS_PROXY
和FTP_PROXY
环境变量,使其/etc/profile
具有适合我公司代理的值。