程式扎記: [Linux 常見問題] How to change a network interface name on CentOS 7

標籤

2015年10月23日 星期五

[Linux 常見問題] How to change a network interface name on CentOS 7

Source From Here 
Introduction 
Traditionally, network interfaces in Linux are enumerated as eth[0123...], but these names do not necessarily correspond to actual hardware slots, PCI geography, USB port number, etc. This introduces a unpredictable naming problem (e.g., due to undeterministic device probing behavior) which can cause various network misconfigurations (e.g., disabled interface or firewall bypass resulting from unintentional interface renaming). MAC address based udev rules are not so much helpful in a virtualized environment where MAC addresses are as euphemeral as port numbers. 

CentOS/RHEL 6 has introduced a method for consistent and predictable network device naming for network interfaces. These features uniquely determine the name of network interfaces in order to make locating and differentiating the interfaces easier and in such a way that it is persistent across later boots, time, and hardware changes. However, this naming rule is not turned on by default on CentOS/RHEL 6. 

Starting with CentOS/RHEL 7, the predictable naming rule is adopted by default. Under this rule, interface names are automatically determined based on firmware, topology, and location information. Now interface names stay fixed even if NIC hardware is added or removed without re-enumeration, and broken hardware can be replaced seamlessly. 
  1. * Two character prefixes based on the type of interface:  
  2. *   en -- ethernet  
  3. *   sl -- serial line IP (slip)  
  4. *   wl -- wlan  
  5. *   ww -- wwan  
  6. *  
  7. * Type of names:  
  8. *   b                             -- BCMA bus core number  
  9. *   ccw                             -- CCW bus group name  
  10. *   o                              -- on-board device index number  
  11. *   s[f][d]     -- hotplug slot index number  
  12. *   x                                -- MAC address  
  13. *   [P]ps[f][d]  
  14. *                                         -- PCI geographical location  
  15. *   [P]ps[f][u][..]1[i<interface>]  
  16. *                                         -- USB port number chain  
A minor disadvantage of this new naming scheme is that the interface names are somewhat harder to read than the traditional names. For example, you may find names like enp0s3. Besides, you no longer have any control over such interface names. 
 

If, for some reason, you prefer the old way, and want to be able to assign any arbitrary name of your choice to an interface on CentOS/RHEL 7, you need to override the default predictable naming rule, and define a MAC address based udev rule. 

Here is how to rename a network interface on CentOS or RHEL 7. 
First, let's disable the predictable naming rule. For that, you can pass "net.ifnames=0" kernel parameter during boot. This is achieved by editing/etc/default/grub and adding "net.ifnames=0" to GRUB_CMDLINE_LINUX variable. 
 

Then run this command to regenerate GRUB configuration with updated kernel parameters. 
$ sudo grub2-mkconfig -o /boot/grub2/grub.cfg

 

Next, edit (or create) a udev network naming rule file (/etc/udev/rules.d/70-persistent-net.rules), and add the following line. Replace MAC address and interface with your own. 
$ sudo vi /etc/udev/rules.d/70-persistent-net.rules
  1. SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:fd:32:df", ATTR{type}=="1", KERNEL=="eth*", NAME="sushi"  

Finally, reboot the machine, and verify the new interface name. 
 

Note that it is still your responsibility to configure the renamed interface. If the network configuration (e.g., IPv4 settings, firewall rules) is based on the old name (before change), you need to update network configuration to reflect the name change. 

Supplement 
CentOS : Manual IP network configuration

沒有留言:

張貼留言

網誌存檔

關於我自己

我的相片
Where there is a will, there is a way!