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: 域名解析暫時失敗 簡單解決