在 Linux 中,ifconfig 本身并不会导致无法联网,它只是一个查看和配置网络接口的工具。如果你说“ifconfig 无法联网”,通常是指以下几种情况之一。下面我按常见原因逐一说明,并给出排查方法。
ifconfig 命令)ifconfig
# 或
ip addr
启动网卡并获取 IP:
ifconfig eth0 up
dhclient eth0
或(推荐新系统):
ip link set eth0 up
dhclient eth0
route -n
# 或
ip route
如果没有 default 路由:
ip route add default via 192.168.1.1
cat /etc/resolv.conf
应有类似:
nameserver 8.8.8.8
临时修改:
echo "nameserver 8.8.8.8" > /etc/resolv.conf
iptables -L
可临时关闭测试:
systemctl stop firewalld
# 或
iptables -F
现代 Linux 通常用:
nmcli device status
重启网络:
systemctl restart NetworkManager
新系统可能没装:
apt install net-tools # Debian/Ubuntu
yum install net-tools # CentOS 7
ip addr
ip route
ping 8.8.8.8
ping www.baidu.com
如果你愿意,可以把下面信息发我,我可以精准判断:
ip addr 输出我可以一步一步帮你修好。