Renaming network interfaces linux

How to rename an Ethernet interface?

As my built-in NIC was not supported by Ubuntu out-of-the-box I was forced to use a USB NIC for temporary installation-time Internet connection. And the USB NIC has taken the eth0 name making the built-in NIC to become eth1 . Sure, this doesn’t really matter but just for the system «prettiness» I would like eth1 to become eth0 letting any newly attached NIC to become eth1 . Is this possible?

3 Answers 3

gksudo gedit /etc/udev/rules.d/70-persistent-net.rules 

Swap eth0 and eth1. Proofread carefully, save and close gedit. Use any other text editor if you don’t have gedit. Reboot immediately and you should be all set.

Just for the record: this is correct for 14.04, but 70-persistent-net.rules no longer exists as of Ubuntu 15.10. See askubuntu.com/questions/689501 for a solution that works for Ubuntu 15.10, 16.04, and later.

You are correct. When this was posted in 2012, it was the correct procedure. This procedure, as well as many other things, has changed in 15.10 et seq.

This renames em1 to eth0 for me on Ubuntu 14.04:

# Note: replace xx:xx. in the rule with the MAC address of your Nic> $ sudo vim /etc/udev/rules.d/75-persistent-net-generator.rules SUBSYSTEM=="net", ACTION=="add", ATTR=="xx:xx:xx:xx:xx:xx", NAME="eth0" # Change "em1" to "eth0" in your interfaces file. $ sudo vim /etc/network/interfaces $ sudo reboot 

FYI, this was what I was originally seeing in logs:

$ sudo grep eth0 /var/log/dmesg [ 2.976463] e1000e 0000:00:19.0 eth0: registered PHC clock [ 3.003714] e1000e 0000:00:19.0 eth0: (PCI Express:2.5GT/s:Width x1) 18:03:73:e9:f2:36 [ 3.031177] e1000e 0000:00:19.0 eth0: Intel(R) PRO/1000 Network Connection [ 3.058399] e1000e 0000:00:19.0 eth0: MAC: 10, PHY: 11, PBA No: E041FF-0FF [ 3.153759] systemd-udevd[167]: renamed network interface eth0 to em1 

Looks like systemd-udevd was doing negative work and renaming eth0 to em1 in the first place. Not sure how to stop it from doing that, but renaming back to eth0 seems to work.

Источник

Changing Network Interfaces name Ubuntu 16.04

I tried to change network interfaces name on this new Ubuntu 16.04 LTS version but doesn’t have the /etc/udev/rules.d/70-persistent-net.rules . So, I tried to use /lib/udev/write_net_rules but it not exist. Why do I need this modification? Because I’m using a tool to Simulate virtual platforms that use flex licensing and the authentication need to be in eth0 interface name. Any suggestion? The command ip link returns:

user@laptop:~$ ip link 1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: enp6s0: mtu 1500 qdisc pfifo_fast state DOWN mode DEFAULT group default qlen 1000 link/ether b8:2a:xx:yy:xx:yy brd ff:ff:ff:ff:ff:ff 3: wlp7s0: mtu 1500 qdisc mq state UP mode DORMANT group default qlen 1000 link/ether 5c:e0:xx:yy:xx:yy brd ff:ff:ff:ff:ff:ff user@laptop:~$ ifconfig enp6s0 Link encap:Ethernet HWaddr b8:2a:xx:yy:xx:yy lo Link encap:Local Loopback wlp7s0 Link encap:Ethernet HWaddr 5c:e0:xx:yy:xx:yy 

4 Answers 4

There is a lot of misleading information about how to change network names in recent versions of Ubuntu. Some information points to systemd.link, which is just wrong because Ubuntu (as of 16.04) does not use this part of systemd.

Читайте также:  Установка kali virtual linux

Actually, changing interface name works nearly like it used to, with two small differences: First, the file /etc/udev/rules.d/70-persistent-net.rules now has to be created manually. This has the advantage that you do not have to worry about any script overwriting this file and can simply add the lines that you need (you do not need any comments either). Second — and this is the change that cost me a lot of time to figure it out — the format changed slightly compared to Ubuntu 14.04 LTS:

