WireGuard client mikrotik simple setup

Hi. i am fighting with WireGuard client setup, but without successfully.
My network looks as in attached picture .
My problem is that not able set correct settings on MT2 for users 192.168.7.254 connected for ETH2.
From other devices like phone or computer I am able connect as client to MT1, so works, but from users who connected for MT2 I can’t.

Because other users using iOS or computes can connect directly to MT1 via wireguard (to internet and local LAN MT1, as well) , so I suspect that main problem is in MT2 setup (routes?,rules)

Handshake between MT1 and MT2 by wireguard are working correctly, ping for gate to 192.168.1.254(gate MT1) is working only when ping use direct wireguard interface on MT2.
Ping from user 192.168.7.254 to 192.168.1.254 (MT1) not .
May i please for clarify me, what i will do something else ?
please be patient i am not advanced network setup person…
WGsetup.pdf (18.4 KB)

I will have a look but first read this reference as it may likely answer your questions…

See para F - https://forum.mikrotik.com/viewtopic.php?t=182373

There are usualy three main problem areas, Allowed IPs, Firewall Rules, and IP routes.

(1) ALLOWED IPs

Allowed addresses on MT1 Server need to be spelled out clearly.
peer1 - iphone remote → 172.16.10.3
peer2 - laptop remote → 172.16.10.4
peer3- MT2 ---->172.16.10.2/32,192.168.7.0/24

Allowed address on MT2 Client
Peer1 -MT1 —> 172.16.10.0/24,192.168.1.0/24

(2) FIREWALL RULES

MT1 and M2 ( not all rules apply, and depend upon traffic admin wants to direct )

  • allow local subnet to enter tunnel (forward chain) for local subnets going to remote sites.
  • allow remote subnet to exit tunnel (forward chain) for remote subnets coming to the local router.
  • allow remote users to exit tunnel (forward chain) for remote users coming to local router
  • allow remote users to enter tunnel (forward chain) for remote users going to remote sites (relay at server)
  • allow remote subnets to enter tunnel (forward chain) for remote subnets going to remote sites (relay at server)
  • allow admin to access router (input chain)
    ++++++++++++++++++++++++++++++++++\
  • allow initial handshake (input) (only at server if connectivity not achievable in reverse)

(3) IP ROUTES

MT2

  • wireguard IP address takes care of any routes for pinging and return routing of any remote users that reach MT2 through MT1
  • require IP Route for remote subnets
    a. either → remote subnets that visit the router and router needs to know where to send return traffic
    b. Or → or remote subnets that will be the destination address of any local subnets.

add dst-address=remotesubnet gwy=wireguard table=main

MT3
Same as above!
In addition, one has to take into account any RELAY ACTIVITY.
ENSURE that remote traffic coming into the router has a route to then to re-enter the tunnel.

Thank you for answer
some tips and rules i fill and corrected some values on MT1 and MT2
I am really beginer in this case…
Resluts of my configuration on MT2 are in attachment.
results are the same ping on gate from MT2 (wireguard) to MT1 (192.168.1.254). is working, but still don’t work conneted user 192.168.7.254.
MT2.PNG

Would need to see the full config on each MT
/export (minus serial number and any actual public WANIP or gatewayIP info).

Hello. thanks for answer and patience. The are my first configuration export i hope that the are correctly…
On MT1 are placed two onther one VPN service (server) , OpenVpn (bridge mode) and L2tp+ipsec. both works correctly.
Kind Regards Mariusz.
MT1.txt (12 KB)
MT2.txt (7.15 KB)

MT2

(1) The wg1 wireguard IP address for MT2, is incorrect

From:
/ip address
add address=192.168.7.1/24 comment=defconf interface=bridge network=192.168.7.0

add address=172.16.10.2 interface=wg1 network=172.16.10.0

TO:
/ip address
add address=192.168.7.1/24 comment=defconf interface=bridge network=192.168.7.0

add address=172.16.10.2**/24** interface=wg1 network=172.16.10.0

(2) WHY DO you have this Input chain rule on MT2 ??? The handshake is in the opposite direction and plus you cannot receive such things as there is no public iP address??
add action=accept chain=input protocol=udp src-address=“my public address” src-port=13231


(3) There is no need for the extra source nat rule on MT2, it can be removed. The reason for allowed IPs on MT1, means that you dont need to use sourcenat, your LAN members will be welcome at MT1!!
/ip firewall nat
add action=masquerade chain=srcnat comment=“defconf: masquerade” ipsec-policy=out,none
out-interface-list=WAN

