I have a setup with a bunch of vlan interfaces on a physical interface.

Physical interface: eth1
VLANS on top of this: vlan1, vlan2, vlan3

Now, I want to know which is the parent interface of my vlan (for example, here eth1 is the parent interface of these vlans).

I can get this information by running "ip addr show vlan-name" and then in output, I will get vlan1@eth1, but I need to parse the output of this command or by looking at my network config file, parsing it and interpreting it.

Is there another way by which I can get this information without any parsing logic? For example, for bonded interfaces, the information is present in /sys/class/net/ directory and one can simply read files there.

# cat /sys/class/net/bond0/bonding/slaves
eth0 eth1

Is there a similar path/file available for vlan tagged interfaces? I couldn't figure out if there is some file I can just read without any parsing and extract this information or any command/utility that just gives the parent interface name.

Kindly do let me know if there are other alternatives to this.



I didn't find a way without any parsing to get the underlying interface, so I give 4 (sometimes just slightly) different ways to get this information, I hope one will be handy.

There's a symlink having the name of the physical interface:

$ ls -l /sys/class/net/vlan2
lrwxrwxrwx. 1 root root 0 nov. 10 02:12 lower_eth1 -> ../eth1
-rw-r--r--. 1 root root 4096 nov. 10 01:49 uevent

Method 1

$ echo $(basename $(readlink /sys/class/net/vlan2/lower_*))

There's uevent that is handy too:

$ cat /sys/class/net/vlan2/uevent 
$ cat /sys/class/net/vlan2/lower_*/uevent

Method 2

$ cat /sys/class/net/vlan2/lower_*/uevent|sed -n 's/^INTERFACE=//p'

As root, there are entries in /proc/net/vlan:

# ls /proc/net/vlan/
config  vlan1  vlan2  vlan3  vlan4  vlan5
# cat /proc/net/vlan/config
VLAN Dev name    | VLAN ID
vlan1          | 1  | eth1
vlan3          | 3  | eth1
vlan4          | 4  | eth1
vlan2          | 2  | eth1
vlan5          | 5  | eth2

# cat /proc/net/vlan/vlan2
Device: eth1

Method 3

# awk -F ' *\\| *' '$1 == "vlan2" { print $3 }' /proc/net/vlan/config

Method 4

# sed -n 's/^Device: //p' /proc/net/vlan/vlan2

Note that in /sys the other direction is also possible with upper_*:

$ ls -l /sys/class/net/eth1


-rw-r--r--. 1 root root 4096 nov.  10 01:46 uevent
lrwxrwxrwx. 1 root root    0 nov.  10 02:23 upper_vlan1 -> ../vlan1
lrwxrwxrwx. 1 root root    0 nov.  10 02:18 upper_vlan2 -> ../vlan2
lrwxrwxrwx. 1 root root    0 nov.  10 02:23 upper_vlan3 -> ../vlan3
lrwxrwxrwx. 1 root root    0 nov.  10 02:23 upper_vlan4 -> ../vlan4

$ sed -n 's/^INTERFACE=//p' /sys/class/net/eth1/upper_*/uevent

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.