On Ubuntu 16.04 server I'd like to have another name for eth0, for example.
-
1Do you want another name or do you want to [add another IP to it](https://askubuntu.com/questions/585468/how-do-i-add-an-additional-ip-address-to-an-interface-in-ubuntu-14)? – muru Sep 11 '17 at 06:17
-
@muru, another name. – Velkan Sep 11 '17 at 06:26
-
Maybe try https://unix.stackexchange.com/a/367889/70524? – muru Sep 11 '17 at 06:28
-
@muru, as an the actual solution I'll probably leave some comments in my iptables rules to then grep for the comment to get the right interface name. – Velkan Sep 11 '17 at 06:57
-
Try [this](http://ask.xmodulo.com/change-network-interface-name-centos7.html) for an udev name rule. `/etc/udev/rules.d/70-persistent-net.rules` – jc__ Sep 11 '17 at 15:05
-
What is the use you have in mind? – vonbrand Feb 22 '20 at 18:53
-
@vonbrand I think I wanted to make some old config files and documentation be compatible with the new system that adds better names. I've ended up writing scripts and daemons to convert the configs. – Velkan Feb 27 '20 at 19:49
5 Answers
You might want to take a look at the new iproute2 network interface alternative name feature (ip link altname). Note that the command syntax seems to have changed since that article. For example:
ip link property add dev eth0 altname someothername
Note that this is very new, you will need a recent version of iproute2 for it to work (v5.4.0 which came out on 2019-11-25, if I'm reading the git log right).
- 361
- 2
- 4
-
2
-
1@Haris Just like every other `ip` command, the answer is no. You will have to persist the config using your mechanism of choice. – Etienne Dechamps Aug 31 '20 at 21:36
-
@EtienneDechamps do you have any suggestions on what mechanisms to use to get the altname to persist across reboots? i am failing to figure this out for any tool which seems like it might be capable of doing so (network-scripts, udev, systemd-networkd, NetworkManager, etc.) – jayhendren Mar 17 '23 at 22:50
From man ip-link:
alias NAME give the device a symbolic name for easy reference.
Example giving an alias to the lo interface:
$ sudo ip link set lo alias mycustomaliasforlo
$ ip link show lo
1: lo: <LOOPBACK,UP,LOWER_UP> 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
alias mycustomaliasforlo
However, note that this only creates a symbolic reference, meaning you cannot use this alias as a real device name. For example, the following will fail:
$ ip link show mycustomaliasforlo
Device "mycustomaliasforlo" does not exist.
- 1,934
- 1
- 15
- 28
Changing the nic name on Ubuntu 16 by reverting to udev rules.
Software: Fresh install of Ubuntu 16.04.3 server with sshd in virtual machine. Not updated
How I got here:
Could not get any of the systemd instructions to work. I looks like systemd is being used, but no joy
network-manager is not installed, so no interference from it.
Step 1:
Stop systemd's Predictable Network Interface Names thingy by adding net.ifnames=0 to kernel command line.
sudo vi /etc/default/grub
GRUB_CMDLINE_LINUX="net.ifnames=0"
update grub with new info:
sudo grub-mkconfig -o /boot/grub/grub.cfg
note:
I have seen where the value biosdevname=0 was added to the kernel command line in addition to net.ifnames=0. This setup did not require it.
Step 2:
Assign a new name using udev rules by creating a new rule file.
sudo vi /etc/udev/rules.d/10-myCustom-net.rules
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:f3:79:59", KERNEL=="eth*", NAME="test0"
adjust the MAC address and name for your system.
note:
Removed ATTR{dev_id}=="0x0" and ATTR{type}=="1" from my Ubuntu 14 template.
Some say to remove KERNEL=="eth*" or the entire line is ignored. This was not the case in this setup.
If you 'lose' the MAC address like I did because I rebooted before this step, does not show with ifconfig, go find it in /sys/class/net/assignedName/address. BTW: this system renamed it eth0, cat /sys/class/net/eth0/address
/etc/udev/rules.d/70-persistent-net.rules was the file automatically created in <= Ubuntu 14.
Step 3:
Assign the new interface name an address
sudo vi /etc/network/interfaces
auto test0
iface test0 inet static
address 192.168.2.202
netmask 255.255.255.0
Step 4:
reboot (its just easier for most of us)
As always verify all file locations for your system before executing any commands.
- 2,485
- 1
- 16
- 22
You can rename the NIC "label" this way on /etc/network/interfaces
rename ens21=niclan
auto niclan
iface niclan inet static
address 192.168.1.200
netmask 255.255.255.0
- 21,637
- 21
- 47
- 71
The net-tools methode:
You can add a network alias to your eth0 interface:
ifconfig eth0:0 192.168.1.200 up
Verify it ifconfig:
eth0:0: flags=-28669<UP,BROADCAST,MULTICAST,DYNAMIC> mtu 1500
inet 192.168.1.200 netmask 255.255.255.0 broadcast 192.168.1.255
ether 34:07:cc:6f:82:5f txqueuelen 1000 (Ethernet)
You can configure the eth0:0 on your /etc/network/interfaces:
auto eth0:0
allow-hotplug eth0:0
iface eth0:0 inet static
address 192.168.1.200
netmask 255.255.255.0
Do not add a "gateway" or a "dns-nameservers"
The iproute2 method on debian wiki
- 63,407
- 31
- 131
- 192
-
Isn't that just the old way to add several IP addresses to a single interface? With `ip`, those interfaces won't show up, instead it will just list all the addresses. – dirkt Sep 11 '17 at 17:50