{"id":4091,"date":"2014-12-24T19:03:28","date_gmt":"2014-12-24T11:03:28","guid":{"rendered":"http:\/\/rmohan.com\/?p=4091"},"modified":"2014-12-24T19:03:28","modified_gmt":"2014-12-24T11:03:28","slug":"how-to-change-a-network-interface-name-on-centos-7","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=4091","title":{"rendered":"How to change a network interface name on CentOS 7"},"content":{"rendered":"<p>Traditionally, network interfaces in Linux are enumerated as eth[0123&#8230;], 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 <tt>udev<\/tt> rules are not so much helpful in a virtualized environment where MAC addresses are as euphemeral as port numbers.<\/p>\n<p>CentOS\/RHEL 6 has introduced a method for <a href=\"https:\/\/access.redhat.com\/documentation\/en-US\/Red_Hat_Enterprise_Linux\/6\/html\/Deployment_Guide\/appe-Consistent_Network_Device_Naming.html\" target=\"_blank\">consistent and predictable network device naming<\/a> 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.<\/p>\n<p>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.<\/p>\n<div>\n<div id=\"highlighter_558075\" class=\"syntaxhighlighter  bash\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<div class=\"line number6 index5 alt1\">6<\/div>\n<div class=\"line number7 index6 alt2\">7<\/div>\n<div class=\"line number8 index7 alt1\">8<\/div>\n<div class=\"line number9 index8 alt2\">9<\/div>\n<div class=\"line number10 index9 alt1\">10<\/div>\n<div class=\"line number11 index10 alt2\">11<\/div>\n<div class=\"line number12 index11 alt1\">12<\/div>\n<div class=\"line number13 index12 alt2\">13<\/div>\n<div class=\"line number14 index13 alt1\">14<\/div>\n<div class=\"line number15 index14 alt2\">15<\/div>\n<div class=\"line number16 index15 alt1\">16<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"bash plain\">* Two character prefixes based on the <\/code><code class=\"bash functions\">type<\/code> <code class=\"bash plain\">of interface:<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"bash plain\">*\u00a0\u00a0 en -- ethernet<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"bash plain\">*\u00a0\u00a0 sl -- serial line IP (slip)<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"bash plain\">*\u00a0\u00a0 wl -- wlan<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"bash plain\">*\u00a0\u00a0 ww -- wwan<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"bash plain\">*<\/code><\/div>\n<div class=\"line number7 index6 alt2\"><code class=\"bash plain\">* Type of names:<\/code><\/div>\n<div class=\"line number8 index7 alt1\"><code class=\"bash plain\">*\u00a0\u00a0 b&lt;number&gt;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -- BCMA bus core number<\/code><\/div>\n<div class=\"line number9 index8 alt2\"><code class=\"bash plain\">*\u00a0\u00a0 ccw&lt;name&gt;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -- CCW bus group name<\/code><\/div>\n<div class=\"line number10 index9 alt1\"><code class=\"bash plain\">*\u00a0\u00a0 o&lt;index&gt;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -- on-board device index number<\/code><\/div>\n<div class=\"line number11 index10 alt2\"><code class=\"bash plain\">*\u00a0\u00a0 s&lt;slot&gt;[f&lt;<\/code><code class=\"bash keyword\">function<\/code><code class=\"bash plain\">&gt;][d&lt;dev_port&gt;]\u00a0\u00a0\u00a0\u00a0 -- hotplug slot index number<\/code><\/div>\n<div class=\"line number12 index11 alt1\"><code class=\"bash plain\">*\u00a0\u00a0 x&lt;MAC&gt;\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -- MAC address<\/code><\/div>\n<div class=\"line number13 index12 alt2\"><code class=\"bash plain\">*\u00a0\u00a0 [P&lt;domain&gt;]p&lt;bus&gt;s&lt;slot&gt;[f&lt;<\/code><code class=\"bash keyword\">function<\/code><code class=\"bash plain\">&gt;][d&lt;dev_port&gt;]<\/code><\/div>\n<div class=\"line number14 index13 alt1\"><code class=\"bash plain\">*\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -- PCI geographical location<\/code><\/div>\n<div class=\"line number15 index14 alt2\"><code class=\"bash plain\">*\u00a0\u00a0 [P&lt;domain&gt;]p&lt;bus&gt;s&lt;slot&gt;[f&lt;<\/code><code class=\"bash keyword\">function<\/code><code class=\"bash plain\">&gt;][u&lt;port&gt;][..]1[i&lt;interface&gt;]<\/code><\/div>\n<div class=\"line number16 index15 alt1\"><code class=\"bash plain\">*\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 -- USB port number chain<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>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 <tt>enp0s3<\/tt>. Besides, you no longer have any control over such interface names.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/rmohan.com\/wp-content\/uploads\/2014\/12\/eth0001.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4092\" src=\"http:\/\/rmohan.com\/wp-content\/uploads\/2014\/12\/eth0001.jpg\" alt=\"eth0001\" width=\"750\" height=\"339\" srcset=\"https:\/\/mohan.sg\/wp-content\/uploads\/2014\/12\/eth0001.jpg 750w, https:\/\/mohan.sg\/wp-content\/uploads\/2014\/12\/eth0001-300x135.jpg 300w, https:\/\/mohan.sg\/wp-content\/uploads\/2014\/12\/eth0001-150x67.jpg 150w, https:\/\/mohan.sg\/wp-content\/uploads\/2014\/12\/eth0001-400x180.jpg 400w\" sizes=\"(max-width: 750px) 100vw, 750px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>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 <tt>udev<\/tt> rule.<\/p>\n<p><b>Here is how to rename a network interface on CentOS or RHEL 7<\/b>.<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/rmohan.com\/wp-content\/uploads\/2014\/12\/eth0002.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4093\" src=\"http:\/\/rmohan.com\/wp-content\/uploads\/2014\/12\/eth0002.jpg\" alt=\"eth0002\" width=\"1322\" height=\"195\" srcset=\"https:\/\/mohan.sg\/wp-content\/uploads\/2014\/12\/eth0002.jpg 1322w, https:\/\/mohan.sg\/wp-content\/uploads\/2014\/12\/eth0002-300x44.jpg 300w, https:\/\/mohan.sg\/wp-content\/uploads\/2014\/12\/eth0002-1024x151.jpg 1024w, https:\/\/mohan.sg\/wp-content\/uploads\/2014\/12\/eth0002-150x22.jpg 150w, https:\/\/mohan.sg\/wp-content\/uploads\/2014\/12\/eth0002-400x59.jpg 400w, https:\/\/mohan.sg\/wp-content\/uploads\/2014\/12\/eth0002-900x132.jpg 900w\" sizes=\"(max-width: 1322px) 100vw, 1322px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p>First, let&#8217;s disable the predictable naming rule. For that, you can pass &#8220;net.ifnames=0&#8221; kernel parameter during boot. This is achieved by editing \/etc\/default\/grub and adding &#8220;net.ifnames=0&#8221; to GRUB_CMDLINE_LINUX variable.<\/p>\n<p>[root@localhost ~]# grub2-mkconfig -o \/boot\/grub2\/grub.cfg<br \/>\nGenerating grub configuration file &#8230;<br \/>\nFound linux image: \/boot\/vmlinuz-3.10.0-123.el7.x86_64<br \/>\nFound initrd image: \/boot\/initramfs-3.10.0-123.el7.x86_64.img<br \/>\nFound linux image: \/boot\/vmlinuz-3.10.0-123.13.1.el7.x86_64<br \/>\nFound initrd image: \/boot\/initramfs-3.10.0-123.13.1.el7.x86_64.img<br \/>\nFound linux image: \/boot\/vmlinuz-0-rescue-11510efe0881461cb2aa7cb613f65395<br \/>\nFound initrd image: \/boot\/initramfs-0-rescue-11510efe0881461cb2aa7cb613f65395.img<br \/>\ndone<\/p>\n<p>&nbsp;<\/p>\n<p>Next, edit (or create) a <tt>udev<\/tt> 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.<\/p>\n<div class=\"console\">$ vi \/etc\/udev\/rules.d\/70-persistent-net.rules<\/div>\n<div class=\"console\"><\/div>\n<div class=\"console\">SUBSYSTEM==&#8221;net&#8221;, ACTION==&#8221;add&#8221;, DRIVERS==&#8221;?*&#8221;, ATTR{address}==&#8221;00:0c:29:58:a6:b7&#8243;, ATTR{type}==&#8221;1&#8243;, KERNEL==&#8221;eth*&#8221;, NAME=&#8221;mohan&#8221;<\/div>\n<div class=\"console\"><\/div>\n<div class=\"console\"><\/div>\n<div class=\"console\"><\/div>\n<div class=\"console\"><a href=\"http:\/\/rmohan.com\/wp-content\/uploads\/2014\/12\/eth0003.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4094\" src=\"http:\/\/rmohan.com\/wp-content\/uploads\/2014\/12\/eth0003.jpg\" alt=\"eth0003\" width=\"1154\" height=\"721\" srcset=\"https:\/\/mohan.sg\/wp-content\/uploads\/2014\/12\/eth0003.jpg 1154w, https:\/\/mohan.sg\/wp-content\/uploads\/2014\/12\/eth0003-300x187.jpg 300w, https:\/\/mohan.sg\/wp-content\/uploads\/2014\/12\/eth0003-1024x639.jpg 1024w, https:\/\/mohan.sg\/wp-content\/uploads\/2014\/12\/eth0003-150x93.jpg 150w, https:\/\/mohan.sg\/wp-content\/uploads\/2014\/12\/eth0003-400x249.jpg 400w, https:\/\/mohan.sg\/wp-content\/uploads\/2014\/12\/eth0003-900x562.jpg 900w\" sizes=\"(max-width: 1154px) 100vw, 1154px\" \/><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Traditionally, network interfaces in Linux are enumerated as eth[0123&#8230;], 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 [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,4,17],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/4091"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4091"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/4091\/revisions"}],"predecessor-version":[{"id":4095,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/4091\/revisions\/4095"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4091"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4091"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4091"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}