The line for fixing the interface name of the NIC with MAC address «02:01:02:03:04:05» to «eth0» is now:

SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR=="02:01:02:03:04:05", ATTR=="0x0", ATTR=="1", NAME="eth0" 

This line looks nearly the same as in Ubuntu 14.04 LTS with one slight difference: In Ubuntu 14.04, there was the additional condition KERNEL==»eth*» . For some reason, this does not work in Ubuntu 16.04 LTS. If this additional condition is present, the whole line is ignored and you are back to the default behavior (as specified in 80-net-setup-link.rules ).

Bingo! I now have enusb01 for my USB Docking Station’s NIC. Thanks! # USB Display Link Docking Station SUBSYSTEM==»net», ACTION==»add», DRIVERS==»?*», ATTR

==»8c:ae:4c:fa:92:bf», ATTR==»0x0″, ATTR==»1″, NAME=»enusb1″

How can I set the name to enp0s1 from enp0s17 ? Is it the same process ? Also, what should I do for virtual network-interfaces like enp0s1:1 or enp0s2 etc. ?

You don’t really need to specify all of that in 16.04. I was able to get away with SUBSYSTEM==»net», ACTION==»add», ATTR

==»xx:xx:xx:xx:xx:xx», NAME=»eth0″

@kbuilds, per Linux From Scratch: DRIVERS==»?*» — This exists so that Udev will ignore VLAN or bridge sub-interfaces (because these sub-interfaces do not have drivers). These sub-interfaces are skipped because the name that would be assigned would collide with their parent devices.

Important: you need to edit /etc/network/interfaces to make sure the renamed interface gets automatically started. Otherwise, if you’re on SSH — you will lose access to that machine, not to mention waste time trying to figure out why it doesn’t work.

On Ubuntu 16.04.1 LTS, Linux plaptop 4.4.0-31-genericx86_64 MATE. step one of @Geancarlo Abich answer and it worked. Ubuntu created a new names directly after reboot:

Edit your /etc/default/grub changing the line from

GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0" 
msa@plaptop:~$ ifconfig eth0 Link encap:Ethernet HWaddr 70:5a:0f:d7:03:38 inet addr:10.67.10.43 Bcast:10.67.10.255 Mask:255.255.255.0 inet6 addr: fe80::8c03:edb5:a3d1:ba21/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:63129 errors:0 dropped:0 overruns:0 frame:0 TX packets:37788 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:51115719 (51.1 MB) TX bytes:5006758 (5.0 MB) Interrupt:16 Memory:f1200000-f1220000 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:255 errors:0 dropped:0 overruns:0 frame:0 TX packets:255 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1 RX bytes:21076 (21.0 KB) TX bytes:21076 (21.0 KB) wlan0 Link encap:Ethernet HWaddr 44:85:00:62:c6:e5 inet addr:10.67.14.106 Bcast:10.67.14.255 Mask:255.255.255.0 inet6 addr: fe80::5844:f9dd:32ff:9b45/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:25 errors:0 dropped:0 overruns:0 frame:0 TX packets:86 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:5320 (5.3 KB) TX bytes:14611 (14.6 KB) 

Источник

Читайте также:  Планировщик ввода вывода linux

Persistently rename a Linux network interface without Udev / Reboot

I’ve come up with one reason to avoid udev: You’re bringing up a VM by cloning, on the first boot NICS have already been detected (named), you’ve got a couple of NICs and they came up in the wrong order. You need to rename them. You add the udev rules, but that’s just for the second boot. So you resort to the ip command. However now you have a set of udev rules that were never tested. How do you know they are right without rebooting? This is one edge-case where putting the ip commands in rc.local may be better.

3 Answers 3

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:

A reboot may be required to apply the name change.

