Associate a VLAN to a VPN while others remain with normal access

Hello,

By using the OpenWRT VLAN and VPN functionality, I’m trying to associate a VLAN to a VPN network, but I’m missing something. I suspect it should be somewhere in the firewall configuration. I’ve tried so many things that I’m not sure anymore.

Basically I'm trying to configure OpenWRT so that devices from a specific VLAN could access Internet through the VPN tunnel while the devices from the other VLANs could access the internet from the current (normal) access.

Firstly, my current OpenWRT setup:
I have an ISP router connected to my OpenWRT router. The LAN behind the ISP router is connected to OpenWRT’s WAN port, so I’m calling it “WAN”.

I’m calling “LAN” to the LAN behind the OpenWRT router. VLAN1 is the VLAN for “LAN” and VLAN2 is the VLAN for “WAN”.

Each VLAN is associated to its own WIFI SSID and both receive IPs from OpenWRT DHCP server, depending on the pool configured for each.

Some ports of the OpenWRT router are dedicated to VLAN1 and others are dedicated to VLAN2. Other port is a trunk port (link where VLANs traffic goes tagged), which is connected to a managed switch.

In the switch I have configured some ports to be VLAN1 ports and other ports to be VLAN2 ports.

In other words: If I connect a device to any VLAN1 port (or VLAN1 SSID), it will get an IP from VLAN1 pool and if I connect to any VLAN2 port (of VLAN2 SSID) it will get an IP from the VLAN2 pool.

VLAN1 can access VLAN2 but the opposite isn’t allowed.

This is working happily for some time now. I got it working with the help of @vgaetera in this thread.

Now, I have configured access to a VPN provider from the OpenWRT router. When connected, the router creates a TUN device and I’m able to get an IP from the VPN provider.
When the VPN is up and running, I’m able to ping servers on the internet from the router, but the devices from VLAN1 and VLAN2 loose internet connectivity (it must be something in the firewall), but that’s kind of fine, because I don’t want all my traffic to go through that tunnel: I’d like to create a 3rd VLAN that is associated to this VPN and only devices from this VLAN will be able to go through the VPN.

So basically, this would be a 3rd VLAN (also with its own dedicated SSID, BTW) where its traffic goes only through the VPN while the VLAN1 and VLAN2 should continue as before. The traffic from the 3rd VLAN shouldn’t reach either VLAN1 or VLAN2 but VLAN2 should be able to reach VLAN3.

What I've done so far:
I’ve created a new bridge and a new interface, dedicated to the new VLAN.
I’ve created a new sub-radio (new SSID) and associated it to the bridge.
I’ve added the DHCP configuration for the new VLAN.
I’ve created a new FW zone.
I’ve added a rule where the traffic from the new VLAN should reach OpenWRT “device”, so dhcpd could assign IPs to this VLAN as well.

