1、前言
ping: www.baidu.com: 域名解析暂时失败
2、排查
ifconfig
显示如下,enx000ec635404a网卡没有ip配置
enp4s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.19.138 netmask 255.255.255.0 broadcast 192.168.19.255
inet6 fe80::d058:2b28:6be9:fe29 prefixlen 64 scopeid 0x20<link>
ether ce:e6:4c:68:04:bc txqueuelen 1000 (以太网)
RX packets 276511173 bytes 348533647010 (348.5 GB)
RX errors 0 dropped 23750 overruns 0 frame 0
TX packets 465668303 bytes 541502143429 (541.5 GB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
enx000ec635404a: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
ether 00:0e:c6:35:40:4a txqueuelen 1000 (以太网)
RX packets 71039 bytes 12267317 (12.2 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 10258570 bytes 11216668369 (11.2 GB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (本地环回)
RX packets 6466211 bytes 1905907598 (1.9 GB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 6466211 bytes 1905907598 (1.9 GB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
sudo vim /etc/netplan/00-installer-config.yaml
创建配置文件,输入以下内容
enx000ec635404a 网卡名称与上述缺少ip的网卡一致
network:
ethernets:
enx000ec635404a: #配置的网卡的名称
addresses: [192.168.0.138/24] #配置的静态ip地址和掩码
dhcp4: no #关闭DHCP,如果需要打开DHCP则写yes
optional: true
gateway4: 192.168.0.1 #网关地址
nameservers:
addresses: [192.168.0.1,114.114.114.114] #DNS服务器地址,多个DNS服务器地址需要用英文逗号分隔开
version: 2
renderer: networkd #指定后端采用systemd-networkd或者Network Manager,可不填写则默认使用systemd-workd
sudo netplan apply
使网络配置生效
结果
enp4s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.19.138 netmask 255.255.255.0 broadcast 192.168.19.255
inet6 fe80::d058:2b28:6be9:fe29 prefixlen 64 scopeid 0x20<link>
ether ce:e6:4c:68:04:bc txqueuelen 1000 (以太网)
RX packets 276511173 bytes 348533647010 (348.5 GB)
RX errors 0 dropped 23750 overruns 0 frame 0
TX packets 465668303 bytes 541502143429 (541.5 GB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
enx000ec635404a: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.138 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 fe80::864b:38d0:a3d7:cc1d prefixlen 64 scopeid 0x20<link>
ether 00:0e:c6:35:40:4a txqueuelen 1000 (以太网)
RX packets 71039 bytes 12267317 (12.2 MB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 10258570 bytes 11216668369 (11.2 GB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (本地环回)
RX packets 6466211 bytes 1905907598 (1.9 GB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 6466211 bytes 1905907598 (1.9 GB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
3、扩展
ping: www.baidu.com: 域名解析暂时失败 简单解决