6

Is there a way to name a VLAN interface arbitrarily like eth72 or ext19 instead of the four standard nameing schemes eth0.72, vlan19 (and the padded variations)?

Don't have no clue. Perhaps udev?

Michuelnik
  • 3,410
  • 3
  • 19
  • 24
  • Sure, udev can do that. – Skaperen Sep 05 '12 at 16:11
  • @boburob: I have three "upstream" nets - one comes in physically and two via VLANs on another Link. For sake of clarity I want to rename them all to ext0, ext1 and ext2. – Michuelnik Sep 05 '12 at 16:43
  • This is very likely to confuse anybody who ever has to touch that box in the future. We are _professionals_ here and we assume you are too. Don't confuse your colleagues. – Michael Hampton Sep 05 '12 at 19:14
  • @MichaelHampton: Actual, this _wish_ came from my colleagues - where I have been denying their request. – Michuelnik Sep 05 '12 at 19:31
  • @MichaelHampton I rename all the interfaces on my BSD boxen so that they're meaningful, like `lan0` and `wan0`. I'm genuinely stunned Linux has no easy way to do this. – Chris S Sep 05 '12 at 23:27
  • Well that's BSD; it has such bizarre default names for interfaces that renaming them is pretty much mandatory. – Michael Hampton Sep 05 '12 at 23:28
  • 1
    @ChrisS I have been stunned, too. But there _is_ an easy way to do this - simply `ip link set name`... – Michuelnik Sep 27 '12 at 08:04

7 Answers7

8

OMG - it's that easy:

Rename vlan 42 on eth0 to ext2:

ip link set dev eth0.42 name ext2

Michuelnik
  • 3,410
  • 3
  • 19
  • 24
  • Assuming you don't want it to persist past the next reboot, this is the correct answer. If you do want it to persist, the appropriate way would be udev rules, systemd-network configuration, or your distribution's specific network configuration files. – jbg Mar 27 '17 at 09:20
4

I didn't have luck with "ip link set dev bond0.10 name ext0". If the interface is up, it gets a BUSY error. If the interface is down, it gets a NOT FOUND error.

What I did have luck with is this: in my base interface definition for bond0,

post-up ip link add name ext0 link bond0 type vlan id 10
pre-down ip link delete dev ext0 type vlan

and

auto ext0
iface ext0 inet static
    address ...

Now I find that "ifup bond0" not only creates the VLAN as seen in /proc/net/vlan/config and creates the ext0 device, but it even ifup's the ext0 device. bond0.10 never comes into existence.

Curt
  • 191
  • 1
  • 6
3

In OpenBSD (and presumably other BSDs) you can set a description of an interface with ifconfig using the aptly named description argument, see ifconfig(8). This is very handy for distinguishing between a bunch of interfaces. But that doesn't help you.

Unfortunately there's no great way to do this in Linux.

In Linux, interfaces are named dynamically with each interface being assigned the first available name. This means that if you pull a NIC and then add another one (say to replace it or upgrade it) there is no guarantee that its interface will remain the same.

Try a program like ifrename which will allow you to manually specify the interface names. It looks primarily designed to assure that NIC0 is always associated with eth0 but I believe you can use it assign names like external and dmz to interfaces instead of eth0 and so on. Udev will also allow you to change interface names using the network.rules file (see here for an examples).

You should be careful to document this as it is not typically done but unlike @MichealHampton I don't see any particular problem with it. I personally make great use of the description field for interfaces in my BSD installs.

  • On all BSDs: `-description` actually takes the description off an interface, `description` or `descr` followed by the quoted text puts it on an interface. Also, you can easily rename interfaces with the `name` command to `ifconfig`. – Chris S Sep 05 '12 at 23:29
  • @ChrisS: Ahh thanks! Edited my answer for correctness. –  Sep 06 '12 at 01:04
  • Unfortunately ifrename won't work here (I guess!) since it's using the MAC addr to distinguish interfaces and the VLAN-IFs of an ethernet inherit it's MAC.... Same applies to udev if only the MAC can be used as distinguisher. Maybe the full device path? – Michuelnik Sep 06 '12 at 06:51
  • To your pull-replace-nic-part: atm it's mostly guarenteed, that the interface will NOT remain the same since $most dists are using mac-based dynamically learned fixed interface names. (-> _70-persistent-net.rules_) Understood udev so far, but cant get the step to VLAN interfaces there.... – Michuelnik Sep 06 '12 at 06:59
1

In debian you use /etc/network/interfaces to configure your network interfaces.

Be aware that you should install the vlan package:

apt-get install vlan

From man 5 interfaces:

To ease the configuration of VLAN interfaces, interfaces having . (full stop character) in the name are configured as 802.1q tagged virtual LAN interface.

For example, interface eth0.1 is a virtual interface having eth0 as physical link, with VLAN ID 1.

For more information check man 5 vlan-interfaces. Basically, you can give your vlan interface any name, and use vlan-raw-device to associate the vlan with your NIC. For instance, vlan10 on eth0 would be:

iface vlan10 inet static
    vlan-raw-device eth0
    address 192.168.10.1
    netmask 255.255.255.0

On non-debian distros, you can do this same thing with iproute2 as follows:

ip link add link enp3s0f1 name vlan10 type vlan id 10
ip addr add 192.168.10.1/24 dev vlan10
GnP
  • 955
  • 8
  • 15
1

So this works well.

in /etc/network/interfaces:

auto lxdHost
iface lxdHost static
   pre-up ip link add link eth0 name lxdHost type vlan id 102
   address 192.1.1.1/25
   ...

then ifup lxdHost

pre-up and post-down and the others in intefaces man are the magic hooks to do things your own way.

0

Not sure if this also applies to Debian, but in Ubuntu (and Red Hat), this is easily done by editing /etc/udev/rules.d/persistent-net.rules (or similar; I'm not in a position to check)

Renaming interfaces has some useful advantages:

  • assigns known semantics to an interface (eg. 'management0', 'front0', 'back0')
  • having a predictable name makes it easier for configuration management scripts etc to work well (esp. Firewall rules)

You do need to make sure that your team knows to expect this. That's not a problem, it's generally very welcome, particularly when you have many interfaces in a system (eth8 is not unreasonable in an host with redundant bonded links to SAN storage)

Having discussed this recently, if you wanted to rename based on VLAN ID, I would suggest that you consider the following:

  • VLAN IDs are not all that memorable and easily mistyped and looked over.
  • a host generally has no simple way to determine which VLAN (if any) it is on, or it if is the native VLAN, and an access or trunk port (doing this manually from the host is sometimes doable if you tcpdump for CDP messages or know what traffic maps to which VLAN). Thus, the configuration is one based on belief, which can easily become invalid.
Cameron Kerr
  • 4,069
  • 19
  • 25
0

Using nmcli on RedHat/CentOS/SL 7 you have system-supported persistent arbitrary namig for VLAN interfaces, just:

$ nmcli con add type vlan ifname outside dev eno1 id 10

Veniamin
  • 863
  • 6
  • 11