1.環境說明
系統:Ubuntu 24.04
環境:VMware下橋接靜態IP設定
2.問題:ping www.baidu.com報錯
[~] ping www.baidu.com
ping: www.baidu.com: Temporary failure in name resolution
3.解決辦法
(1)利用route -n命令查詢閘道器正常的伺服器,用命令設定閘道器
- 沒有閘道器的伺服器
[~] route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33
- 有閘道器的正常伺服器
[root@localhost /]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.122.254 0.0.0.0 UG 0 0 0 ens33
192.168.122.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
(2)設定閘道器
[~] sudo route add default gw 192.168.122.254
[~] route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.122.254 0.0.0.0 UG 0 0 0 ens33
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 ens33
(3)測試能正常連通外網
參照:https://blog.csdn.net/qq_32927563/article/details/132297413