Need help setting up wireguard

Hello,
I've setup wireguard using this manual.

and it works,
but I have a few issues

  1. on the QR scanning I would like to use host

but in the QR this will be translated to IP, this is not usable for me as I have a dynamic IP and use a dyndns to update my ip.
2. I only want to VPN my dns, not all my traffic, but I can't find how to configure this.
3. I would like to restrict access to my internal network to only some devices. Now all are exposed.

Is this possible in the openwrt wireguard implementation?

The endpoint shows as myhost.duckds.org but it is resolved on your client.
But you can always check on your client what is in the clients config

See my notes how to setup a WireGuard server:

Your WireGuard Clients have a different IP address (e.g. 172.16.1.2) then your lan subnet so usually your LAN clients will not allow that unless specifically allowed.

But if you want to be sure add the WG interface to its own firewall zone and do not make a forward rule from wg firewall zone to LAN but make traffic rules to allow the WG clients you want to the LAN IP addresses you want

1 Like

yes, I can modify the endpoint in the ios wireguard client.
however I need to think about this when rescanning the QR.
using host directly would be easier.

but probably I have to deal with this,

in regards of the firewall,
I now have this

but as I only want to be able to connect to one server, this is probably to open,
or doesn't it hurt just having access to the full network?

and for me most important, is that I only route dns through my VPN. I need this for AGH, the rest of the traffic should go directly

Your firewall setting is not correct.

Either you add the WG interface/network to the LAN zone, but as you want fine grained control you better make a separate zone for the WG interface like you are doing, but this zone has to have the same settings as the lan zone.

Note that a network/interface can only be added to one firewall zone, it looks like you also have the LAN zone added, but I assume there is a separate LAN zone which covers the LAN interface?

Masquerading should not be enabled just like it is not enabled for the LAN zone

Why not have a look at my notes it should be covered there (you need the Server guide): https://github.com/egc112/OpenWRT-egc-add-on/tree/main/notes

The client decides what traffic where to route so if you do not want to route all traffic of your clients to route via your router then do not use 0.0.0.0/0 but e.g. the IP address of your AGH server that way the client only routes that specific traffic through the tunnel.

1 Like

remove the lan from the covered networks in that screenshot. You can only have a network in a single zone, and lan is already in the lan firewall zone.

Is this the 'server' side of the equation? If so, disable masquerading.

It's easy enough to setup a firewall rule to allow only access to the desired resources. Please describe your goal when you are remotely connected - is it for tunneling all traffic (including internet traffic), too?

EDIT: looks like @egc beat me by a few seconds!! lol

1 Like

Probably a first :smile:

1 Like

thnx,
regarding to firewall, I do have a zone for lan,
zo I removed it from covered networks
now it's this


for the QR registration I did found that
the save button does not save the endpoint or allowed ip's

I have to enter them every time again,
But when I do it like this, I can access my dns server,
but not my server on 192.168.180.13 (which is in zone lan)

If it is your phone/tablet/laptop connecting as the remote peer, the only allowed IP that should exist (in the peer config section on the 'server') is the one that is in the same subnet as the WG main interface.

Moving forward, let's see the your configs in text form rather than screenshots. This makes it far easier to read and also much easier to recommend specific changes.

Please connect to your OpenWrt device using ssh and 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:

ubus call system board
cat /etc/config/network
cat /etc/config/firewall

here is my full config

root@OpenWrt:~# ubus call system board
{
        "kernel": "6.6.73",
        "hostname": "OpenWrt",
        "system": "ARMv8 Processor rev 4",
        "model": "Zyxel EX5601-T0 ubootmod",
        "board_name": "zyxel,ex5601-t0-ubootmod",
        "rootfs_type": "squashfs",
        "release": {
                "distribution": "OpenWrt",
                "version": "24.10.0",
                "revision": "r28427-6df0e3d02a",
                "target": "mediatek/filogic",
                "description": "OpenWrt 24.10.0 r28427-6df0e3d02a",
                "builddate": "1738624177"
        }
}
root@OpenWrt:~# 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 'fd52:7983:4908::/48'
        option packet_steering '1'

config device
        option name 'br-lan'
        option type 'bridge'
        list ports 'lan1'
        list ports 'lan2'
        list ports 'lan3'
        list ports 'lan4'
        option ipv6 '0'

config bridge-vlan
        option device 'br-lan'
        option vlan '180'
        list ports 'lan1:u*'
        list ports 'lan2:u*'
        list ports 'lan3:u*'
        list ports 'lan4:u*'

config bridge-vlan
        option device 'br-lan'
        option vlan '1'
        list ports 'lan1:t'
        list ports 'lan2:t'
        list ports 'lan3:t'
        list ports 'lan4:t'

config bridge-vlan
        option device 'br-lan'
        option vlan '170'
        list ports 'lan1:t'
        list ports 'lan2:t'
        list ports 'lan3:t'
        list ports 'lan4:t'