Keep in mind that netplan is just talking to udev for you. And like many of Canonical’s other really bad ideas, netplan will likely go away. I wouldn’t put too much effort into learning it.

Likely go away ? I think it is the best replacement I have ever seen for configuration. It would be a shame. Especially that the learning curve is quite flat.

@MichaelHampton just curious — do you have a specific reason to say that Netplan is going away (like a thread in a mailing list), or just commentary on Canonical’s whimsy?

Knowing the ip command is nice, but there are persistent ways to configure using existing scripts, and yes, udev.

One thing you can dois map a NIC of a specific MAC address to a name. Append something like this to /etc/udev/rules.d/70-persistent-net.rules

SUBSYSTEM=="net", ACTION=="add", ATTR=="xx:xx:xx:xx:xx:xx", NAME="eth0" 

As of 2021 there is a move away from udev rules (although they still work fine) and a move towards doing it in systemd, to keep all the network configuration in one place.

Читайте также:  Линукс посмотреть таблицу маршрутизации

To set a persistent network device, create /etc/systemd/network/10-eth0.link with the following contents. The filename must start with a number and end with .link but the rest is not important and up to you. You need one file for each network interface you want to rename.

[Match] # This is the MAC address of the card to change. You can also # match against other properties like PCI/USB slot. MACAddress=00:11:22:33:44:55 [Link] # This is the name to assign. It must not conflict with any existing # device, so be careful if you use a name like eth0 which can fail # unexpectedly if you plug in another device that ends up on eth0 first. Name=lan0 # You can also change the MAC address at the same time if you like. # Make sure you follow the MAC address numbering rules or you can run # into problems, e.g. if you assign a broadcast MAC address by mistake. MACAddress=02:00:00:00:00:10 

At the time of writing systemd will not re-apply .link files once the system is up and running (even if you restart systemd-networkd ), so you’ll need to reboot in order to confirm it can apply the change successfully.

Источник

Change Network Interface Name: eth0,eth1,eth2+

The best way to rename a network interface is through udev .

Edit the file /etc/udev/rules.d/70-persistent-net.rules to change the interface name of a network device.

The names of the network devices are listed in this file as follows:

# PCI device 0x11ab:0x4363 (sky2) SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR=="00:00:00:00:00:00",ATTR=="0x0", ATTR=="1", KERNEL=="eth*", NAME="eth0"

Rename network interface from eth0 to wan0

To rename interface eth0 to wan0 , edit /etc/udev/rules.d/70-persistent-net.rules file and change NAME=»eth0″ to NAME=»wan0″ .

# PCI device 0x11ab:0x4363 (sky2) SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR=="00:00:00:00:00:00",ATTR=="0x0", ATTR=="1", KERNEL=="eth*", NAME="wan0"

For Centos/RHEL etc.

Rename the network interface configuration file:

# cd etc/sysconfig/network-scripts/ # mv ifcfg-eth0 ifcfg-wan0

Edit the network interface configuration file and replace all occurrences of the old name eth0 with the new one wan0 :

# vi /etc/sysconfig/network-scripts/ifcfg-wan0

For Ubuntu etc.

Edit the /etc/network/interfaces file and replace all occurrences of the old name eth0 with the new one wan0 :

# sudo nano /etc/network/interfaces

Test changes

Reboot the system to test changes:

Rename network interface from eth1 back to eth0

Q: Why does my network interface name change?
A: The interface name of a network device increases if the MAC address of a network card changes.

Edit the file /etc/udev/rules.d/70-persistent-net.rules .

Copy the new MAC address from eth1 to the line of your eth0 rule.

Delete the rule for eth1 . Save and close the file.

For Centos/RHEL etc.

Check the network interface configuration located under:

# vi /etc/sysconfig/network-scripts/ifcfg-eth0

Don’t forget to replace the old MAC address with the new one.

For Ubuntu etc.

Make sure /etc/network/interfaces file has correct configuration:

# sudo nano /etc/network/interfaces

Test changes

Reboot the system to test changes:

Источник

Оцените статью
Adblock
detector