add action=masquerade chain=srcnat out-interface=wg1 out-interface-list=WAN protocol=udp

(4) The IP route to MT1 subnets is great but there is a slight config error!!!
From:
/ip route
add disabled=no distance=1 dst-address=192**.68**.1.0/24 gateway=wg1 pref-src=“” routing-table=tablWG scope=
30 suppress-hw-offload=no target-scope=10

TO:
/ip route
add disabled=no distance=1 dst-address=192.168.1.0/24 gateway=wg1 pref-src=“” routing-table=tablWG scope=
30 suppress-hw-offload=no target-scope=10


MT1

(4) Allowed IPs… There is no requirement to fill in any endpoint address or endpoint port information, should be removed!
/interface wireguard peers
add allowed-address=172.16.10.120/32 comment=“Klient ipad” endpoint-address=193.239.58.35 endpoint-port=13231 interface=wireguard1
persistent-keepalive=10s public-key=“i9QMyKH2aiZhRleIeKGUl0JUNABBq1I0W3IniXb12GA=”
add allowed-address=172.16.10.2/32,192.168.7.0/24 comment=“Testowy w domu” endpoint-address=193.239.58.35 endpoint-port=13231
interface=wireguard1 persistent-keepalive=5s public-key=“Zi5xqAAQACtMQkOxohiXw8LPkiyIJNNYqdjmzHN/MUM=”

(5) Not sure what you are accomplishing with the SOURCE NAT RULES but the one in yellow for wireguard should be removed.
/ip firewall nat
add action=masquerade chain=srcnat comment=“defconf: masquerade” out-interface=ether1
add action=masquerade chain=srcnat out-interface=ether1 src-address=192.168.10.0/24
add action=masquerade chain=srcnat dst-address=192.168.1.0/24 src-address=192.168.1.0/24
add action=masquerade chain=srcnat out-interface=ether1 src-address=192.168.16.0/24

add action=masquerade chain=srcnat out-interface=ether1 src-address=172.16.10.0/24

(6) The IP routes are incomplete missing the route to the subnet on M2!
/ip route
add disabled=no distance=2 dst-address=0.0.0.0/0 gateway=“Huawei Play USB”
add disabled=no dst-address=192.168.1.0/0 gateway=“my public IP” routing-table=main suppress-hw-offload=no
add disabled=no dst-address=192.168.7.0/24 gateway=wireguard1

Hello, justnagain Thanks for patience and answer, I will apply your notices
Some answers are in text below.

Hi, the notices was introduces, i hope that i understood correctly and complete
The results are following:

  • handshake is working


  • ping to gate from wg1 interlace on MT2 to gateway 192.168.1.254 is working


  • ping form user 192.168.7.254 to gateway 192.168.1.254 not work , some rules/ routes was missing ? i don’t have experience (in bridge was easy…)
    MT1.txt (12.3 KB)
    MT2.txt (7.24 KB)

MT2

(1) Modify these rules just to be sure…
add action=accept chain=forward dst-address=192.168.7.0/24 src-address=192.168.1.0/24 in-interface=wg1
add action=accept chain=forward dst-address=192.168.1.0/24 src-address=192.168.7.0/24 out-interface=wg1

(2) Delete this rule NOT needed. You dont need to masquerade traffic because we allow 192.168.7.0/24 users (all of the subnet IPs) on MT1.
add action=masquerade chain=srcnat out-interface=wg1 out-interface-list=WAN protocol=udp

(3) This route is needed but… the last part is wrong. The gateway is needed, not a different table. Just remove the routing-table entry.
/ip route
add disabled=no distance=1 dst-address=192.168.1.0/24 gateway=wg1 pref-src=“” routing-table=tablWG
scope=30 suppress-hw-offload=no target-scope=10


(4) Why do you have this routing rule… not sure what you are attempting to do but its not under any guidance/advisement.???
REMOVE IT.
/routing rule
add action=lookup-only-in-table disabled=no dst-address=192.168.1.254/32 interface=wg1 routing-mark=
tablWG src-address=192.168.7.254/32 table=tablWG

NOTE: A routing rule and table are typical if you have to redirect users to use internet through the wireguard tunnel, vice ones own local WAN. Not the case here!


MT1