What is the current behaviour:
If I connect a WIFI device to the new SSID, it will get an IP from the correct pool. However, it will not have access to the internet, even if the VPN is up (must be something missing in the firewall, but don't know exactly what).
If I connect a wired device to a port that is associated to the 3rd VLAN, I can’t get nothing. Even if I manually assign an IP from the correct network, it will not ping the OpenWRT router. I’ve reviewed the switch configuration several times, so I’m not sure it would be a switch issue or OpenWRT misconfiguration.

Soooo... Any brave expert would be able to point me in the right direction? :smiley:

Router details:

Linksys EA8500 WiFi Router
ARMv7 Processor rev 0 (v7l)
OpenWrt 19.07.3 r11063-85e04e9f46 / LuCI openwrt-19.07 branch git-20.136.49537-fb2f363
4.14.180

Bridge config:

root@mojito:/etc/config# brctl show
bridge name     bridge id               STP enabled     interfaces
br-lan          7fff.58ef6858cf9d       no              eth0.1
                                                        wlan0
br-toxic                7fff.58ef6858cfab       no              eth0
                                                        wlan0-2
br-wan          7fff.58ef6858cfaa       no              eth0.2
                                                        wlan0-1
root@mojito:/etc/config#

Network Config:

root@mojito:/etc/config# cat 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 'xxxx:xxxx:xxxx::/48'

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

config device 'lan_dev'
        option name 'eth0.1'
        option macaddr '58:ef:68:58:xx:xx'

config interface 'wan'
        option ifname 'eth0.2'
        option proto 'static'
        option netmask '255.255.255.0'
        option type 'bridge'
        option igmp_snooping '1'
        option ipaddr '192.168.9.2'
        option gateway '192.168.9.1'
        list dns '8.8.8.8'
        list dns '192.168.9.1'

config device 'wan_dev'
        option name 'eth0.2'
        option macaddr '58:ef:68:58:xx:xx'

config interface 'wan6'
        option ifname 'eth0.2'
        option proto 'dhcpv6'
        option auto '0'

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

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

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

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

config interface 'toxic'
        option proto 'static'
        option netmask '255.255.255.0'
        option type 'bridge'
        option igmp_snooping '1'
        option ipaddr '192.168.99.1'
        list dns '8.8.8.8'
        list dns '192.168.99.1'
        option ifname 'eth0'

config device 'toxic_dev'
        option name 'eth0.99'
        option macaddr '58:ef:68:58:xx:xb'

config interface 'tun1'
        option proto 'none'

Firewall Config:

root@mojito:/etc/config# cat firewall

config defaults
        option syn_flood '1'
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'REJECT'

config zone 'lan'
        option name 'lan'
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'ACCEPT'
        list device 'tun0'
        list device 'tun+'
        option network 'lan'

config zone 'wan'
        option name 'wan'
        option input 'REJECT'
        option output 'ACCEPT'
        option forward 'REJECT'
        option masq '1'
        option mtu_fix '1'
        option network 'wan wan6'

config forwarding 'lan_wan'
        option src 'lan'
        option dest 'wan'

config rule
        option name 'Allow-DHCP-Renew'
        option src 'wan'
        option proto 'udp'
        option dest_port '68'
        option target 'ACCEPT'
        option family 'ipv4'

config rule
        option dest_port '22'
        option src 'wan'
        option name 'Allow SSH'
        option target 'ACCEPT'
        option family 'ipv4'
        list proto 'tcp'
        list dest_ip '192.168.9.2'

config rule
        option dest_port '67'
        option src 'wan'
        option name 'DHCP-Server'
        option family 'ipv4'
        option target 'ACCEPT'
        list proto 'udp'

config rule
        option name 'Allow-Ping'
        option src 'wan'
        option proto 'icmp'
        option icmp_type 'echo-request'
        option family 'ipv4'
        option target 'ACCEPT'

config rule
        option name 'Allow-IGMP'
        option src 'wan'
        option proto 'igmp'
        option family 'ipv4'
        option target 'ACCEPT'

config rule
        option name 'Allow-DHCPv6'
        option src 'wan'
        option proto 'udp'
        option src_ip 'fc00::/6'
        option dest_ip 'fc00::/6'
        option dest_port '546'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-MLD'
        option src 'wan'
        option proto 'icmp'
        option src_ip 'fe80::/10'
        list icmp_type '130/0'
        list icmp_type '131/0'
        list icmp_type '132/0'
        list icmp_type '143/0'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-ICMPv6-Input'
        option src 'wan'
        option proto 'icmp'
        list icmp_type 'echo-request'
        list icmp_type 'echo-reply'
        list icmp_type 'destination-unreachable'
        list icmp_type 'packet-too-big'
        list icmp_type 'time-exceeded'
        list icmp_type 'bad-header'
        list icmp_type 'unknown-header-type'
        list icmp_type 'router-solicitation'
        list icmp_type 'neighbour-solicitation'
        list icmp_type 'router-advertisement'
        list icmp_type 'neighbour-advertisement'
        option limit '1000/sec'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-ICMPv6-Forward'
        option src 'wan'
        option dest '*'
        option proto 'icmp'
        list icmp_type 'echo-request'
        list icmp_type 'echo-reply'
        list icmp_type 'destination-unreachable'
        list icmp_type 'packet-too-big'
        list icmp_type 'time-exceeded'
        list icmp_type 'bad-header'
        list icmp_type 'unknown-header-type'
        option limit '1000/sec'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-IPSec-ESP'
        option src 'wan'
        option dest 'lan'
        option proto 'esp'
        option target 'ACCEPT'

config rule
        option name 'Allow-ISAKMP'
        option src 'wan'
        option dest 'lan'
        option dest_port '500'
        option proto 'udp'
        option target 'ACCEPT'

config include
        option path '/etc/firewall.user'

config rule 'ovpn'
        option name 'Allow-OpenVPN'
        option src 'wan'
        option dest_port '1194'
        option proto 'udp'
        option target 'ACCEPT'

config zone
        option name 'toxic'
        option mtu_fix '1'
        option input 'REJECT'
        option forward 'REJECT'
        option masq '1'
        option output 'ACCEPT'
        option network 'toxic tun1'

config forwarding
        option dest 'toxic'
        option src 'lan'

config forwarding
        option dest 'toxic'
        option src 'wan'

config rule
        option target 'ACCEPT'
        option src 'toxic'
        option name 'toxic access'

config zone
        option name 'VPN_TOXIC'
        option input 'REJECT'
        option network 'toxic'
        option output 'ACCEPT'
        option masq '1'
        option forward 'REJECT'

(I also have openVPN server installed on the router so I can establish VPNs towards my home LAN.)

DHCP config:

root@mojito:/etc/config# cat dhcp

config dnsmasq
        option domainneeded '1'
        option localise_queries '1'
        option rebind_protection '1'
        option rebind_localhost '1'
        option local '/lan/'
        option domain 'lan'
        option expandhosts '1'
        option authoritative '1'
        option readethers '1'
        option leasefile '/tmp/dhcp.leases'
        option localservice '1'
        option noresolv '1'
        option doh_backup_noresolv '-1'
        list doh_backup_server '8.8.8.8'
        list doh_backup_server '192.168.9.1'
        option logqueries '1'
        list server '127.0.0.1#5054'
        list server '127.0.0.1#5053'

config dhcp 'lan'
        option interface 'lan'
        option leasetime '12h'
        option force '1'
        option start '120'
        option limit '20'

config dhcp 'wan'
        option interface 'wan'
        option leasetime '12h'
        option force '1'
        option start '120'
        list dhcp_option '3, 192.168.9.1'
        list dhcp_option '6, 192.168.9.1'
        option limit '20'

config dhcp 'toxic'
        option interface 'toxic'
        option leasetime '12h'
        option force '1'
        option start '120'
        list dhcp_option '3, 192.168.99.1'
        list dhcp_option '6, 192.168.99.1'
        option limit '20'

config odhcpd 'odhcpd'
        option maindhcp '0'
        option leasefile '/tmp/hosts/odhcpd'
        option leasetrigger '/usr/sbin/odhcpd-update'
        option loglevel '4'


The dns ip for the Toxic subnet should be the dns server IP provided by VPN provider?

Not necessarily, It could be the google DNS server (8.8.8.8). The problem is that it doesn't seem to even reach it....

Probably the CPU port should be also tagged.

Looks like the interface is missing the VID tag.

Remove DNS from your downstream interfaces.

1 Like

Also picked up that "Toxic" is missing VLAN tag, (WAN and LAN both have them )

Hi,

Thanks for the help. I'm closer but still not working.
I have tweaked the configuration:

  • Created an Interface for the VPN connection and created a firewall zone for it. Bonded both.
  • Instead of allowing all traffic from toxic zone to "device" allowed simply DHCP
  • Tagged the toxic traffic to the CPU
  • Corrected the device (VLAN tag) in the "config interface" section
  • Added pull_filter ignore "redirect-gateway" into the ovpn config
  • Added package "VPN policy routing" and configured two policies as below (everything else is as default)

Sympthoms:

  • VLAN99 clients (wired and wifi) are able to obtain their IP
  • VLAN 99 clients don't have internet access, (the VPN is ON)
  • VLAN 99 clients have access to router web page and SSH (although I just allowed DHCP in the firewall)

Stragenly enough, I'm able to traceroute out of a host in the toxic VLAN, but unable to ping (!) neither having web access: (10.8.1.1 is the VPN interface)

user1@nostromo:~$ traceroute ifconfig.me
traceroute to ifconfig.me (34.117.59.81), 30 hops max, 60 byte packets
 1  mojito.lan (192.168.99.1)  0.623 ms  0.713 ms  0.934 ms
 2  10.8.1.1 (10.8.1.1)  173.114 ms  344.823 ms  346.013 ms
 3  v146.ce01.sin-01.sg.leaseweb.net (103.254.155.220)  346.208 ms  346.382 ms  346.674 ms
 4  be-1.br02.sin-01.sg.leaseweb.net (23.106.255.6)  346.846 ms  347.152 ms  347.678 ms
 5  be-1001.br02.sin-10.sg.leaseweb.net (23.106.255.198)  515.850 ms ae-1002.br01.sin-10.sg.leaseweb.net (23.106.255.196)  347.815 ms ae-1001.br01.sin-10.sg.leaseweb.net (23.106.255.194)  347.982 ms
 6  po-102.bb01.sin-10.leaseweb.net (31.31.38.124)  348.150 ms po-101.bb01.sin-10.leaseweb.net (31.31.38.168)  344.098 ms  344.211 ms
 7  209.85.148.160 (209.85.148.160)  511.669 ms  508.553 ms  513.594 ms
 8  108.170.254.225 (108.170.254.225)  513.243 ms 74.125.242.33 (74.125.242.33)  511.757 ms 108.170.254.225 (108.170.254.225)  448.521 ms
 9  72.14.232.101 (72.14.232.101)  448.342 ms 74.125.251.207 (74.125.251.207)  448.206 ms 209.85.244.157 (209.85.244.157)  447.622 ms
10  81.59.117.34.bc.googleusercontent.com (34.117.59.81)  447.847 ms  447.892 ms  447.936 ms

user1@nostromo:~$ ping ifconfig.me
PING ifconfig.me (34.117.59.81) 56(84) bytes of data.
From mojito.lan (192.168.99.1) icmp_seq=1 Destination Port Unreachable
From mojito.lan (192.168.99.1) icmp_seq=2 Destination Port Unreachable
From mojito.lan (192.168.99.1) icmp_seq=3 Destination Port Unreachable
From mojito.lan (192.168.99.1) icmp_seq=4 Destination Port Unreachable
CFrom mojito.lan (192.168.99.1) icmp_seq=5 Destination Port Unreachable
From mojito.lan (192.168.99.1) icmp_seq=6 Destination Port Unreachable

This is odd, I'd believe traceroute and ping would be both ICMP...

Network config:

root@mojito:~# 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 'fde2:2722:656e::/48'

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

config device 'lan_dev'
        option name 'eth0.1'
        option macaddr '58:ef:68:58:cf:9d'

config interface 'wan'
        option ifname 'eth0.2'
        option proto 'static'
        option netmask '255.255.255.0'
        option type 'bridge'
        option igmp_snooping '1'
        option ipaddr '192.168.9.2'
        option gateway '192.168.9.1'
        list dns '8.8.8.8'
        list dns '192.168.9.1'

config device 'wan_dev'
        option name 'eth0.2'
        option macaddr '58:ef:68:58:cf:aa'

config interface 'wan6'
        option ifname 'eth0.2'
        option proto 'dhcpv6'
        option auto '0'

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

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

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

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

config interface 'toxic'
        option proto 'static'
        option netmask '255.255.255.0'
        option type 'bridge'
        option igmp_snooping '1'
        option ipaddr '192.168.99.1'
#       list dns '8.8.8.8'
#       list dns '192.168.99.1'
        option ifname 'eth0.99'

config device 'toxic_dev'
        option name 'eth0.99'
        option macaddr '58:ef:68:58:cf:ab'

config interface 'VPN_TO_ZOOG'
        option ifname 'tun1'
        option proto 'none'

Firewall:

root@mojito:~# cat /etc/config/firewall

config defaults
        option syn_flood '1'
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'REJECT'

config zone 'lan'
        option name 'lan'
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'ACCEPT'
        list device 'tun0'
        list device 'tun+'
        option network 'lan'

config zone 'wan'
        option name 'wan'
        option input 'REJECT'
        option output 'ACCEPT'
        option forward 'REJECT'
        option masq '1'
        option mtu_fix '1'
        option network 'wan wan6'

config forwarding 'lan_wan'
        option src 'lan'
        option dest 'wan'

config rule
        option name 'Allow-DHCP-Renew'
        option src 'wan'
        option proto 'udp'
        option dest_port '68'
        option target 'ACCEPT'
        option family 'ipv4'

config rule
        option dest_port '22'
        option src 'wan'
        option name 'Allow SSH'
        option target 'ACCEPT'
        option family 'ipv4'
        list proto 'tcp'
        list dest_ip '192.168.9.2'

config rule
        option dest_port '67'
        option src 'wan'
        option name 'DHCP-Server'
        option family 'ipv4'
        option target 'ACCEPT'
        list proto 'udp'

config rule
        option name 'Allow-Ping'
        option src 'wan'
        option proto 'icmp'
        option icmp_type 'echo-request'
        option family 'ipv4'
        option target 'ACCEPT'

config rule
        option name 'Allow-IGMP'
        option src 'wan'
        option proto 'igmp'
        option family 'ipv4'
        option target 'ACCEPT'

config rule
        option name 'Allow-DHCPv6'
        option src 'wan'
        option proto 'udp'
        option src_ip 'fc00::/6'
        option dest_ip 'fc00::/6'
        option dest_port '546'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-MLD'
        option src 'wan'
        option proto 'icmp'
        option src_ip 'fe80::/10'
        list icmp_type '130/0'
        list icmp_type '131/0'
        list icmp_type '132/0'
        list icmp_type '143/0'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-ICMPv6-Input'
        option src 'wan'
        option proto 'icmp'
        list icmp_type 'echo-request'
        list icmp_type 'echo-reply'
        list icmp_type 'destination-unreachable'
        list icmp_type 'packet-too-big'
        list icmp_type 'time-exceeded'
        list icmp_type 'bad-header'
        list icmp_type 'unknown-header-type'
        list icmp_type 'router-solicitation'
        list icmp_type 'neighbour-solicitation'
        list icmp_type 'router-advertisement'
        list icmp_type 'neighbour-advertisement'
        option limit '1000/sec'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-ICMPv6-Forward'
        option src 'wan'
        option dest '*'
        option proto 'icmp'
        list icmp_type 'echo-request'
        list icmp_type 'echo-reply'
        list icmp_type 'destination-unreachable'
        list icmp_type 'packet-too-big'
        list icmp_type 'time-exceeded'
        list icmp_type 'bad-header'
        list icmp_type 'unknown-header-type'
        option limit '1000/sec'
        option family 'ipv6'
        option target 'ACCEPT'

config rule
        option name 'Allow-IPSec-ESP'
        option src 'wan'
        option dest 'lan'
        option proto 'esp'
        option target 'ACCEPT'

config rule
        option name 'Allow-ISAKMP'
        option src 'wan'
        option dest 'lan'
        option dest_port '500'
        option proto 'udp'
        option target 'ACCEPT'

config include
        option path '/etc/firewall.user'

config rule 'ovpn'
        option name 'Allow-OpenVPN'
        option src 'wan'
        option dest_port '1194'
        option proto 'udp'
        option target 'ACCEPT'

config zone
        option name 'toxic'
        option mtu_fix '1'
        option masq '1'
        option output 'ACCEPT'
        option network 'toxic tun1'
        option input 'ACCEPT'
        option forward 'ACCEPT'

config forwarding
        option dest 'toxic'
        option src 'lan'

config forwarding
        option dest 'toxic'
        option src 'wan'

config rule
        option target 'ACCEPT'
        option src 'toxic'
        option dest_port '68'
        option name 'DHCP_RENEW_TOXIC'
        list proto 'udp'

config zone
        option output 'ACCEPT'
        option masq '1'
        option input 'REJECT'
        option forward 'REJECT'
        option name 'VPN_Z'
        list device 'tun1'

config rule
        option dest_port '67'
        option name 'DHCP_SERVER_TOXIC'
        option target 'ACCEPT'
        list proto 'udp'
        option src 'toxic'

config forwarding
        option src 'toxic'
        option dest 'VPN_Z'

config rule
        option src 'toxic'
        option name 'toxic_to_vpn'
        option target 'ACCEPT'
        option dest 'VPN_Z'

Any idea what may still be missing?

Any idea or suggestion?
Thanks