How to Create VLANs on Trunk and Access Interfaces

I want to create the following scenario in which I want to receive on a trunk port two vlans 10 and 20 that will be data service and the other video service and exit through 2 access ports for vlan 10 and 20, on the other side I have a mikrotik which has the vlans created and sends it through a trunk port.

Usually this is super easy.

Please connect to your OpenWrt device using ssh and copy the output of the following commands and post it here using the "Preformatted text </> " button:
grafik
Remember to redact passwords, MAC addresses and any public IP addresses you may have:

ubus call system board
cat /etc/config/network

I haven't configured the router yet but that is the complete scenario and the script output:

root@OpenWrt:~# cat /etc/config/network

config interface 'loopback'
        option ifname 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config globals 'globals'
        option ula_prefix 'fd22:a979:dd9d::/48'

config interface 'lan'
        option type 'bridge'
        option ifname 'eth0.1'
        option proto 'static'
        option ipaddr '192.168.1.1'
        option netmask '255.255.255.0'
        option ip6assign '60'

config interface 'wan'
        option ifname 'eth1'
        option proto 'dhcp'

config interface 'wan6'
        option ifname 'eth1'
        option proto 'dhcpv6'

config switch
        option name 'switch0'
        option reset '1'

config switch_vlan
        option device 'switch0'
        option vlan '1'
        option ports '0t 1 2 3 4'
        option vid '1'

What device is this?

ubus call system board

It is a TPLINK 841ND router and has openWRT loaded:
OpenWrt 18.06.9 r8077-7cbbab7246 / LuCI openwrt-18.06 branch (git-20.319.49209-ab22243)

On this hardware, the blue WAN port is a direct path to the CPU (as eth1) it does not go through the switch. You probably want to use one of the yellow lan ports as the trunk port in order to take advantage of fast hardware switching between the trunk and the access ports. Here I will use #4. To configure the router, your PC should be plugged into #3, which will remain in the default VLAN 1 which is the router's LAN.

A trunk port is tagged (t) in all VLANs of interest, while an access port is untagged in only one vlan, and not present in the others. With that in mind, build out the switch configuration like this:

config switch_vlan
        option device 'switch0'
        option vlan '1'
        option ports '0t 3'
        option vid '1'

config switch_vlan
        option device 'switch0'
        option vlan '2'
        option ports '0t 1 4t'
        option vid '10'

config switch_vlan
        option device 'switch0'
        option vlan '3'
        option ports '0t 2 4t'
        option vid '20'

Note the following:

  • I have removed ports 1,2, and 4 from the default VLAN 1.
  • This hardware requires splitting vlan and vid to use VLAN tags above 16. Only 16 unique VLANs can exist in the switch, but each can have a 802.11q tag number from 1-4094.
  • VLANs 10 and 20 are available to the CPU as eth0.10 and eth0.20 if you want to attach them to software networks inside the router. Presently they are only hardware switched between the external ports.
  • The blue wan port remains associated with the default wan network which you probably won't be using. However you could instead assign it to a software bridge and even VLAN tag it if you wanted to.
1 Like

thank you very much you can do it now