Hi, is there any similar to Asus VPN Fusion (link) for OpenWrt? To set up the router as e.g. an OpenVPN client for selected devices on LAN (either with IP, or with MAC), so all traffic would go to the internet, only the selected devices would be directed through the VPN tunnel?
Yeah, it didn't cross my mind, to do it through routing, lol.
I just have an OpenVPN server at some other place and I wanted to bind a specific device (or devices) to the VPN from the router as a client, not from the devices themselves. Yeah, I could look into routing.
I know WireGuard would be much better, but I never managed to successfully set up even a WireGuard server on my OpenWrt router (I get TX, but no RX). I am not sure I want to deal with the client...
root@Wifi:~# wg show
interface: wg0
public key: PublicKey
private key: (hidden)
listening port: Port
peer: PeerKey
preshared key: (hidden)
endpoint: PhoneIP:SomePort
allowed ips: 10.3.0.2/32
latest handshake: 14 minutes, 1 second ago
transfer: 868 B received, 23.48 KiB sent
persistent keepalive: every 25 seconds
Btw, is it possible that it generated a key pair with symbols which are not allowed?
Sorry, I've been busy with some other stuff. So, I have a new snapshot on my Redmi AX6000 and I have it as a dumb AP / switch atm (e.g. 192.168.9.0 VPN > 192.168.9.1 Redmi > 192.168.15.2 Redmi > 192.168.15.1 main router > Internet). I am now able to connect to the OpenVPN and WireGuard server on the Redmi AX6000, but...
On the WireGuard server (but same as on the OpenVPN server), I am able to connect to all the devices in the cascade (e.g. 192.168.9.0 VPN > 192.168.9.1 Redmi > 192.168.15.2 Redmi > 192.168.15.1 main router > Internet), but no other devices within the 192.168.15.0 network (e.g. another OpenWrt device on 192.168.15.3).
I have "0.0.0.0/0, ::/0, 192.168.15.0/24" in Allowed IPs on the client, I have a routing on the main router from 192.168.15.0 through 192.168.15.2 to 192.168.9.0 (although, I am not sure I even need this, I wouldn't be connecting in the direction to the client).
Main router network file (stock vendor-modified 18.06-SNAP firmware, but working normally):
The Redmi AX6000 WireGuard (and OpenVPN) server's network file:
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 'ULA::/48'
option packet_steering '1'
config device
option name 'br-lan'
option type 'bridge'
list ports 'eth0'
list ports 'lan2'
list ports 'lan3'
list ports 'lan4'
list ports 'wan'
config interface 'lan'
option device 'br-lan'
option proto 'static'
option ipaddr '192.168.15.2'
option netmask '255.255.255.0'
option ip6assign '60'
option gateway '192.168.15.1'
list dns '192.168.15.1'
config device
option name 'wan'
option macaddr 'MAC'
config interface 'wg0'
option proto 'wireguard'
option private_key 'PRIVATE-KEY'
option listen_port 'WG-PORT'
list addresses '192.168.9.1/24'
list addresses 'fd00:9::1/64'
config wireguard_wg0 'wgclient'
option public_key 'PUBLIC-KEY'
option preshared_key 'PRESHARED-KEY'
list allowed_ips '192.168.9.2/32'
list allowed_ips '192.168.15.0/24'
list allowed_ips 'fd00:9::2/128'
Is it even possible to share the lan network if the OpenWrt router with the WireGuard server is not in the router mode, but only a dumb AP / switch with disabled firewall, dnsmasq, and odhcpd?
Removed in the client config on the switch and the client config file, but still not able to connect to other devices on 192.168.15.0. I am able to connect to the internet through the VPN, I am able to connect to the devices in the cascade, but nothing within the LAN network.
Ok, here is a solution to one of the issues:
For the WireGuard server on a dumb AP / switch (with disabled odhcpd, dnsmasq, firewall) to allow clients to reach devices in the lan network, not only those in the cascade between the VPN client and the internet (not only VPN client > WireGuard gateway > Switch IP > Router IP > Internet), I had to add following nftable rules to the startup script (/etc/rc.local):
nft add table ip nat
nft add chain ip nat postrouting { type nat hook postrouting priority srcnat \; }
nft add rule ip nat postrouting masquerade
nft add table ip filter
nft add chain ip filter FORWARD { type filter hook forward priority 0 \; }
nft add rule ip filter FORWARD iifname "wg0" accept
nft add rule ip filter FORWARD oifname "wg0" accept
For routing OpenVPN on the dumb AP / switch without firewall, I need to add following to the startup switch (adjusted IP domain of OpenVPN, e.g. 10.8.0.0):
nft add rule ip nat postrouting oifname "br-lan" ip saddr 10.8.0.0/24 masquerade
nft add rule ip filter FORWARD iifname "tun0" accept
nft add rule ip filter FORWARD oifname "tun0" accept
Now I can use VPN services even on a dumb AP / switch with disabled firewall etc. I think this can be useful to many people and maybe, it would be worth updating the WireGuard and OpenVPN manuals to include dumb APs / switches.
The original question, however, stays. How can I connect to VPN on the main router (main router as a VPN client) and route only selected lan devices through the VPN?
You need to either enable masquerading on the lan zone of your OpenWrt + WG router, or you need to add a static route on the main router so that the return traffic can be properly routed back to the WG tunnel.
Either method works -- if your main router supports adding static routes, you can just add one and then you can turn off masquerading on the WG router's lan zone.