config bridge-vlan
        option device 'br-lan'
        option vlan '160'
        list ports 'lan1:t'
        list ports 'lan2:t'
        list ports 'lan3:t'
        list ports 'lan4:t'

config interface 'lan'
        option device 'br-lan.180'
        option proto 'static'
        option ipaddr '192.168.180.1'
        option netmask '255.255.255.0'
        option ip6assign '60'

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

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

config interface 'guest'
        option device 'br-lan.1'
        option proto 'static'
        option ipaddr '192.168.2.1'
        option netmask '255.255.255.0'

config interface 'smarthome'
        option device 'br-lan.170'
        option proto 'static'
        option ipaddr '192.168.170.1'
        option netmask '255.255.255.0'

config interface 'ziggo'
        option device 'br-lan.160'
        option proto 'static'
        option ipaddr '192.168.160.1'
        option netmask '255.255.255.0'

config device
        option name 'br-lan.1'
        option type '8021q'
        option ifname 'br-lan'
        option vid '1'
        option ipv6 '0'

config device
        option name 'br-lan.170'
        option type '8021q'
        option ifname 'br-lan'
        option vid '170'
        option ipv6 '0'

config device
        option name 'br-lan.160'
        option type '8021q'
        option ifname 'br-lan'
        option vid '160'
        option ipv6 '0'

config device
        option name 'br-lan.180'
        option type '8021q'
        option ifname 'br-lan'
        option vid '180'
        option ipv6 '0'

config interface 'WireGuardVPN'
        option proto 'wireguard'
        option private_key '<some key>'
        list addresses '172.16.1.1/24'
        option nohostroute '1'
        option listen_port '6666'

config device
        option name 'WireGuardVPN'

config wireguard_WireGuardVPN
        option description 'IPhone Bart'
        option public_key '<some key>'
        option private_key '<some key>'
        option preshared_key '<some key>'
        list allowed_ips '172.16.1.2/32'
        option endpoint_host '<mydomain>.duckdns.org'

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

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

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

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

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 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 redirect
        option dest 'lan'
        option target 'DNAT'
        option name 'Home Assistant'
        list proto 'tcp'
        option src 'wan'
        option src_dport '8123'
        option dest_ip '192.168.180.13'
        option dest_port '8123'

config redirect
        option dest 'lan'
        option target 'DNAT'
        option name 'WireGuard pihole'
        list proto 'udp'
        option src 'wan'
        option src_dport '47111'
        option dest_port '47111'
        option dest_ip '192.168.180.10'
        option enabled '0'

config redirect
        option target 'DNAT'
        option name 'NTP-on router'
        option src 'lan'
        option src_dport '123'
        list proto 'tcp'
        list proto 'udp'
        option enabled '0'

config redirect
        option dest 'lan'
        option target 'DNAT'
        option name 'DNS on Pi-hole'
        option src 'lan'
        option src_dport '53'
        option dest_ip '192.168.180.13'
        option src_ip '!192.168.180.13'
        option family 'ipv4'
        option enabled '0'

config rule
        option name 'VacuumCleaner internet'
        list src_ip '192.168.180.22'
        option dest 'wan'
        option target 'REJECT'

config rule
        option name 'Doorbell Internet'
        list src_ip '192.168.180.21'
        option dest 'wan'
        option target 'REJECT'
        option enabled '0'

config rule
        option name 'Doorbell Initial'
        option dest 'wan'
        option target 'ACCEPT'
        option limit '10/second'
        list src_ip '192.168.180.21'

config redirect
        option dest 'lan'
        option target 'DNAT'
        option name 'wireguard HA'
        list proto 'udp'
        option src 'wan'
        option src_dport '51820'
        option dest_ip '192.168.180.13'
        option dest_port '51820'

config zone
        option name 'guest'
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'REJECT'
        list network 'guest'

config forwarding
        option src 'guest'
        option dest 'wan'

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

config forwarding
        option src 'smarthome'
        option dest 'lan'

config forwarding
        option src 'lan'
        option dest 'smarthome'

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

config forwarding
        option src 'ziggo'
        option dest 'lan'

config forwarding
        option src 'lan'
        option dest 'ziggo'

config redirect
        option dest 'lan'
        option target 'DNAT'
        option name 'WireGuard OpenWrt'
        option src 'wan'
        option src_dport '6666'
        option dest_ip '172.16.1.1'
        option dest_port '6666'

config zone
        option name 'WireGuard'
        option input 'ACCEPT'
        option output 'ACCEPT'
        option forward 'ACCEPT'
        list network 'WireGuardVPN'

config forwarding
        option src 'WireGuard'
        option dest 'wan'

config forwarding
        option src 'lan'
        option dest 'WireGuard'

root@OpenWrt:~#

however it's kind of hard to read I think

I am connecting with my phone

Note that there is also wireguard running on my .13 server, but I'm planning to remove it from there once I have it working on openWrt

Remove the nohostroute line:

Delete this:

Add one line (shown below) to this:

Add:

        option route_allowed_ips '1

Delete this:

And add this instead:

config rule
        option name 'WireGuard OpenWrt'
        option src 'wan'
        option proto 'udp'
        option dest_port '6666'
        option target 'ACCEPT'

And finally, if you want to be able to reach your (full) lan, add this:

config forwarding
        option src 'WireGuard'
        option dest 'lan'

(but if you only want a single server, that would actually just be a standard traffic rule)..

1 Like

For the record, allmost all the things we have discussed are covered in my notes, see my earlier post.

But I know reading a manual is not very popular these days :wink:

2 Likes

thnxs,
all seems to work now,
for now it's ok if I can connect to my complete lan
it's filtered client side, this is not secure, but for me it's ok

the last 3 rules of my firewall are

config forwarding
        option src 'WireGuard'
        option dest 'wan'

config forwarding
        option src 'lan'
        option dest 'WireGuard'

config forwarding
        option src 'WireGuard'
        option dest 'lan'

do I need them all?

@egc I actually read your manual, but somehow I still couldn't find the cause,

What is your goal?

wg > wan will allow you to reach the internet from your remote peer via your ISP where the 'server' is located... so in other words, tunnel all traffic through home. Applies if you have allowed_ips on your remote peers set to 0.0.0.0/0 and/or if you have other public IPs in that section.

lan > wg will allow you to reach your remote client from your home lan. This is probably not really necessary in your case, but is useful in a site-to-site configuration.

wg > lan allows you to access your lan from your remote peer.

1 Like

thnx, I was indeed wondereing about lan > wg
and wg > wan I probably do not need, as I do not want to forward any public addresses,
but now I know where they are for .

thank you for the big help!

From my notes:

/etc/config/firewall:
config zone
	option name 'wgserver'
	option input 'ACCEPT'	#use REJECT if you do not want access to the router
	option output 'ACCEPT'
	option forward 'ACCEPT'
	list network 'wgserver'

config forwarding
	# to give WG clients access to your LAN clients 
	# if you want more fine grained control remove this and make a traffic rule see below
	option dest 'lan'
	option src 'wgserver'

config forwarding
	option dest 'wgserver'
	option src 'lan'

config forwarding
    # to give your WG client access to the internet via the router
	option src 'wgserver'
	option dest 'wan'

#Extra traffic rule for access to individual LAN clients if there is no general forwarding:
config rule
	option name 'access-from-wg'
	option src 'wgserver'
	list dest_ip '192.168.5.199'
	option target 'ACCEPT'
	list proto 'all'
	option dest '*'

Also this :slight_smile:

4.  Allow seamless access to LAN clients
Your LAN clients might not accept traffic from your WG clients because traffic comes from another subnet and LAN clients might have their own firewall which blocks non local traffic.
The best way to solve this is to tweak the firewall of local clients to accept traffic from the WG subnet.
For Windows:
How to Add IP Address in Windows Firewall
Step 1) On the Start menu, Click ‘Windows Firewall with Advanced Security’.
Step 2) Click the ‘Advanced settings’ option in the sidebar.
Step 3) On the left side, click the option ‘Inbound Rules’.
Step 4) On the right, under the section ‘Actions’, click on the option ‘New Rule’. Windows Firewall shows you the New Inbound Rule Wizard.
Step 5) A new window will open and Select the ‘custom’ option and click Next.
Step 6) In the left-hand side again, go to the option ‘Scope’.
Step 7) Add the IP address and click on the ‘Ok’ button.

But if that is not feasible you can masquerade the WireGuard traffic which comes out of the router.
Simplest method is to use option 2b for setting up the firewall and Enable Masquerading on the LAN interface.

However this Masquerades all traffic so better is to only Masquerade WG traffic with the following firewall NAT rule:
Network > Firewall > NAT rules:

/etc/config/firewall:
config nat
	option name 'SNAT-WGserver'
	option src 'lan'
	option src_ip '172.22.22.0/24'  # the WG subnet, note the .0 at the end
	option target 'MASQUERADE'
	list proto 'all'
	option enabled '1'


With Masquerading WG traffic you loose logging and access control but  in a typical SoHo setup, where you trust your users, that is not a big deal.

1 Like

@psherman @egc Does the video accurately describe how we should setup wireguard or we need to include the additional steps outlined in this thread?

Not looking for anything fancy or setting up restrictions, just need to connect to my local LAN when remote.

I don't know if it does or not... I didn't watch it.

They may be "additional" with respect to the video if they were omitted there, but they're fairly basic for setting up WG.

If you have issues, please start your own thread and we'll help you through the process.

1 Like

Will do, video looks to be very off from @egc document from what I could tell.

I took a quick look and the video is what the OP followed and which is obviously wrong.

When my notes are polished and improved I hope they will be good enough to be used as OpenWRT Wiki

the video works, but does not cover specific use cases,
if you do that and then compare it to the manual, you probably have a hard time figuring out what the differences are.

I think If I knew about this manual before starting that would be helpful.
however, the video covers QR, the manual does not.

And I love the QR part of wireguard.