I am really confused about "device" and "interface" concepts

After days of studying, I got more confused about "device" and "interface" concepts. I found some explanations about the network configuration seems to be contradicted in these two concepts:

  1. /sys/class/net
    From sysfs man page, this file represents networking devices:

Thus, I listed all the networking devices of my openwrt(phicomm n1 as host) as follows:

  1. ipconfig command
    From ifconfig(8) - Linux manual page (man7.org), ipconfig command displays the status of the currently active interfaces:
    image
    By executing ipconfig -a command, I listed all interfaces:
root@OpenWrt:~# ifconfig -a
docker0   Link encap:Ethernet  HWaddr 02:42:7A:4F:68:6C  
          inet addr:172.31.0.1  Bcast:172.31.0.255  Mask:255.255.255.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

dummy0    Link encap:Ethernet  HWaddr E2:E0:32:72:28:DA  
          BROADCAST NOARP  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

erspan0   Link encap:Ethernet  HWaddr 00:00:00:00:00:00  
          BROADCAST MULTICAST  MTU:1450  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

eth0      Link encap:Ethernet  HWaddr FC:7C:02:E9:6A:53  
          inet addr:192.168.31.3  Bcast:192.168.31.255  Mask:255.255.255.0
          inet6 addr: fe80::fe7c:2ff:fee9:6a53/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:5263667 errors:0 dropped:5 overruns:0 frame:0
          TX packets:4156935 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:3277095525 (3.0 GiB)  TX bytes:2835687763 (2.6 GiB)
          Interrupt:30 

gre0      Link encap:UNSPEC  HWaddr 00-00-00-00-FF-00-00-00-00-00-00-00-00-00-00-00  
          NOARP  MTU:1476  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

gretap0   Link encap:Ethernet  HWaddr 00:00:00:00:00:00  
          BROADCAST MULTICAST  MTU:1462  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

ip6tnl0   Link encap:UNSPEC  HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00  
          NOARP  MTU:1452  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

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:897389 errors:0 dropped:0 overruns:0 frame:0
          TX packets:897389 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:404757065 (386.0 MiB)  TX bytes:404757065 (386.0 MiB)

sit0      Link encap:IPv6-in-IPv4  
          NOARP  MTU:1480  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

wlan0     Link encap:Ethernet  HWaddr FC:7C:02:E9:6A:52  
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:41 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:9322 (9.1 KiB)

As you can see, all these "interfaces " are actually "devices" in /sys/class/net file.
Also, the above interfaces contradicts with the configuration webpage of interface:


From this screenshot, the interfaces are VPN0, DOCKER, VPN, LAN, while docker0, etho, etc. are actually devices.

So how do we tell from device and interface? I saw that some one said that device is layer2 and interface is layer3, is that correct? and if so, how is the relationship between layer2 and layer3, can they be mapped randomly ?
I appreciate that you can clear my doubts. Thank you

OpenWrt interfaces are logical networks which utilize one or more devices. Devices in OpenWrt terminology are Linux kernel netdevs, such as eth0 etc.

Linux itself uses the term interface and device interchangeably when referring to netdevs.

1 Like

but device can also either be logical or physical, correct?

With openwrt this statement is correct. In the network settings you have to configure layer2 settings on a device while layer3 settings need to be configured on an interface. The reasoning are based on concepts and implementation on Openwrt.
In general... Have a look at the traditional osi layer architecture.
You start with layer 1 which is a link. Like a cable. Let it be cooper or fiber...
Layer 2 is data, with tcp/IP we will see frames. Mac addresses are used to address and deliver.
And on a single layer2 you can have multiple layer3 IP networks. Normally/commonly you will only see only a single layer3 network but technical this is no limitations.
Also, vlans take place on layer2. So on a single link (layer1) you can run multiple virtual lan (layer-2).

If you for instance use just the ip command from iproute2 you can configure layer-2 and layer-3 on a netdev. On tradition Linux distributions you can also configure layer-2 and layer-3 "directly" but Openwrt needs to separate this. I know jow explained this already hundreds of times but maybe he can loose a few words again :sweat:

2 Likes

Yes, there's physical netdevs such as eth0, eth1 which correspond to actual rj45 ports on your system. But there might also be logical or software defined "devices" such as "tun0", "br-lan" etc. which are software abstractions modeled after physical devices. From an OpenWrt configuration pov, those logical or software netdevs are still "devices" though.

1 Like

Thank you. So in my last screenshot can I say that VPN0, DOCKER, VPN, LAN are openwrt interfaces(layer 3) and ipsec0, docker0, eth0, tun0 are openwrt devices?(layer2)?

1 Like

Yes, this sounds correct.

2 Likes