以太网接口名称不一致

以太网接口名称不一致

我在启动后看到这种奇怪的行为,我看到接口为 enp2s0、enp1s0,当我删除模块并再次加载时,我看到 eth0、eth1。我需要取回 enp2s0、enp1s0,因为我的脚本取决于名称。你能帮我更改接口名称吗

开机后:

root@panther2:~# lsmod | grep r8169
r8169                  81920  0
root@panther2:~# ifconfig 
enp1s0    Link encap:Ethernet  HWaddr 3C:E1:A1:3F:21:3F  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

enp2s0    Link encap:Ethernet  HWaddr 3C:E1:A1:3F:F8:17  
          inet addr:192.168.1.2  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::3ee1:a1ff:fe3f:f817/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:219 errors:0 dropped:0 overruns:0 frame:0
          TX packets:120 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:21142 (20.6 KiB)  TX bytes:24150 (23.5 KiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:92 errors:0 dropped:0 overruns:0 frame:0
          TX packets:92 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:4692 (4.5 KiB)  TX bytes:4692 (4.5 KiB)

删除/加载模块: rmmod r8169 ; modprobe r8169

root@panther2:~# ifconfig 
eth0      Link encap:Ethernet  HWaddr 3C:E1:A1:3F:21:3F  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

eth1      Link encap:Ethernet  HWaddr 3C:E1:A1:3F:F8:17  
          inet addr:192.168.1.2  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::3ee1:a1ff:fe3f:f817/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:145 errors:0 dropped:0 overruns:0 frame:0
          TX packets:68 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:15675 (15.3 KiB)  TX bytes:13552 (13.2 KiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:144 errors:0 dropped:0 overruns:0 frame:0
          TX packets:144 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:7344 (7.1 KiB)  TX bytes:7344 (7.1 KiB)

答案1

ip link set eth0 down
ip link set eth0 name enp1s0
ip link set enp1s0 up

ip link set eth1 down
ip link set eth1 name enp2s0
ip link set enp2s0 up

相关内容