大网数据广告活动
服务器运维问答

Persistently rename a Linux network interface without Udev / Reboot

· 52CE 我爱测

Based on: http://kernelpanik.net/rename-a-linux-network-interface-without-udev/ We can easily change the name of an interface using: ifconfig peth0 down ip link set peth0 name eth0 ifconfig eth0 up How do we do it at startup usin…

问题原文

原帖链接 · user1707414 · CC BY-SA 4.0

Based on: http://kernelpanik.net/rename-a-linux-network-interface-without-udev/

We can easily change the name of an interface using:

ifconfig peth0 down  
ip link set peth0 name eth0  
ifconfig eth0 up

How do we do it at startup using the above way ?

In /etc/network/interfaces or any other file ?

已采纳解答

原帖链接 · user1707414 · CC BY-SA 4.0

Thanks to netplan (default in ubuntu 18.04) this is now particularly easy. You can set the interface name based on macaddress or driver:

Edit an existing .yaml configuration file in /etc/netplan/ or create a new one:

sudo nano /etc/netplan/config.yaml

Here is an example with MAC address matching. Names are set with 'set-name' and matched by the MAC address of the interface:

network:
  ethernets:
    wan:
      match:
        macaddress: 00:ab:cd:ef:12:34
      addresses: 
        - 10.5.1.2/16
      dhcp4: true
      optional: true
      set-name: wan0
    lan:
      match:
        macaddress: 00:ab:cd:ef:12:45
      addresses: 
        - 10.6.1.1/16
      optional: true
      set-name: eth0
  version: 2

Save the .yaml file and apply the configuration with:

sudo netplan apply

A reboot may be required to apply the name change.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2018-05-02)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。