用ifconfig命令,显示结果只有lo,没有eth0

本文介绍了如何解决Linux系统中网卡未启用的问题。通过使用ifconfig命令查看网络接口状态,编辑配置文件ifcfg-eth0设置ONBOOT为yes,并重启网络服务来启用网卡。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

解决:
1. 输入ifconfig -a命令,可以看到eth0和lo。
2. 进入/etc/sysconfig/network-scripts 目录,发现有ifcfg-eth0,即网卡(驱动)存在但未启用。
3. 输入ifconfig eth0 up,启用网卡。此时用ifconfig,只能看到inet6的地址,没有ip
4. vi /etc/sysconfig/network-scripts/ifcfg-eth0 文件, 把ONBOOT=no 改为 ONBOOT=yes,检查其他信息又没错误。
5. service network restart,重启

https://blog.youkuaiyun.com/buyueliuying/article/details/78444810

### ifconfig 显示 eth2 和 lo 接口的原因及含义 在网络接口配置方面,`ifconfig` 是一个常用的工具用于管理和显示网络接口的状态。当执行 `ifconfig` 或者带有特定参数的命令时,可以观察到不同的网络接口被列出。 对于 `eth2` 这样的命名方式,在较旧版本的 Linux 发行版中较为常见。通常情况下,系统会按照发现顺序自动分配编号给以太网设备,比如第一个检测到的是 `eth0`, 第二个可能是 `eth1` 等等[^3]。如果存在名为 `eth2` 的接口,则意味着这是第三个物理或虚拟以太网适配器。此接口可能代表实际硬件连接或者是通过某些机制创建出来的逻辑接口。 至于回环接口 (`lo`) ,这是一个特殊的网络接口,它并不对应于任何外部通信端口而是存在于操作系统内部。其主要作用是用来处理本地进程之间的数据交换以及测试目的。每一个基于 Unix/Linux 的系统都会有一个默认存在的回环接口,并且一般会被赋予 IP 地址 127.0.0.1 (IPv4) 或 ::1 (IPv6)[^2]。 为了更好地理解这些概念,下面是一个简单的 Python 脚本模拟如何获取并打印当前系统的网络接口列表: ```python import os def get_network_interfaces(): result = os.popen('ip addr show').read() interfaces = [] lines = result.split('\n') current_interface = None for line in lines: stripped_line = line.strip() if not stripped_line or ':' not in stripped_line: continue parts = stripped_line.split(': ') if len(parts) >= 2 and '@' not in parts[1]: interface_name = parts[1].strip() if current_interface is not None: interfaces.append(current_interface) current_interface = {'name': interface_name, 'details': []} elif current_interface is not None: current_interface['details'].append(stripped_line) if current_interface is not None: interfaces.append(current_interface) return interfaces for iface in get_network_interfaces(): print(f"Interface Name: {iface['name']}") for detail in iface['details']: print(detail) ``` 该脚本利用了更现代的 `ip` 工具来代替传统的 `ifconfig` 来列举所有可用的网络接口及其属性信息。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值