Wireguard Server - forward traffic to peer

Hi there,

I've successfully set up a wireguard server on my router, and am able to confirm handshake and ping the router from the peer. However, I cannot access my home network (different subnet), nor access the internet from the connected peer. I've been fumbling with firewall settings for a couple days but can't seem to get this traffic forwarded. Please see firewall config below. Thanks for any help and let me know if you need more information.

/etc/config/firewall

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

config zone 'lan'
        option name 'lan'
        list network 'lan'
        list network 'vpn'
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'ACCEPT'

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

config forwarding
        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 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 rule                   
        option name 'wg-port'
        list proto 'udp'      
        option src 'wan'
        option dest_port '49xxx'
        option target 'ACCEPT' 

Forward should be ACCEPT

This is how things pass from one zone to another. If it's REJECT then it doesn't work.

I would / do run all of these a REJECT on my server as a router. Using iptables though and simply set them to drop to avoid responses to whomever is trying to get acknowledged.

*filter
:INPUT **DROP** [0:0]
:FORWARD **DROP** [0:0]
:OUTPUT **DROP** [0:0]
:PERMIT-FWD - [0:0]
:PERMIT-IN - [0:0]
:PERMIT-OUT - [0:0]
-A INPUT -j PERMIT-IN
-A FORWARD -j PERMIT-FWD
-A OUTPUT -j PERMIT-OUT
-A PERMIT-FWD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A PERMIT-FWD -m conntrack --ctstate NEW -j ACCEPT
-A PERMIT-FWD -j DROP
-A PERMIT-IN -i lo -j ACCEPT
-A PERMIT-IN -i br0 -j ACCEPT
-A PERMIT-IN -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A PERMIT-IN -j DROP
-A PERMIT-OUT -o lo -j ACCEPT
-A PERMIT-OUT -o br0 -j ACCEPT
-A PERMIT-OUT -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A PERMIT-OUT -m conntrack --ctstate NEW -j ACCEPT
-A PERMIT-OUT -j DROP
COMMIT
# Completed on Sun Jan 23 20:51:32 2022
# Generated by iptables-save v1.8.7 on Sun Jan 23 20:51:32 2022
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -o bo0 -j MASQUERADE
COMMIT

Create a wgzone and forwardings

wgzone > wan
wgzone <> lan

To access internet in peer you need allow 0.0.0.0/0 in peer

This is actually a sometimes confusing feature of the firewall...
the "forward" zone rule does not affect inter-zone routing. This affects only intra-zone forwarding. In other words, if you have multiple networks that are assigned to the same firewall zone, this affects the ability for inter-VLAN (inter-network) routing between the networks within that zone (determined at the zone level).

When routing is desired between networks that are associated with different zones (again, at the zone level), forwarding rules such as the one below are used to allow this to work.

In this case, the OP theoretically has the WG interface associated with the lan firewall zone which has foward=accept (as shown below):

The "default" zone (which is kind of an unnamed zone) had the forward=reject (as you can see below), but that is not relevant to networks that are assigned to other zones. The default zone is what happens when you don't make an explicit assignment for a network into a zone.

In all cases, it is possible to write traffic rules that provide much more granularity -- so the default action within a zone (or a zone forwarding rule) can be overridden for specific hosts or networks by writing rules as desired.

Using iptables explicitly is one way to achieve the firewall goals, but what is available to implmeent in LuCI/UCI standard rules is usually sufficient. The use of iptables becomes useful if a more sophisticated/explicit/granular ruleset is needed as compared to what the UCI firewall syntax can provide and/or for those who prefer to write the rules this way (which is a totally legit option).

Keep it simple, stupid (KISS)

Works best when it comes to this sort of stuff. All of the BS baked into these FW chains just makes things overly complicated.

For instance if you've ever worked on a Cisco FW using ASDM it takes 1 rule and macro's the hell out of it into 15 lines of code.

Thanks for the reply. I changed the default to ACCEPT as you noted above, as a test, but that broke the peer connection. Was not even able to ping the server, whereas when it is set to REJECT I am. Not sure why this is...

Thank you for the detailed breakdown. I'm not clear if you are recommending a change to get the peer online? If so can you clarify?

Please 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:

cat /etc/config/network
cat /etc/config/firewall

Also, please provide info about the remote peer:

  • what OS is it running (is it also OpenWrt)?
  • is the service you're trying to forward to running on that same host (alongside WG), or is it a different host on the network there?
  • please share the peer config info.

I am recommending that you leave the forward=reject intact for the default zone rules.

Thank you, please see below.

  • what OS is it running (is it also OpenWrt)?

Two peers - Mac OS and iOS

  • is the service you're trying to forward to running on that same host (alongside WG), or is it a different host on the network there?

Different host on the network. But I'd also like to be able to access the internet from the connected peer via my home network when I am away from home.

  • please share the peer config info.
[Interface]
PrivateKey = xxxxxxxxxxx
ListenPort = xxxxx (same as server)
Address = 192.x.x.2/32
DNS = 192.x.x.x (dhcp router)

[Peer]
PublicKey = xxxx
PreSharedKey = xxxx
AllowedIPs = 0.0.0.0/0
Endpoint = 198.x.x.x:xxxxx (public IP)
PersistentKeepalive = 25
$ cat /etc/config/network

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 'fddc:957a:ceea::/48'

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

config interface 'lan'
	option device 'br-lan'
	option proto 'static'
	option netmask '255.255.255.0'
	option ip6assign '60'
	option ipaddr '192.x.x.x'
	option gateway '192.x.x.x'
	list dns '192.x.x.x'