(5) Just in case it makes a difference, modify the allowed address for the MT2 (remove the /32)
TO:
add allowed-address=172.16.10.2,192.168.7.0/24 comment=“Testowy w domu”
interface=wireguard1 persistent-keepalive=5s public-key=
“Zi5xqAAQACtMQkOxohiXw8LPkiyIJNNYqdjmzHN/MUM=”


Please make the changes above and then confirm the following:

IPad to MT1 ping
IPAD to MT2 ping
IPAD to MT1 - access a device on the 192.168.1.254 network
IPAD to MT2 - access a device on the 192.168.7.0/24 networks
MT2 to MT1 - ping
MT2 to MT1 - access a device on the 192.168.1.254 network
MT1 to MT2 - ping
MT1 to MT2 - access a device on the 192.168.7.0/24 network

hello.
i am not sure what is wrong in notice 3. So i introduced directly this rule by terminal on MT2
“/ip route
add disabled=no distance=1 dst-address=192.168.1.0/24 gateway=wg1 pref-src=”" routing-table=tablWG
scope=30 suppress-hw-offload=no target-scope=10"

results of Ping:
IPad to MT1 ping
IPad to gateway MT1 192.168.1.254 by WireGuard Client on IPad from other network status OK 5ms

IPAD to MT2 ping
IPad to gateway MT2 192.168.7.1 by WireGuard Client on IPad from other network status OK 5ms

IPAD to MT1 - access a device on the 192.168.1.254 network
IPad to gateway MT1 192.168.1.xx local devices by WireGuard Client on IPad from other network status OK 5ms

IPAD to MT2 - access a device on the 192.168.7.0/24 networks
IPad to gateway MT2 192.168.7.254 local devices by WireGuard Client on IPad from other network status not OK timeout

MT2 to MT1 - ping
computer connected to local LAN on MT2 ping to 192.168.1.254 - notOK

MT2 to MT1 - access a device on the 192.168.1.254 network
computer connected to local LAN on MT2 ping 192.168.1.200 - notOK

MT1 to MT2 - ping
ping form network (computer 192.168.1.200) local LAN on MT1 - to 192.168.7.1 - not OK timeout

MT1 to MT2 - access a device on the 192.168.7.0/24 network
ping form network (computer 192.168.1.200) local LAN on MT1 - to 192.168.7.254 - not OK timeout


My observation:

  1. IPAD works OK and get public address form MT1 for internet, have fully access to local network on MT1 as well…
  2. handshake between MT1 / MT2 works as expected
    MT2.txt (7.55 KB)

The problem is you dont NEED a routing rule or routing table on MT2 !!!

The table on the route should be TABLE MAIN!!!

I think the instructions were clear!

TOO FUNNY, instead of deleting the WRONG table entry, you disabled it and then created the same rule with the same WRONG table entry
From:
/ip route
add disabled=yes distance=1 dst-address=192.168.1.0/24 gateway=wg1 pref-src=“”
routing-table=tablWG scope=30 suppress-hw-offload=no target-scope=10
add disabled=no distance=1 dst-address=192.168.1.0/24 gateway=wg1 pref-src=“”
routing-table=tablWG scope=30 suppress-hw-offload=no target-scope=10

TO:
/ip route
add distance=1 dst-address=192.168.1.0/24 gateway=wg1 table=main

Hi.
All pings works !!! without one exception.
My computer still have public IP from MT2…
What I will do get internet form MT1?

I checked WG VPN speed performance this connection
MT2->MT1 Upload is 44 Mbps
download is 20,6 Mbps
is it normal ?

CPU usage MT1 is 40/20%
CPU usage MT2 is 90/75%

Ipad WG clinet connection performance
download 83Mbps upload 40,6Mbps

performance l2PT+ipsec for Ipad is
80/45

is it possible improve this on side MT2?

You never stated a requirement to go out internet of MT1 from MT2!
Post latest of both configs please…

Sorry that not clear…..
My main intend was that user connected to mt2 (red on diagram) go to internet via WG by MT1
(Red arrow on diagram)
The configuration was not not changed only was introduced with correct valuec (main table) within your latest post

Cant help unless you post your latest config from both.
A fresh export ensures changes you forget you made are included (trust me it happens).

Hi my latest fresh configs in attachments
MT1.txt (12.5 KB)
MT2.txt (7.36 KB)

So you want MT2 users to access M1 servers and M1 internet.

