Sorting of network interfaces

Hello everyone, I know this is probably a stupid question, but I would like to solve it.

How can I get the interfaces to line up one after the other … ie: vlan102, vlan103, vlan600 and vlan1000 ?

I came from Debian 11 and it sorts automatically there. I haven’t figured out a way to achieve this yet. Can someone advise me?

[root@router ~]# ip -4 a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    inet 10.107.x.x/30 brd 10.107.x.x scope global noprefixroute enp1s0
       valid_lft forever preferred_lft forever
5: vlan600@enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    inet 10.20.x.x/26 brd 10.20.x.x scope global noprefixroute vlan600
       valid_lft forever preferred_lft forever
6: vlan103@enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    inet 10.107.x.x/29 brd 10.107.x.x scope global noprefixroute vlan103
       valid_lft forever preferred_lft forever
7: vlan1000@enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    inet 10.123.x.x/29 brd 10.123.x.x scope global noprefixroute vlan1000
       valid_lft forever preferred_lft forever
8: vlan102@enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    inet 10.107.x.x/29 brd 10.107.x.x scope global noprefixroute vlan102
       valid_lft forever preferred_lft forever

Thanks

vecino

I’ve never even realized that there should/could be some order. Hence, no idea.

Furthermore, network configuration is by NetworkManager by default. While ip remains a useful “What do we have?”, the NM offers others. For example:

nmcli
nmcli c s
nmcli d s
nmcli d show

Is it possible that order is as the interfaces were created and that Debian creates them in “apparently sorted” order?

Debian ranks them in order. Even if I add the vlans differently, not consecutively.

Thanks for the tip on nmcli, it’s totally new to me. I will look at it.

[root@router ~]# nmcli d s
DEVICE    TYPE       STATE        CONNECTION 
enp1s0    ethernet   connected    enp1s0     
vlan1000  vlan       connected    vlan1000   
vlan600   vlan       connected    vlan600    
vlan102   vlan       connected    vlan102    
vlan103   vlan       connected    vlan103    
wg0       wireguard  connected    WireGuard  
enp2s0    ethernet   unavailable  --         
enp3s0    ethernet   unavailable  --         
lo        loopback   unmanaged    -- 

I don’t think there’s anywhere for NetworkManager to say in which order it should sort it, right?

There are /org/freedesktop/NetworkManager/Devices/1 - 9, but I don’t know if I can interfere in any way…

Dec 03 18:51:52 router NetworkManager[731]: <info>  [1670089912.4983] manager: (lo): new Generic device (/org/freedesktop/NetworkManager/Devices/1)
Dec 03 18:51:52 router NetworkManager[731]: <info>  [1670089912.5081] manager: (enp1s0): new Ethernet device (/org/freedesktop/NetworkManager/Devices/2)
Dec 03 18:51:52 router NetworkManager[731]: <info>  [1670089912.5123] device (enp1s0): state change: unmanaged -> unavailable (reason 'managed', sys-iface-state: 'external')
Dec 03 18:51:52 router NetworkManager[731]: <info>  [1670089912.5571] manager: (vlan600): new VLAN device (/org/freedesktop/NetworkManager/Devices/3)
Dec 03 18:51:52 router NetworkManager[731]: <info>  [1670089912.6871] device (vlan600): state change: unmanaged -> unavailable (reason 'managed', sys-iface-state: 'external')
Dec 03 18:51:52 router NetworkManager[731]: <info>  [1670089912.7185] manager: (vlan103): new VLAN device (/org/freedesktop/NetworkManager/Devices/4)
Dec 03 18:51:52 router NetworkManager[731]: <info>  [1670089912.7537] device (vlan103): state change: unmanaged -> unavailable (reason 'managed', sys-iface-state: 'external')
Dec 03 18:51:52 router NetworkManager[731]: <info>  [1670089912.7813] manager: (vlan1000): new VLAN device (/org/freedesktop/NetworkManager/Devices/5)
Dec 03 18:51:52 router NetworkManager[731]: <info>  [1670089912.7990] device (vlan1000): state change: unmanaged -> unavailable (reason 'managed', sys-iface-state: 'external')
Dec 03 18:51:52 router NetworkManager[731]: <info>  [1670089912.8135] manager: (vlan102): new VLAN device (/org/freedesktop/NetworkManager/Devices/6)
Dec 03 18:51:52 router NetworkManager[731]: <info>  [1670089912.8354] device (vlan102): state change: unmanaged -> unavailable (reason 'managed', sys-iface-state: 'external')
Dec 03 18:51:52 router NetworkManager[731]: <info>  [1670089912.8619] manager: (enp2s0): new Ethernet device (/org/freedesktop/NetworkManager/Devices/7)
Dec 03 18:51:52 router NetworkManager[731]: <info>  [1670089912.8661] device (enp2s0): state change: unmanaged -> unavailable (reason 'managed', sys-iface-state: 'external')
Dec 03 18:51:52 router NetworkManager[731]: <info>  [1670089912.9245] manager: (enp3s0): new Ethernet device (/org/freedesktop/NetworkManager/Devices/8)
Dec 03 18:51:52 router NetworkManager[731]: <info>  [1670089912.9284] device (enp3s0): state change: unmanaged -> unavailable (reason 'managed', sys-iface-state: 'external')
Dec 03 18:51:52 router NetworkManager[731]: <info>  [1670089912.9923] manager: (wg0): new WireGuard device (/org/freedesktop/NetworkManager/Devices/9)

I think you can try the brief option of ip command, then pipe through sort and play with its options, like:

ip -br addr show | sort
1 Like

Thanks for the tip - I’ll definitely try it.

Do you think the ordering is affected by udev or directly by NetworkManager? I would like to look at the source codes if it would be possible to modify it.

As far as I know, it’s the udev that decides the naming scheme. Because we don’t have problem with naming scheme here, but rather how to display it, I think we should look at or modify the command that does the display, i.e. “ip addr” command. But I’m not an expert on this so I might be wrong :slight_smile:

A friend of mine who is very experienced in Linux explained it to me:

The whole thing is created by ip addr ordering it according to ifIndex, which is created by how interfaces are added. Nmcli adds it all at once in parallel, the init script is loaded lined up - that’s why init runs nicely. The whole problem with init is that almost any change requires a reboot, which nmcli solves.

So it makes no sense to deal with it and it is better to reorient to NetworkManager / nmcli.

Hi, I found a solution: https://developer-old.gnome.org/NetworkManager/stable/settings-connection.html

autoconnect-priority
The autoconnect priority. If the connection is set to autoconnect, connections with higher priority will be preferred. Defaults to 0. The higher number means higher priority.

So, depending on how you want to sort the vlans, you can set, for example:

vlan100 = autoconnect-priority 100
vlan200 = autoconnect-priority 90
vlan300 = autoconnect-priority 80
etc

Yes, I know it’s probably stupid for you, but it made me happy. :slight_smile:

Haha, not at all. Thank you for sharing. Just curious, maybe you have OCD? I think I also have one, so I understand why you want things in a specific order :slight_smile:

What OCD? Damn, I have to go straighten the clothes in the closet again (last time I did it 5 minutes ago)… :joy:

I have, for example, more than 10 VLANs on one router … and thanks to this arrangement, it is much clearer for me.

Well, looks like you really have OCD. It’s obsessive compulsive disorder. You can search and read more about it. It’s nothing to worry about though. I’ve just recently realized that I may also have it because of the needs to check things over and over again :slight_smile:

I was joking of course. I didn’t mean it. It’s called humor. :smiley: