linux 主机无法联网问题

主机不能联网
查看当前ip ping路由

ifconfig wlan0
wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.78  netmask 255.255.255.0  broadcast 192.168.2.255

ping 192.168.2.1

查看是否能ping通

查看路由表

route -n
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.2.0     0.0.0.0         255.255.255.0   U     0      0        0 wlan0

这种情况缺默认网关,添加网关

route add default gw 192.168.2.1
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.2.1   0.0.0.0         UG    0      0        0 wlan0
192.168.2.0     0.0.0.0         255.255.255.0   U     0      0        0 wlan0

查看 /etc/resolv.conf dns解析

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
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "resolvectl status" to see details about the actual nameservers.
nameserver 192.168.0.1

dns解析为空或缺失对应 添加一行

nameserver 192.168.2.1

192.168.2.1修改为对应的路由地址

你可能感兴趣的:(linux,服务器,运维)