Is possible to reach services hosted within the LAN from the Internet while the VPN client is active ?
I have a service running on a computer at let’s say 192.168.8.100. I have a port forwarding rule from WAN 8080 towards 192.168.8.100:8080.
When the VPN client is off, I can reach this service from the Internet by reaching [public IP]:8080. However, when I turn the VPN client on (all traffic policy), the service cannot be reached anymore.
I guess I would need something like “Services from GL.iNet Use VPN” to off, but for my own services. Is there any way to allow the non-VPN incoming traffic when the VPN is active ?
There is a workaround which consists in excluding the MAC address of computer at 192.168.8.100 from using the VPN with a policy, but I’d like the outgoing traffic of this computer to go through the VPN, and that the non-VPN incoming traffic is accepted anyway. Does this sound feasible ?
# mark incoming traffic from wan for record
iptables -t mangle -A INPUT -i eth0 -j CONNMARK --set-xmark 0x80000/0x80000
# mark outgoing traffic not use vpn
iptables -t mangle -A OUTPUT -m connmark --mark 0x80000/0x80000 -j CONNMARK --restore-mark
I’m not used to performing such low level operations. Where should I insert these ? How can I undo them if it doesn’t work as expected?
Besides, I’m using repeater as WAN source, do you confirm the “-i eth0” option ?
# mark incoming traffic from wan for record
iptables -t mangle -A INPUT -i wlan-sta0 -j CONNMARK --set-xmark 0x80000/0x80000
# mark outgoing traffic not use vpn
iptables -t mangle -A OUTPUT -m connmark --mark 0x80000/0x80000 -j CONNMARK --restore-mark
To revert the rules, reboot or issue the following command:
uci set firewall.wan_in_conn_mark=rule
uci set firewall.wan_in_conn_mark.name='wan_in_conn_mark'
uci set firewall.wan_in_conn_mark.src='wan'
uci set firewall.wan_in_conn_mark.dest='*'
uci set firewall.wan_in_conn_mark.set_xmark='0x80000/0x80000'
uci set firewall.wan_in_conn_mark.target='MARK'
uci set firewall.wan_in_conn_mark.extra='-j CONNMARK --set-xmark 0x80000/0x80000'
uci set firewall.wan_in_conn_mark.enabled='1'
uci set firewall.lan_in_conn_mark_restore=rule
uci set firewall.lan_in_conn_mark_restore.name='lan_in_conn_mark_restore'
uci set firewall.lan_in_conn_mark_restore.src='lan'
uci set firewall.lan_in_conn_mark_restore.dest='*'
uci set firewall.lan_in_conn_mark_restore.set_xmark='0x80000/0x80000'
uci set firewall.lan_in_conn_mark_restore.target='MARK'
uci set firewall.lan_in_conn_mark_restore.extra='-m connmark --mark 0x80000/0x80000 -j CONNMARK --restore-mark'
uci set firewall.lan_in_conn_mark_restore.enabled='1'
uci set firewall.out_conn_mark_restore=rule
uci set firewall.out_conn_mark_restore.name='out_conn_mark_restore'
uci set firewall.out_conn_mark_restore.dest='*'
uci set firewall.out_conn_mark_restore.set_xmark='0x80000/0x80000'
uci set firewall.out_conn_mark_restore.target='MARK'
uci set firewall.out_conn_mark_restore.extra='-m connmark --mark 0x80000/0x80000 -j CONNMARK --restore-mark'
uci set firewall.out_conn_mark_restore.enabled='1'
uci commit firewall
/etc/init.d/firewall reload
They mark wan incoming traffic with connmark 0x80000, when the traffic go outgoing direction, it restore connmark(ctmark) to nfmark, with mark 0x80000, it will go via route table 52 that not use vpn.
However, I noticed a sudden bandwidth drop of the traffic using Flint’s Wireguard Server, when I did set up the rules (from ~35Mbps in direct Wi-Fi to ~5Mbps when going through WG server). But in reverting the rules I didn’t notice a bandwith improvement, so it may be unrelated, I don’t know…
I had to setup a VPN policy, based on the VLAN, and now it’s not working anymore, the port forwarding remains closed with the VPN on. What should I change such as it works again ?
By the way, do you consider enabling this feature through the interface ?
Sorry for late relay.
I tested on firmware 4.2.1, the vlan VPN policy is compatible with _conn_mark firewall rules.
This code has already been merged into the latest firmware.
When the issue happened, could you send me the iptables output:
Thanks for coming back for this issue.
I just upgraded to the last 4.2.1 snapshot firmware (from 2023-03-30) and it’s still not working with the vlan policy.
I’ll send my iptables in private message.
Hi, thanks for the update.
However I just tested it, I have installed the 4.2.1 beta4 without keeping settings to have a fresh install, set again all my settings, and it’s still not working. My local service responds from the Internet when VPN client is off, and as soon as I turn it on it is not reachable anymore.
The router interface just prompted me to upgrade to 4.2.3 release5, which I did, and then this was not working anymore.
I had to manually redo this command to make it work again, so it seems the script it still missing.
That script is installed in 4.2.3 release5 but another issue is found, you need to apply the policy mode setting after vpnclient is toggle on. Or the port forward rule will not work. That’s buggy, we’ll fix it later.