(1) In this case on MT2, the allowed IPs should consist solely of 0.0.0.0/0 as this is what is needed to cover off internet inquiries.
The neat thing is this also covers off any subnets at M1, and the wireguard IP address at M1.

(2) We still need the route that points users into wireguard for the remote subnet they will be visiting 192.168.1.0/24 on table main.
/ip route
add disabled=no distance=1 dst-address=192.168.1.0/24 gateway=wg1 pref-src=“”
routing-table=main scope=30 suppress-hw-offload=no target-scope=10

(3) Your firewall rules are backward.
From:
add action=accept chain=forward dst-address=192.168.7.0/24 out-interface=wg1
src-address=192.168.1.0/24
add action=accept chain=forward dst-address=192.168.1.0/24 in-interface=wg1
src-address=192.168.7.0/24

TO:
add action=accept chain=forward dst-address=192.168.7.0/24 in-interface=wg1
src-address=192.168.1.0/24
add action=accept chain=forward dst-address=192.168.1.0/24 out-interface=wg1
src-address=192.168.7.0/24

Think of it this way. In the first rule you are saying traffic heading to the local subnet its coming in on wireguard1 and specifically from the remote subnet.
The second rule you are saying any traffic heading for the remote subnet from local users it going out the wireguard interface.

(4) Whats missing is the firewall rule for internet access, or more clearly stated, the ability for your local subnet users on M2, to enter the wireguard when attempting to either go out the internet via M1 WAN, or to m1 subnets, so we can basically replace the second rule above with one that covers off any traffic from local users on M2 to M1
so the two rules will now look like this
add action=accept chain=forward dst-address=192.168.7.0/24 in-interface=wg1
src-address=192.168.1.0/24

add action=accept chain=forward out-interface=wg1 src-address=192.168.7.0/24

(5) Now a new route required to ensure M2 users going out for internet get routed to the wireguard tunnel and we do this by forcing the users out the wireguard tunnel for internet instead of the local M2 WAN.
We need three things, the table, you already have, the routing rule and the route.
a. /routing table
add disabled=no fib name=tablWG

b. /routing rule add src-address=192.168.7.0/24 action=lookup table=tablWG
Note: If you want users to be able to access the local WAN if the wireguard tunnel goes down, then keep the action as noted above. However if you dont want them having any internet when wireguard goes down then change the action to: lookup-only-in-table

c. /ip route
add dst-address=0.0.0.0/0 gwy=wireguard1 table=tablWG

that should suffice for M2
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

M1 Comments…

(6) The masquerade rule for remote users coming out the tunnel (from mT2 or any remote user) and going out the WAN of the MT1 is NOT REQUIRED!
THe MT1 router has a direct link to the internet and thus returning traffic will be sent back to the KNOWN originators.
A. because the wireguard interface is on MT1
B. because one has a route through the wireguard interface for remote subnets
c. because one has firewall rules permitting the traffic flow.

Remove this rule.
add action=masquerade chain=srcnat comment=“niepewne dla lWireGuard”
disabled=yes out-interface=ether1 src-address=172.16.10.0/24

(7) I dont see an explicit firewall rule allowing mt2 users to go out WAN on MT1 so suggest adding it.
add chain=forward action=accept in-interface=wireguard1 src-address=192.168.7.0/24 out-interface=ether1

(8) I do not understand the purpose of this route assuming you made it?
add disabled=no dst-address=192.168.1.0/0 gateway=“public IP MT1”
routing-table=main suppress-hw-offload=no

If you dont know why suggest remove it.

Hi, i dont introduced your tips about access to internet by MT1, beacuce my previosus configuration (for local LAN on MT1) was complete destroyed … after reset MT1 (power cycle) ,or afer one day works.
At the momnet MT1<->MT2 handshake dont work
I will tried recreated configuration i onotherone router (hexS) router config as MT3 as WG client.
please help ! i don’t know waht hepend…


Update. It is works when in MT1 i put endpoint addres to my MT2/MT3 public network !!!
I don’t understand
I am really beginer.
MT2.txt (6.75 KB)
MT3.txt (6.51 KB)
MT1.txt (12.1 KB)

Hi all Your tips was introuced
All works fine, thank You very much!!
It is strange whe when MT1 was power up then WG don’t work… without definition endopints by peer…
MT2.txt (7.57 KB)
MT1.txt (12.5 KB)