Hi, I am a new OpenWrt user and when I tried installing and configuring it, I found I am not quite clear about some basic concepts with interface.
For example, in /etc/config/network where the network configuration is written, we usually have configures like:
I searched the official docs and I think the term interface means a logical connector, and the term ifname means a physical device (If I am wrong, please point out.)
And here comes my questions:
what does a physical device really mean? a RJ45 port or something similar?
how does the interface map with the device? does one interface map with only one device?
does a physical device have one distinct IP address?
I appreciate if anyone could clarify these doubts, thank you.
SoHo routers often come with an additional switch, which just happens to live on the same PCB as the computer but is actually a separate device.
Option (a): Some of those boxes have a single eth0 iface (think rj45) available to the CPU, which is directly soldered to a port of the switch that is otherwise not externally exposed. The switch has 5 additional rj45 ports which are exposed. One of them is labeled as "wan", the others as "lan1-4". In this case, the included switch is a 6-port switch (CPU + WAN + 4 x LAN).
Option (b): Some of those boxes have two ifaces (eth0 and eth1). One of them is exposed externally as a rj45 port labeled as "WAN", the other one is soldered to the switch. In this case, the included switch is a 5-port switch (CPU + 4x LAN).
So you can think of every iface a rj45 port, but not every rj45 port you see on the outside of the box is actually an iface and not every face has a physical rj45 port available.
And if we really want to split hairs, there's even e.g. a "loopback device" which behaves as physical but is not, and there's something like PPPoE, which is not physical either.
If we're going vlans, you could use "eth0.1" as ifname, which means you want the vlan ID 1 of your physical device eth0. That was the way of configuring networks before the "distributed switch architecture" became a thing. Nowadays, there's one more layer of abstraction (the DSA), but the concept still applies.
So ... it's complicated
As for the third question: No, the IP address isn't assigned to the physical thing ("ifname") but to a virtual one. Sometimes even only to a fraction of that.
You can have one "interface" with ifname set to "eth0" as "wan" (for simplicity, I'm not describing DSA here) configured as "proto dhcp". That one will ask for an IPv4 address via DHCP.
And you can have another "interface" that has its interfaces set to "@wan" and its "proto dhcp6". That one will ask for an IPv6 address via DHCP.
Internally, both "interfaces" will be bound to the very same physical device, "eth0".
As for vlans: Your router usually has one IPv4 address on its "lan vlan" (eth0.1, without DSA) and another IPv4 address on its "wan vlan" (eth0.2, again without DSA). That's once again the same physical interface on your CPU, but it has two different IP addresses and is even exposed as different rj45 ports.
You may want to read up here:
But the thing not described: When it comes to OpenWRT ifnames, we always talk about "physical or virtual devices as part of the CPU board", more or less. They are not to be mixed up with the rj45 ports visible on the outside of your box, which are usually only a managed switch glued and soldered to your CPU board but need to be viewed as a different device.
Your example is from a very old version. The syntax of defining interfaces has changed.
option ifname has been replaced by option device to point to a single physical (or virtual) device. This also clarifies the distinction between interfaces and devices.
Bridges are now declared in a separate block as virtual devices. This is how an interface can link to more than one physical device at layer 2. See the config device br-lan which is default in newer configurations.
option _orig_* is a vestige of the how the old Luci system processed change reversion. These lines do not affect the configuration at all.
option netmask and option broadcast are deprecated in favor of CIDR notation within the ipaddr setting, i.e. option ipaddr '192.168.31.1/24'
So in sum, can I understand that interface could be either physical or virtual? And any connected interface has one distinct IP address?
BTW I have another doubt which is about the Network Interface Controller(NIC). what I mean by NIC is the device like this:
As you can see, this device has two RJ 45 ports, as for IP address, I am prertty sure that these two ports have different IP address, but when it comes to MAC address, do they share a same MAC address? I saw from internet that someone says that their MAC are different, but when I test it on my own computer which has a NIC like this, both the two share same MAC address
It may have none (proto=none), it indirectly may have several (e.g. via alias interfaces; but that needs very special care not to mess up routing). The only thing that mustn't happen, is having overlapping=conflicting IP ranges on different interfaces.
I don't see 2 RJ-45 ports. I see 2 SFP (Small Form-factor Pluggable) ports. Not sure if there was a difference as it relates to your topic - but just wanted to clarify.
Multi port NIC cards should have different MAC addresses for each port. They are usually consecutively numbered at the factory. Of course you can override to a different MAC in the configuration.
Even though they are built on the same card, the kernel sees each port as a completely separate Ethernet device and will give each one a separate name such as eth1 and eth2. In order to have both ports in the same Interface network, create a bridge in software.