config device
	option name 'eth0.2'
	option macaddr '--------'

config interface 'wan'
	option device 'eth0.2'
	option proto 'dhcp'

config interface 'wan6'
	option device 'eth0.2'
	option proto 'dhcpv6'

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

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

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

config interface 'vpn'
	option proto 'wireguard'
	option listen_port '49375'
	option private_key '------/tZei59538='
	list addresses '192.x.x.1/24'

config wireguard_vpn 'wgclient'
	option public_key '-------='
	option description 'Macbook Pro'
	option preshared_key '-------'
	option persistent_keepalive '25'
	list allowed_ips '192.x.x.2/32'

config wireguard_vpn
	option description 'iPhone'
	option public_key '---------'
	list allowed_ips '192.x.x.3/32'
	option persistent_keepalive '25'
$ cat /etc/config/firewall

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

config zone 'lan'
	option name 'lan'
	list network 'lan'
	list network 'vpn'
	option input 'ACCEPT'
	option output 'ACCEPT'
	option forward 'ACCEPT'

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

config forwarding
	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 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 rule
	option name 'wg-port'
	list proto 'udp'
	option src 'wan'
	option dest_port 'XXXXX'
	option target 'ACCEPT'

Can you repost without redacting the rfc1918 addresses and the port numbers, too? They don’t reveal anything sensitive about your network, but it is important to see for troubleshooting

Also, please verify that you have gotten the handshakes to work:

wg show

Also, please verify that you have gotten the handshakes to work:

yes confirmed

Can you repost without redacting the rfc1918 addresses and the port numbers, too? They don’t reveal anything sensitive about your network, but it is important to see for troubleshooting

Please see below. Thank you.

[Interface]
PrivateKey = xxxxxxxxxxx
ListenPort = xxxxx (same as server)
Address = 192.168.10.2/32
DNS = 192.168.1.1 (dhcp router)

[Peer]
PublicKey = xxxx
PreSharedKey = xxxx
AllowedIPs = 0.0.0.0/0
Endpoint = 198.x.x.x:xxxxx (public IP)
PersistentKeepalive = 25

$ cat /etc/config/network

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 'fddc:957a:ceea::/48'

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

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

config device
	option name 'eth0.2'
	option macaddr 'b0:a7:b9:17:e4:91'

config interface 'wan'
	option device 'eth0.2'
	option proto 'dhcp'

config interface 'wan6'
	option device 'eth0.2'
	option proto 'dhcpv6'

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

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

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

config interface 'vpn'
	option proto 'wireguard'
	option listen_port 'xxxxx'
	option private_key 'xxxxxx'
	list addresses '192.168.10.1/24'

config wireguard_vpn 'wgclient'
	option public_key 'xxxxxx'
	option description 'Macbook Pro'
	option preshared_key 'xxxxxx'
	option persistent_keepalive '25'
	list allowed_ips '192.168.10.2/32'

config wireguard_vpn
	option description 'iPhone'
	option public_key 'xxxxx'
	list allowed_ips '192.168.00.3/32'
	option persistent_keepalive '25'

This should be 192.168.10.3/32. Disregard if this was a typo in this post and is correct in your config.

I would recommend placing the vpn in its own firewall zone (you can set accept on input, output, and forward). Create a forward rule for the vpn zone > lan zone.

Meanwhile, it seems that this is not the main router. There are two ways to get this to work. Either enable masquerading on the lan firewall zone or setup a static route in the main router (if supported).

Does your main router support static routes?

Thank you for the reply. Yes that is a typo, the address is correct.

Yes I am running the WG server on an access point, as my main router is running wireguard as a VPN client so keeping them separate. Not sure if this is necessary The main router is also running openwrt, so yes does support static routes.

I have trouble understanding firewall zones, can you help me to understand the steps involved in getting this working? Thank you again for your help here.

You can combine them, if you want. But since you have this setup, we can probably get it working.
NOTE: you may need to setup VPN Policy Based Routing in order to allow the inbound VPN connections from the WAN to work properly.

Yes...
You want your firewall zones to look like this (note that I have removed the vpn network from the lan and added it to its own zone):

config zone 'lan'
	option name 'lan'
	list network 'lan'
	option input 'ACCEPT'
	option output 'ACCEPT'
	option forward 'ACCEPT'

config zone 'vpn'
	option name 'vpn'
	list network 'vpn'
	option input 'ACCEPT'
	option output 'ACCEPT'
	option forward 'ACCEPT'

Then add a forwarding rule:

config forwarding
	option src 'vpn'
	option dest 'lan'

On your main router, add a static route as follows:
192.168.10.0/24 via 192.168.1.2

Ok this is working!! Thank you so much, I really appreciate the help.

One small thing which which still isn't working: although I can ping and access multiple devices on the network, and access the internet, there is one server I cannot access or ping via the vpn. It is at 192.168.1.205. I can access it when logged onto the home network (192.168.1.x) and I can ping it from both routers. But when connected via the vpn, it times out. Any clues?

Windows? Check the windows firewall. By default, it will not accept connections from other subnets. You can modify the firewall to allow incoming connections from the VPN.

If your problem is solved, please consider marking this topic as [Solved]. See How to mark a topic as [Solved] for a short how-to.

No not windows, linux. I have def accessed this from other subnets. Ok I will dig into the settings on that machine. I will mark this as solved. Thank you for your excellent support!

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.