在 Ubuntu 系统中,ifconfig 命令用于配置、激活和查询网络接口的参数。虽然 ifconfig 在较新的 Ubuntu 版本中已经被 ip 命令取代,但它仍然广泛使用。以下是如何使用 ifconfig 来诊断网络故障的一些步骤:
检查网络接口状态:
ifconfig 命令查看所有活动的网络接口及其状态。UP)并且有正确的 IP 地址分配。ifconfig 检查 IP 地址和子网掩码:
ifconfig <interface> up 启动接口,并使用 ifconfig <interface> <ip_address> 分配 IP 地址。检查默认网关:
route -n 或 ip route 查看默认网关是否正确配置。route -n 检查 DNS 配置:
cat /etc/resolv.conf 查看 DNS 服务器配置。测试网络连通性:
ping 命令测试与目标主机的连通性。ping -c 4 google.com 检查网络接口错误:
ifconfig <interface> 重启网络服务:
sudo systemctl restart networking 使用 ethtool 检查硬件状态:
ethtool <interface> 检查网络接口的硬件状态。sudo ethtool eth0 请注意,ifconfig 命令在 Ubuntu 18.04 及更高版本中已被弃用,建议使用 ip 命令替代。例如,可以使用 ip addr show 来查看网络接口信息,使用 ip route 来查看路由表,以及使用 ip link set <interface> up/down 来启用或禁用网络接口。