use*_*973 2 linux networking centos
我将如何在 CentOS 上安装eth0?当我这样做时ifconfig -a,eth0不在那里。这是输出ip link:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
3: venet0: <BROADCAST,POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue
link/void
Run Code Online (Sandbox Code Playgroud)
网络接口在 Linux 上可以有不同的名称,具体取决于它们的类型(有线以太网、Wi-Fi、PPP、SLIP 等)、PCI 插槽、初始化顺序等。例如,如果一台计算机有一个以太网卡,它的名称将是是eth0 *。
在您的情况下,有一个没有以太网网卡的虚拟专用服务器,甚至没有模拟服务器。不过,您有一个名为venet0 的网卡。您可以使用以下命令重命名:
ip link set venet0 name eth0
Run Code Online (Sandbox Code Playgroud)
如果接口正在使用中,该命令将失败,因此您可能需要将其关闭 ( ip link set venet0 down),但这可能会断开您与服务器的连接。
如果您愿意冒险,您可以在后台运行一个脚本,该脚本将界面关闭、重命名,然后将其打开。首先获取venet0和路由表的设置:
[root@server ~]# ip addr show dev venet0
2: venet0: <BROADCAST,POINTOPOINT,NOARP,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN
link/void
inet 127.0.0.1/32 scope host venet0
inet X.Y.Z.T/32 brd X.Y.Z.T scope global venet0:0
[root@server ~]# ip ro
192.0.2.0/24 dev venet0 scope host
169.254.0.0/16 dev venet0 scope link metric 1002
default dev venet0 scope link
Run Code Online (Sandbox Code Playgroud)
然后创建一个rename-to-eth0.sh类似于此的脚本 ( ):
#!/bin/sh
### Rename
ip link set venet0 down # Bring interface down
ip link set venet0 name eth0 # Rename interface
ip link set eth0 up # Bring interface up
### Restore
# Restore interface settings. Adapt accordingly!!!
ip addr add 127.0.0.1/32 scope host dev eth0
ip addr add X.Y.Z.T/32 brd X.Y.Z.T scope global label eth0:0 dev eth0
# Restore routing table. Adapt accordingly!!!
ip ro add 192.0.2.0/24 dev venet0 scope host
ip ro add 169.254.0.0/16 dev venet0 scope link metric 1002
ip ro add default dev eth0
Run Code Online (Sandbox Code Playgroud)
现在使用nohup ienohup ./rename-to-eth0.sh或 inside screen、tmux等运行脚本。如果失败,您可能必须重新启动服务器。
*随着“可预测网络接口名称”提案的实施,情况会有所改变,尽管这不适用于 CentOS6 或更早版本。请注意,根据该提议,集成以太网卡可能被命名为em1。