VLan in OpenWrt 22.03.0-2

hello, excuse my ignorance, I'm using openwrt 22.03.0-2 and I would like to use the VLan from the command line, but I can't in any way. I have the WAN configuration on eth1 and eth0 and eth2 with the PCs, I would like to create vlans on these two ports, how can I? thanks in advance to whoever helps me

You actually already have WAN on VLAN2 and the other LAN ports on VLAN1 as default setup.

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

config globals 'globals'
        option ula_prefix 'fdce:cf38:4bbe::/48'

config device
        option name 'br-lan'
        option type 'bridge'
        list ports 'eth0'

config interface 'lan'
        option device 'br-lan'
        option proto 'static'
        option ipaddr '192.168.1.1'
        option netmask '255.255.255.0'
        option ip6assign '60'

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

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

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

config switch_vlan
        option device 'switch0'
        option vlan '2'
        option ports '1t 2t'

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

i have this in /etc/config/network

what if i want to add vlan?
I'm following the documentation, but I have no results

That isn’t a DSA config. What device do you have?

Is that setup default or have you changed anything?

Which documentation, officially we have both dsa and swconfig setup?
And on top of that all unofficial doc online.

I'am on GNS3 i dont have device.
This is doc "https://openwrt.org/docs/guide-user/network/vlan/switch_configuration"

and this is default setup:


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

config globals 'globals'
        option ula_prefix 'fdd9:2a0b:c4d6::/48'

config device
        option name 'br-lan'
        option type 'bridge'
        list ports 'eth0'

config interface 'lan'
        option device 'br-lan'
        option proto 'static'
        option ipaddr '192.168.1.1'
        option netmask '255.255.255.0'
        option ip6assign '60'

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

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

i have no idea what i must to do for create a vlan, i tryed but didt work

Do we even support GNS3 or is it this one you have downloaded?
https://www.gns3.com/marketplace/appliances/openwrt-2

please read the guide again and use the DSA syntax only.

"GNS3" appears to be a virtualization system. On a VM installation the ports are direct access like an x86 with separate hardware ports. There is no switch. The OpenWrt configuration to send and receive VLAN tagged packets is simply to add a VLAN number to the port name, such as option device 'eth0.10', or in a bridge, list ports eth0.10. Once a port has been set up with a VLAN, all uses of it should be tagged; don't leave a plain eth0 anywhere in the configuration.

Networking then has to be set up in the hypervisor (GNS3) executive to pass these tagged virtual packets to actual network destinations. This can be complicated, and is outside the scope of this forum. Generally rather then VLAN tagging virtual ports, one would simply add additional separate virtual ports for each network going in or out of the VM, and handle any external tagging needs in the hypervisor setup.

I downloaded what you mentioned

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

config globals 'globals'
        option ula_prefix 'fdfc:efa5:cc90::/48'

config device
        option name 'br-lan'
        option type 'bridge'
        list ports 'eth0'
        list ports 'eth2'

config interface lan
        option device 'br-lan.99'
        option proto 'static'
        option ipaddr '192.168.1.1'
        option netmask '255.255.255.0'

config bridge-vlan
        option device 'br-lan'
        option vlan '4'
        list ports 'lan0:t'
        list ports 'lan3:t'

config bridge-vlan
        option device 'br-lan'
        option van '99'
        list ports 'lan0:t'
        list ports 'lan1:u*'

config interface 'guest'
        option proto 'static'
        option device 'br-lan.4'
        option ipaddr '192.168.4.1'
        option netmask '255.255.255.0'


config interface 'office'
        option device 'office'
        option proto 'static'
        option ipaddr '192.168.3.1'
        option netmask '255.255.255.0'

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


I followed the dsa guide, but the vlans don't work, from an end point if I ping the gateway or try to ping, nothing else works

yes it does not work as you followed the guide by letter and not adopt to your environment.

in a plastic router there is usually a wan port and a switch (in various combination), but in x86 ports are individually bind to a network device. they are eth0,eth1 etc. even if they are named as lan0, lan1 definitely you cannot mix witj ethX as you do in your config

log in to your owrt, and run ip link command to verify the device names. if they are eth0, eth1 then only use those in your config. or vice versa if they are called lan0, lan1 (but i doubt) use only those.

as @mk24 suggested it is better to use dedicated virtual networks instead of vlan in a virtualized environment, i guess you can say in GNS3 too that your owrt guest has 1,2,3,4 network interfaces, right, so you can use them as different networks without vlan tagging.

but if you want to learn vlans, first you need to check your guest (=owrt) devices names and use them accordingly.