Community discussions

MikroTik App
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 18168
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Wireguard Success For The Beginner

Tue Jan 18, 2022 3:44 am

{ linked from New User Pathway To Success Config Success - viewtopic.php?t=182373 }

A thorough, organized plan for your specific WG connectivity will go a long way to establishing a working Peer to Peer config.
- INTRO
(1) Generic Settings for WG Devices
(2) Overlapping Peers
(3) Configuring IP Routes
(4) Using IP address for WG Interfaces
(5) Configuring Firewall Rules
(6) My NETNAME or any DYNDNS URL
(7) Third Party VPN - Keys / Source-Nat / DNS
(8) Behind Another Router & Source-NAT
(9) Other Considerations: A. No Public IP, B. Firewall & Mangling, C. Crypto Key Routing Explained, D. MTU-MSS Issues, and E. Network Diagram
(10) L2TP thru WIREGUARD for MTU Issues
(11) PCC and 2 Wireguard Interfaces Available ( viewtopic.php?t=195145#p995228 )
(12) Wireguard and Multi-Client OSPF ( viewtopic.php?t=199210 )
...
(15) SIX SCENARIO EXAMPLES

If You are Not New To Wireguard Go Straight To The Topic Above That Interests You.
FOR OTHER WIREGUARD APPLICATIONS ADVANCED USES (EOIP, ETC) - viewtopic.php?t=194646
FOR MIKROTIK DOCS -https://help.mikrotik.com/docs/display/ROS/WireGuard

#1 Issue - Don't have an accessible public IP, commonly WISP connections, Cellular Internet, CGNAT and Starlink to name a few!
#2 Issue - You have mismatched public key entries!
#3 Issue - You have to sourcenat your users to the wireguard interface when using a 3rd party VPN for internet!
#4 Issue - Your Router peer subnets should have a corresponding main table router through the wireguard interface.!
#5 Issue - Your wireguard interface does NOT require dhcp/pools etc..!
=================================================================================================

Common Reasons to use Wireguard - A Peer to Peer VPN Protocol

1. Accessing the Internet from another location.
example - remote site to local site OR reverse (one tunnel) ------> mobile iphone or subnet on a remote device, to the internet through a local Wireguard connected device.
example - remote siteA -- to local site -- to remote siteB (two tunnels) ----> mobile iphone to local Wireguard Device and then enters second tunnel to third party providers internet.

2. Accessing Servers/Subnets at another location
example - remote site to local site or reverse (one tunnel) ---> users on remote subnet need to access local wireguard device's subnets
example - remote siteA -- to local site -- to remote siteB (two tunnels) ---->mobile iphone to local Wireguard Device and then enters second tunnel to a remote router's LAN server

3. Bundling Accessing Internet and Subnets -combination of the above!

4. Config Router by Admin any combination of tunnels as outlined above.

INTRO: If you have reached this article, you are probably starting on your first Wireguard setup for one of the reasons above. Its fun and not as complex as many other types of VPN. This article will help explain the various bits and pieces that work together to ensure traffic flows the way you want it too. If nothing else, get a piece of paper (or open word doc) and go through the exercise of filling in the information considered in Steps1-6 and the PLAN 1-5. . All the work after that will make much more sense and will lead to a successful configuration experience!

[Gather Information/Requirements]
Step1: Identify all the connecting devices involved - the ones with Wireguard configuration settings
Step2: Identify all the users, either individuals (like a smart phone or road warrior/laptop), or groups of users (aka a subnet of users).
Step3: Identify which user(s) need access to internet through WG (and thus not from their local ISP)
Step4: Identify which user(s) need access to the subnet at the other end of the tunnel (could be on an MT device or another router up or down from the MT device).
Step5: Identify as you the admin, which MT devices you wish to manage/Config from your local MT end of the WG tunnel.
Step6: Identify between applicable pairs of WG devices, WHICH device, for the initial connection instance, will be acting as SERVER (listening port active) and which will be CLIENT (sends original request). Could be both if they each have an accessible Public IP.

[Planning Steps]
1. Plan Traffic Flows - from where to where for all use cases! (Dont forget Admin to Devices for configuration if required)
2. Plan Initial Tunnel Connection - which site will start the tunnel request (client). As noted, could be either device if they both have accessible Public IPs.
3. Plan coordinated Wireguard IP address Subnet - for all Peer Wireguard Interfaces. ( see - (4) USING IP ADDRESS FOR WG INTERFACE )
4. Plan Routing of Traffic - how to get the traffic routed properly
5. Plan Firewall Rules - how to get the traffic, entering and exiting the wg interface, to where it needs to go.

[Start Configuring Devices - on paper first]
6. Configure Wireguard Interfaces based upon the complete set of requirements/gathered information.
7. Configure Router settings. Applicable for MT devices as additional router settings such as IP Routes and Firewall Rules are normally required.

[The Initial Connection Dilemma!]
i. To establish a WG connection, at least one end of the WG tunnel should have a WG Device with a reachable public IP. If the reachable Public IP resides with an ISP Router or a different device prior to the WG device, (aka internet---->Generic Router/Modem--->WG Device) this could still be considered a USABLE connection, if one can PORT FORWARD from the ISP connected Router/Modem to the listening port on the WG capable device. Such a device can be considered for the SERVER role in the initial connection between wireguard devices.

ii. If one end of the tunnel does not have a WG device with a reachable public IP and one has no control over the ISP connected Router, then this un-configurable end of theWG tunnel is NOT ABLE to act as a Server for the initial connection. Examples of such instances are smart phones or road warriors with laptops.

iii. The WG device that cannot 'host' a connection (not reachable by public IP), must be considered as the Client in the Server/Client relationship when first establishing the tunnel, and if possible should make use of its keep alive setting (in Peer Settings).

iv. If both devices at the ends of the tunnel are turned on (up) the client device will initiate a handshake and a Tunnel will be established. Traffic does not need to occur for the tunnel to be created. Additionaly the keep alives will start kicking in at the presrcibed timing. After this initial connection is established the relationship is no longer Server/Client, the tunnel is now open to two way traffic and traffic can occur from either side (peer to peer network).

v. Wireguard traffic from either end of the tunnel can take place and follows wireguard routing behaviour utilizing, wireguard peer addresses, available Routes and adhering to firewall rules where applicable.

v. After initial connection is established the relationship is no longer Server/Client, the tunnel is now open to two way traffic and traffic can occur from either side (peer to peer network).

vi. Most of the rest of the discussion addresses when one end of a tunnel has limited WANIP access. If you have two MT devices, with accessible public IPs, you do not need keep alives, but more importantly both sets of users behind the tunnels (or even road warriors 'remoting' into one of the MT Routers) can initiate the tunnel creation. If the MT is acting as a client then use the persistent keep alive setting 30 seconds is fine.
For tracking/logging and config purposes it is recommended to use unique listening ports/input chain rules at each end.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
ONCE YOU HAVE COMPLETED STEPS 1-6 & PLAN 1-5 ABOVE, YOU ARE READY TO START THE CONFIG 6-7
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

As discussed above the very basic concepts/steps for setting up any Mikrotik Device are highlighted below as we start to go into the details.....
1. The initial connection configuration ---> one device has to act as client and the other as server for that instant of time ( only one input chain rule needs to be triggered ).
2. Coordinate an IP address subnet, that includes all the peers, so that each wireguard interface has an associated IP address. For mobile devices (single IP/32) this is the address assigned in the wireguard parameters under Interface Settings.
3. Allowed IPs at each device found in PEER Settings. It should include all destination address of local users - outbound that will enter the tunnel AND it should include all source addresses of incoming (remote) users - inbound and will exit tunnel. Additionally, It should also include the IP addresses of all other associated peer wireguard interfaces.
4. Ensuring IP routes are created manually. Not required for Mobile Devices
5. IP routes will be created dynamically (DAC) for the Allowed IPs that detail the Wireguard Interface IP addresses.
6. On Mikrotik devices, FIREWALL RULES are key to ensuring that traffic exiting the tunnel is allowed to go where it needs to go, or the right traffic is allowed to travel to the tunnel.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

(1) GENERIC SETTINGS FOR WG DEVICES

Wireguard Interface Settings (not mobile)
Add name=WG-X Any name of your choosing.
Add listen port=xxxxx. Essential/required only for any Device acting as Server for the initial connection instance. If the client device (speaking about connection instance only) does not have an accessible public IP, it is normal practice to simply put the same port as entered for the Server Device (the Listening Port) and this will actually never be used. However if you have two MT devices local and remote, with both having accessible IPs, one need NOT be concerned about keep alives or which is client or server for the connection, simply config both to have unique listening ports etc. and when users initiate wireguard traffic the tunnel creation instance in either direction will occur and the peer to peer wireguard tunnel will be in play.
Created public key= public key generated by the local device that needs to be provided to the Remote Device (for entry in its associated Peer settings).

Wireguard PEER Settings (not mobile)
Select Interface Name entered above
Endpoint IP address - the PUBLIC IP or associated DYNDNS name of the Remote side of the tunnel ( required if initiating the wireguard tunnel ).
Endpoint Port - the listening port entered on the Remote Device. ( required if initiating the wireguard tunnel )
Allowed IPs (addresses) per peer.
Persistent Keepalive Normally used for the client type devices (iphones etc), common practice is anywhere between 25-45 seconds.

Important Discussion of Allowed IPs
Think of 'Allowed IPs', in the sense of IP addresses being identified on the OTHER END DEVICE, when identifying the TWO local distinct traffic flows of INBOUND and OUTBOUND. Plus we normally add the wireguard interface IP addresses of all peers that may be used for pinging and troubleshooting connectivity.

A. OUTBOUND: In the case of outbound traffic from the local device to the remote device (From SOURCE) , the destination addresses are used by the local WG Device in a SELECTOR (matching) function, to be determine if any of the local users' destination addresses, being executed at any time, line-up with those IP addresses identified on the one or more PEER settings on the local Wireguard settings. More specifically, the Device will first determine if a Route exists for that traffic(destination address) and then if the IP Route associated Gateway points to the Wireguard Interface, the Router will then check the Allowed Addresses, starting with the first Peer for that Wireguard interface and then any remaining peers. The Peer selected (first match) will determine the tunnel selected (destination IP and Port). A WG interface can have multiple peers and each peer can have multiple addresses. Be careful of overlapping or duplicating such Peer Allowed IPs/destination IP addresses as that will cause issues and is a CONFIG ERROR on your part. ( see - (2) )

Normally such OUTBOUND "Allowed IPs (addresses)" consist of two types:
(i) accessing the internet on the other end of the tunnel and thus use address 0.0.0.0/0 (all possible internet addresses)
(ii) accessing specific IP addresses (subnets, server, users, Wireguard Interface IP addresses, etc.) at the other end of the tunnel and thus use applicable IP address(es) as required.
Note1: The dst-address 0.0.0.0/0 also includes subnets at the other end and thus one would only require the insertion of the internet address nomenclature to cover both needs.
Note2: The IP address or subnet to be accessed may not even exist at the other end of the tunnel but that will clearly require further config at the far end MT device to make it work. A typical example could be a Server that exists on another remote Router, where both the local user device and server on that remote devices connect to an intermediary WG Server Device (hosting both tunnels).

B. INBOUND: In the case of inbound traffic from the remote device to the local device (At RECIPIENT), the IP addresses are used by the Recipient device (local device) as a FILTER function, which will only allow traffic with source IPs that are defined on the local Peer Allowed IPs lists. If no such IPs are defined, the traffic will not be be permitted to exit the WG interface and thus not gain access to the LAN or internet etc.

FUN FACT: What you will discover with experience is that there is OFTEN duplication of inbound and outbound flows. Put simply, it is not uncommon for the destination IPs of local users (outbound) to be the same as the source address of inbound remote users (bidirectional traffic). Thus a single "Allowed IP" entry may cover both inbound and outbound traffic. The extreme case being Alllowed IPs=0.0.0.0/0 which allows all traffic (but in this case watch out for overlapping peers).

Wireguard Interface Settings (typical mobile)
Add name=WG-X Any name of your choosing.
Created public key= public key that needs to be provided to the Remote (Server) Device (in its Peer settings).
Addresses= The IP address that will identify the Mobile Device on the Wireguard network. Consider this entry to be the Wireguard IP address for the mobile device. With that in mind, ensure it is planned so that it is included in the coordinated subnet plan for all the Peer Wireguard IP addresses.
MTU=Default value 1420. Normally only changed if partial connectivity issues occur. Try changing this first before mangling and other solutions.
DNS Servers= Anything can be entered here. MT recommends entering in the WG gateway IP of the server (Typically, I put the same external DNS servers that my Server Router also has such as 1.1.1.1,9.9.9.9)

Wireguard PEER Settings (typical mobile)
Public Key: Provided by Remote Server Device.
Endpoint address - the PUBLIC IP or associated DYNDNS name of the Remote (Server) side of the tunnel and the associated port, typically either as two separate line entries or in the following format:
publicIP:port or mynetname:port etc...
Allowed IPs= Covered previously but in most cases this is the internet setting of 0.0.0.0/0 which also covers any subnet access at the remote device or the IP Wireguard interface address of the remote device. If internet is not the destination, then ensure the correct addresses are included.
On Demand: This ensures the mobile device remains connected to the Wireguard network when switching providers (aka hotel wifi to cellular).

-----> Allowed IPs Calculator: https://www.procustodibus.com/blog/2021 ... alculator/

(2) OVERLAPPING PEERS

CAUTION OVERLAPPING PEERS CAUTION: One should not have the same IP addresses identified on two or more peers of ANY SINGLE Wiregard Interface. If you find yourself in this situation, create another WG interface to separate the duplication +++++.

Reason. The local WG device, as stated previously, when receiving a destination address from a user first locates a working route for that traffic and then attempts to match the destination address to the ALLOWED IPs lists entered into the peers of that particular interface (in our case a Wireguard interface), and if it finds a match, selects that peer and sends the traffic accordingly. It has no way of knowing which peer to send that traffic too and only matches the first available peer IP address. This issue is more frequently seen when sending out users through a remote site for internet and have several peers for this purpose, as both have the same destination address of 0.0.0.0/0. The peers do not need to be active for this error to be experienced.
++++ To create another wireguard interface you will need an additional listening port and associated input chain rule on the WG Remote (Server) Router.

(3) CONFIGURING THE IP ROUTES

When configuring IP routes at the local device, one has to consider two traffic flows. One is the traffic originating or considered to be 'starting' at the local device. This could be local users OR for example traffic that has come through and exited the wg interface (and now at the WG Server Device) and is to be relayed through either the same WG interface or a different interface (second tunnel) onwards to another device ( eg.another client MT device or a 3rd party VPN.) The other traffic to direct is any returning traffic that originated at a Remote Client, has exited the tunnel and now needs to return to that same Client. This return traffic could be coming from the internet or perhaps a server at the Local WG Server Device. In the more complex relay example noted above, the Return Traffic, lets say return internet traffic from the 3rd party VPN (via wireguard) that has exited from the Wireguard Interface, onto the Relay Device, and now needs to be directed back through the applicable wireguard interface to the originating user.

(i) Route for Subnet / Single IP - LOCAL TRAFFIC (starting traffic). At the local device, to ensure local user(s)/subnet(s) are sent through the tunnel when attempting to reach destination IP addresses at remote devices, a fairly standard IP Route directing those local users to the wireguard interface gateway is created:
/ip route
dst-address=IPsubnet/24 (or IP address/32) gwy=WG-interface table=main
(where the dst address basically matches an allowed IP address entry - destination address of local users).

(ii) Route for Subnet / Single IP - REMOTE TRAFFIC (returning traffic). At the local device, to ensure remote user(s)/subnet(s) RETURN Traffic (after reaching the internet or local device servers for example) is directed BACK through the tunnel again a fairly standard IP Route is created:.
/ip route
dst-address=IPsubnet/24 (or IP address/32) gwy=WG-interface table=main
(where the dst address basically matches an allowed IP address entry - source IPs of remote users).

FUN FACT: What you will discover with experience is that OFTEN, just as in 'Allowed IPs" and due to bidirectional traffic, one IP Route covers both local 'originated' traffic AND remote returning traffic. Consider the case where the local traffic needs to reach the remote subnet 192.168.50.0/24 and that same remote subnet needs to reach a server on the local device. At the Local device, the "Allowed IP" of 192.168.50.0/24 covers both outbound (destination addresses) and inbound (remote source IPs) considerations. Similarly, one only needs one IP route to ensure that local users get sent out the wireguard interface with destination address of 192.168.50.X and the remote users (with their source addresses) are directed back into the tunnel after hitting the local server.
/ip route
dst-address=192.168.50.0/24 gwy=wg-local table=main
{ Is a single valid IP Route for BOTH CASES! }

Note1: For Mobile Devices with fixed single IPs, that are already included in the coordinated IP wireguard interface schema, a dynamic IP routing (DAC) will already exist and thus a manually created route will not be needed.
Note2: Each Peer will require such routes and multiple IP addresses within each peer should need such routes.
Note3: Manual Routes will not be required for traffic to/fro Wireguard Interface Addresses.
Note3: It may be necessary to source-nat packets entering a tunnel so that they more easily handled at the other end (special cases).

(iii) Route for Internet Traffic . Internet traffic is a special case in terms of IP Routes for Wireguard Interfaces. Mainly because we have to identify this by stating ALL possible IP addresses/subnets - 0.0.0.0/0! As above we will consider the two cases of Return Traffic and Starting Traffic at the local device. Return is straightforward but Starting requires further work:

a. RETURN (REMOTE) TRAFFIC: Remote users are exiting the local device wireguard tunnel and using the local device WAN connection for internet. How do we deal with Traffic returning from the WWW, with source address of remote users. We have to direct that traffic back through the tunnel. It is fairly straightforward:
/ip route
dst-address=IPsubnet/24 (or IP address/32) gwy=WG-interface table=main
(where the dst address basically matches an allowed IP address entry - source address of remote users).

Note: One should see that this matches the configuration for the INBOUND return traffic from local subnet/servers, example above (ii)

b. ORIGINAL (LOCAL) TRAFFIC: One or more local users (or even remote users that came in on a WG tunnel and now considered local) need to ENTER a tunnel to use the Internet at a Remote Device. However, often, there are either multiple subnets on the local Router or only a single user/device has the requirement to go elsewhere for internet. (Many possible combinations) Why is this difficult? We have to recognize and accommodate for the fact that INTERNET access at the local Router already exists for all other users/devices on the Router.

Thus if we already have an IP route dst-address=0.0.0.0/0 gwy=wanIPgateway table=main we will need to deconflict for internet access!!
Q1 - How do we take only one subnet out of two or three on the local device and point it to the tunnel
Q2 - How dow we take one device and point it to the tunnel.

Solution: We create a new table (other than main) and we point the selected traffic to that table in a routing rule. No mangling required. We "FORCE" the traffic into the tunnel so that it is not captured by the already existing route to the internet through the WANIP.
/routing table add fib name=use-WG
/routing rule add src-address=IP address action=lookup-only-in-table table=use-WG

/ip route
dst-address=0.0.0.0/0 gwy=wg-interface-name table=use-WG

Note: If the admin wants the users to be able to access internet locally if WG is down then use ACTION=Lookup { akin to fail over }

(4) USING IP ADDRESS FOR WG INTERFACE

The right plan is to create a coordinated subnet to connect all the Peer Wireguard Interface IP addresses.

IP ADDRESS - INDEPENDENT
Ensure the subnet you create is independent of any subnets existing on any of the devices (excluding mobile devices). This process also ensures proper device to device communications and also aids in troubleshooting(pinging). One should include mobile devices ( where its single IP Address is assigned within the Wireguard settings), that unlike MT devices do not have separate IP address functionality and do not have subnets within the device.

Using en example of three peers and one main router, each peer device and the main router are given an IP address within the same subnet.
Looking at the table below, If the admin wants to check ping from one device to another (local to remote), the admin has to make sure that on the local device the remote WG address is included in the peer IP "allowed IPs" addresses (viable destination address for pinging).

WIREGUARD INTERFACE ADDRESSES.
/ip address
add address=10.10.5.5/24 interface=wg-local {at Local Router} SERVER FOR INITIAL CONNECTION!!
add address=10.10.5.4/24 interface=wg-peer3 {at remote device 3 - Hex}

For mobile devices the wireguard interface address is the ADDRESS you give to the wireguard connection WITHIN the wireguard settings:
Address=10.10.5.2/32 = {at remote device 1 - iphone}
Address=10.10.5.3/32 = {at remote device 2 - laptop}

PEER ALLOWED IPs In general, the Router acting as a hub (usually the receiver of initiated connections) will have specific Peer settings for each client. In this regard each peer in allowed IPs for the wireguard IP, should be set to the specific IP/32. When one has multiple routers, ensure that on any given router, there is not the case of overlap with two wgsubnet .0/24 settings to describe allowed IPs (no two peers on any router should have.0/24). The router will not know which peer you are discerning (much like overlapped peers discussed previously). It is okay to have a mix of one wgsubnet .0/24 and multiple specific wgips/32 as /32 is a longer mask (like in routes) and will always be chosen when requested and thus the router will not be confused at any point.
For single clients its normal/okay to put the wg subnet for allowed IPs.

(only considering Wireguard interface IP addresses, for actual traffic add to this base/minimum setting)
Iphone (Peer=Local Router), Allowed IPs=10.10.5.0/24 (done) [note: not required if for internet access as 0.0.0.0/0 includes all addresses.]
Laptop (Peer=Local Router), Allowed IPs=10.10.5.0/24 (done) [note: not required if for internet access as 0.0.0.0/0 includes all addresses.]
Hex (Peer=Local Router), Allowed IPs=10.10.5.0/24 + any other traffic required = outbound (remote destination addresses at local) + inbound (remote source addresses from local)
Local Router : SERVER FOR CONNECTIONS
Peer1 AllowedIPs=10.10.5.2/32 (done)
Peer2 AllowedIPs=10.10.5.3/32 (done)
Peer3 AllowedIPs=10.10.5.4/32 + any other traffic required = outbound (remote destination addresses at hex) + inbound (remote source addresses from hex)

IP ROUTES
Iphone & Laptop not applicable - Mobile Devices (dependent upon the particular architecture of smart phone OS or Laptop OS apps etc.....) They can ping directly as the routing is applied internally.
Hex (created dynamically)
(dac) dst-address=10.10.10.0/24 gwy=wg-peer3 table=main (routes hex pings to Router (dest addr) and/or routes remote Router return traffic after pinging hex)
Local Router (created dynamically)
dst-address=10.10.10.0/24 gwy=wg-local table=main routes Router pings (dest addr) to all peer devices and routes remote Peer return traffic after pinging Router)

NOTE: Firewall Rules still need to be reviewed to ensure any pinging traffic is permitted (LAN/ROUTER to WG -- or -- WG to LAN/ROUTER)

(5) CONFIGURING FIREWALL RULES

If you use the default rules, there is basically nothing stopping most LAN level traffic and without realizing it, wireguard traffic will be allowed both to the router itself and the other LAN entities. It is for this reason, it is recommended that putting DROP all rules at the end of your input and forward chains is done, so that such traffic is under your control, and not automatically allowed.

Assuming one uses a drop all rule at the end of the input and forward chains, one recognizes that we have to create "allow" rules for wireguard traffic. In any Mikrotik device (client or server) and more accurately (local or remote) there are two cases that may occur.
The first is local outbound traffic from an admin, or user or subnet of users to be permitted to enter the tunnel.
The second case is to allow remote inbound traffic from remote users, to access a local server, an entire subnet, the internet, or the MT device for configuration purposes.
The following rules demonstrate the possibilities that exist at both ends of the tunnel:
add action=accept chain=input in-interface=wg-interface-name dst-port=winboxport protocol=tcp src-address=Admin_IP { allows admin to config local router remotely }
add action=accept chain=forward src-address=Subnet out-interface=wg-interface-name { to allow local subnet to enter the wireguard interface }
add action=accept chain=forward in-interface=wg-interface-name dst-address=IPofServer { to allow remote users access to local server } ***
add action=accept chain=forward in-interface=wg-interface-name out-interface-list=WAN { to allow remote users access to local WANIP (internet) } ***

Note1: In the last two examples *** use src-address or src-address-list to refine access to specific users, which may be required for multiple addresses from a peer and multiple peers.
Note2: Ensure Peer Devices software firewalls ( ex. Windows PC ) do not block WG traffic including ICMP.

(6) MYNETNAME or DYNDNS URL - SPECIAL CONSIDERATION FOR ENDPOINT (reresolve DNS)

ISSUE RESOLVED BY VERS 7.12. SCRIPTS ARE NO LONGER REQUIRED!
A known issue with Wireguard occurs when the Endpoint address is DYNAMIC and has been entered via DYNDNS type name. If the wireguard tunnel is initiated before DNS has resolved the DYNDNS URL, the wireguard client will stop and will NOT restart. One has to manually disable and enable the peer to kick-start the tunnel. This can happen if the endpoint actual WANIP changes or a router is rebooted etc. In other words, there are multiple reasons why a wireguard server device is temporarily unavailable (it is rebooted or perhaps the public facing router is rebooted, changes IP address or suffers a power outage). See **** Recommended script.

Sol/n 1 - CHECK LOCAL_IP NAME THROUGH TUNNEL - Use the script (courtesy of gdanov) on the Remote (originating) end of the tunnel to detect when the endpoint device is available by checking local IPs through the tunnel. In other words 'when down'. The Local_IP refers to the server end of the connection and is any local IP reachable through the tunnel. If that IP is reachable through the tunnel then the tunnel is working! If not, then disable the wireguard peer and enable it after 60 seconds. Run this as a scheduled script perhaps every 2 minutes.
...
:local wgcheckip Local_IP
:local endpointip xxxyyy.sn.mynetname.net
#:log info "wg check-ip $wgcheckip "
:if ([/ping $wgcheckip interval=1 count=5] =0) do={
  :log info "WG down $wgcheckip"
  /interface/wireguard/peers/disable [find endpoint-address=$endpointip];
  :delay 60
  /interface/wireguard/peers/enable [find endpoint-address=$endpointip];
  :log info "WG up again $wgcheckip"
}
...

Sol/n 2 - BASIC NETWATCH - Easier method! (unknown author) Using the Netwatch Tool, using the "DOWN" tab, and the HOST IP is the Local IP ( Reachable subnet or IP address through the tunnel - best to use Wireguard Interface IP address of Server). However, this has been found not to work if the Server side is down for an extended length of time. Suggest if the Server is problematic, try a different script or perhaps extend the delay to 75 seconds. The problem occurs when the Server is still down after the time delay as Netwatch does not trigger/function again (no UP achieved) as its still down.
...
:delay 25
/interface wireguard peer disable 0
:delay 5
/interface wireguard peer enable 0
:log info "WGPeer toggled"
...............

Sol/n 2 - ADVANCED NETWATCH VARIATION on the EASY METHOD - Here a script is used to toggle the Wireguard interface (not netwatch), but netwatch is used to enable or disable the scheduler for the script! Define script to toggle WG peer settings:
.......................
/system script
add dont-require-permissions=no name=ToggleWGPeer owner=*** policy=\
    ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon
    source="
    :delay 25
    /interface wireguard peer disable 0
    :delay 5
    /interface wireguard peer enable 0
    :log info \"WGPeer toggled\"
    "

Define schedule for earlier created script:
I used 2 minute period here, adjust as needed for your own purposes.
Code: Select all

/system scheduler
add disabled=yes interval=2m name=ScheduleWGToggle
on-event="/system script run ToggleWGPeer"
policy=\
    ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon start-date=may/01/2022 start-time=11:34:35

Define Netwatch up/down actions:
Assuming address to be verified "on the other side" is 10.255.255.1 (change as needed for your purposes)
Assumption 2: run every minute (in most cases there is nothing to do... but I prefer not to wait too long when something does go haywire)
Code: Select all

/tool netwatch
add down-script="
    log warning \"NETWATCH - WG Down\"
    /system scheduler set ScheduleWGToggle disabled=no"
    host=10.255.255.1
    up-script="/system scheduler set ScheduleWGToggle disabled=yes"
...........................

**** FOR ADVANCED USERS ------- Courtesy of Sob/Dave ( called elegant by Chupaka even )
It takes all enabled peers with endpoint-address ending with letter (which means it's non-empty and not numeric address) and last handshake older than 5 minutes ("5m" on second line), takes current hostname and sets it again as endpoint-address, which makes RouterOS resolve it again. It should be safe to run it unconditionally from scheduler. In addition, this script will will trigger the endpoint-address reset for blank last-handshake as well.
{ meaning it addresses the following: If the peer has never connected (or if the peer is disabled and re-enabled while the endpoint is down), then the last-handshake is blank and the > 5m condition is false. }
:foreach i in=[/interface/wireguard/peers/find where disabled=no endpoint-address~"[a-z]\$"] do={
  :local LastHandshake [/interface/wireguard/peers/get $i last-handshake]
  :if (([:tostr $LastHandshake] = "") or ($LastHandshake > [:totime "5m"])) do={
    /interface/wireguard/peers/set $i endpoint-address=[/interface/wireguard/peers/get $i endpoint-address]
  }
}
.......................................

VARIATION of ADVANCED (courtesy of msatter!)
>>>>>>>>>>>>>>>>>>>>>>>
{; # BeginOfScript

# scripted by msatter
# function: bring up stalled WireGuard interfaces after restart of the router

:local timesRetried   15    ; # how many times WireGuard is tried to be restarted
:local loopDelay      10s   ; # (loopDelay * timesRetried ) = total timeout
:local restarted      true  ; # set default to true
:local domainResolved false ; # also checking if the endpoint domain-names could be resolved
:local retried        0     ; # set to starting value 

:while ( $restarted && ($retried < $timesRetried) ) do={
    # loop till all Wireguard interfaces are working or there the maximum retries is reached
    :set $restarted false
    /interface/wireguard
    :foreach wg in=[find disabled=no] do={ 
        :local peer [get $wg name]
        # scripted by Anav looking for domain names. Adapted by msatter.
        :foreach i in=[peers/find interface=$peer endpoint-address~"[a-z]\$"] do={
            :if ( [:resolve [peers/get $i value-name=endpoint-address]] ) do={
                :set $domainResolved true
                :set $lastHandshake [peers/get $i last-handshake]
                :if ( ([:tostr $lastHandshake] = "") || ($lastHandshake > [:totime [peers/get $i persistent-keepalive]]) ) do={
                    disable $peer; :delay 1s; enable $peer ; # restarting the WireGuard connection
                    :set $restarted true
                }; # EndIf
            }; # EndIf
        }; # EndForeach
    }; # EndForeach
    :if ( $restarted ) do={
        :put "Check loop: $retried"
        :set $retried ($retried + 1) 
        :put "Checking loop: $retried"
        :delay $loopDelay ; # waiting time till following check
    }; #EndIf
}; # EndWhile
:if ( !$domainResolved ) do={
    :put "One or more domains could not be resolved, all/some domain based endpoints could not be brought up in the set time of ($timesRetried * $loopDelay)"
} else={
    :if ( $restarted && ($retried > $timesRestied) ) do={:put "Not all WireGuard interfaces could be brought up in the set time of ($timesRetried * $loopDelay)"}
    :if ( !$restarted && ($retried > 0) ) do={:put "No WireGuard interfaces are down, after $retried retries"}
    :if ( $retried = 0 ) do={:put "No WireGuard interfaces had to be restared"}
}; # EndElse

}; #EndOfScript
.............................................................

Lastly another script courtesy of AOAKELEY ( called Brutal by Chupaka )
# Wireguard check script

#Declare variables
:local wgport
:local wgpeer

# Disable any peers that have last handshake > 3mins
/interface/wireguard/peers/set disabled=yes [find last-handshake > [:totime "3m"]]
# Disable any peers that have tx or rx 0 (sometimes happens after router restart) 
/interface/wireguard/peers/set disabled=yes [find rx=0 or tx=0]

:delay 2

# For any disabled peer get the port and clear any connections in the firewall
:foreach i in=[/interface/wireguard/peers find disabled=yes] do={
   :set wgport ([/interface/wireguard/peers get $i endpoint-port])

   :foreach j in=[/ip firewall connection find dst-address~":$wgport\$" protocol=udp] do={
   /ip firewall connection remove $j
: log info "** Wiregiuard Check Script ** firewall connections on port $wgport cleared"
   }

# and re-enable any disabled peers
/interface/wireguard/peers set $i disabled=no

# and let the log file know what has happened
:set wgpeer [/interface/wireguard/peers get $i interface]
:log info "** Wireguard Check Script ** wireguard peer $wgpeer restarted"

}
.....

(7) THIRD PARTY VPN ---> Keys / SOURCE-NAT / DNS - See (9)D For Browsing Issues and specific Services like Surfshark VPN

There are two primary methods of 'getting keys' from third party providers. The most common is for the VPN provider to give you a private KEY to use in your own WG interface settings and their public key which one puts on the router peer settings for the VPN provider. Since one only has control at one end of a third party VPN, you should be wondering, how do I give the VPN provider the public key generated by my MT router? By using the private key they gave you on the MT wireguard interface settings this is accomplished. The clue is that regardless of platform, the same private key will generate the same random public key. Thus the VPN provider will give you the Private Key to use for your interface settings as this will then generate a KNOWN (to them) public key and thus you don't have to send one to them. In the standard MT to MT scenario and some other third party providers you need to physically provide the public key generated by a random private key. Router A gives its own public key to B and keeps its own private key secret. and B gives its own public key to A and keeps its own private key secret. This way, A can verify that what has arrived has come from B, and B can verify that what has arrived has come from A.
Caution: When the VPN provider gives your their public key and your private one, whoever has intercepted the delivery of those keys from the VPN provider to you could use your account with the provider.

Often, MT users want to use a third party VPN for all their internet traffic. The considerations are very much standard except for one big difference. VPN providers give you a SINGLE IP address for your WG settings. This makes sense for something like an iphone, or laptop, but creates issues if applying the VPN on an MT device. This is important because the third party VPN will be expecting all traffic to be coming from this IP address as SOURCE IP! In wireguard vernacular, that means the PEER SETTINGS at the 3rd Party VPN server to describe and filter incoming traffic from your MT device for ALLOWED IPs will be set to the single IP address they gave you. Since we have LAN users from potentially multiple subnets going over the wireguard tunnel we have to change their private IPs to that of the assigned WG address. Hence we have to have a way to take all the traffic entering the tunnel locally to appear as if they are coming from that one IP address ---> - answer is SRC-NAT! (see example).

Understanding source-nat and masquerade is an important point for the beginner! SRCNAT Masquerade basically replaces the outgoing source IP address of traffic with the IP of the outgoing interface, be it the local WANIP, OR the IP address of the wireguard interface. The router will un-SRCNAT the return traffic as required.

For this example, we are assuming the 3rd Party VPN provider has assigned you an IP address=10.10.10.2/32, supplied the endpoint IP and port and you have exchanged public keys etc. Thus most of the settings are complete. It is also common fo the third party provider to give you a DNS to use lets say 10.100.200.4 Lets also assume your MT local LANIP subnet to use the tunnel is 192.168.20.0/24. You also have a subnet not going out the third party VPN, but going out local internet 192.168.50.0/25. Furthermore, the .50 subnet should still be able to reach the .20 subnet.
MT WIREGUARD PEER SETTINGS:

1. MT ALLOWED IPs = 0.0.0.0/0 ( also set keep alive to something like 40 seconds)

MT RoS SETTINGS:

2. IP ADDRESS - Add address=10.10.10.2/24 interface=wireguard1

3. FIREWALL RULES -You need to ensure your subnet or subnets are allowed to enter the tunnel. (as applicable)
add chain=forward action=accept src-address=192.168.20.0/24 out-interface=wireguard1 (single subnet)
add chain=forward action=accept in-interface-list=LAN out-interface=wireguard1 (all subnets)
add chain=forward action=accept src-address=192.168.50.0/24 dst-address=192.168.20.0/24 comment="Traffic from subnet .50 to subnet .20 permitted"

4. IP ROUTE - To force all users out Wireguard for internet vice local ISP. You should have the default route already in place, either automatically because in IP DHCP Client you have YES selected for use ISP as default route, OR you should have created one manually.
add dst-address=0.0.0.0/0 gwy=ISP gateway-IP table=main.

THREE STEPS:
Add table
/routing table add name=useWG fib { note this table needs to be high up in the config (has to be there before IP routes etc.)

Add Routing Rule (use as many route rules as you have subnets that need to go out wiregard. Also to ensure local traffic is still possible and to prevent that traffic from getting forced out the wireguard route, ensure we put FIRST IN ORDER, appropriate routing rules.)
/routing rule add dst-address-192.168.50.0/24 action=lookup-only-in-table table=main comment="Return local traffic from .20 to .50 allowed"
/routing rule add src-address=192.168.20.0/24 action=lookup table=useWG comment=-"Force subnet .20 traffic out to wg route"

Add additional route

dst-address=0.0.0.0/0 gwy=wireguard1 table=useWG

Note: lookup means use the table indicated for traffic but if the table is not available, look for another routing (which means check table=main to see if any alive routes exist and use that one).
If you had selected lookup-only-in-table, then the router would not look else where if the wg tunnel was not available and traffic would be dropped.

5. SOURCE-NAT - Two options:

Option 1: (add wireguard interface to WAN LIST)
/interface list
add name=WAN
add name=LAN
/interface list members
add interface=bridge list=LAN
add interface=ether1 list=WAN
add interface=wireguard1 list=WAN
/ip firewall nat
add chain=srcnat action=masquerade out-interface-list=WAN
..........................
OR if you dont add the wireguard interface to the WAN interface list
Option 2:
/ip firewall nat
add chain=srcnat action=masquerade out-interface=ether1   ( assuming ether1 is the name of your WAN interface, it could be pppoe-1, or a vlan etc.)
add chain=srcnat action=masquerade out-interface=wireguard1
................................

6. DNS - As noted in para 4 above, often the 3rd party VPN host provides a DNS to us. In these casesm its best for the subnets going out the WG tunnel to have their dhcp-server network settings adjusted as per the below example, where we have 192.168.20. subnet (be it a vlan or not) that will be going through the wireguard tunnel:
/ip dhcp-server network
add address=10.10.0.0/24 comment=LAN-4-WG dns-server=10.100.200.4 gateway=10.10.0.1

7. THIRD PARTY VPN IP ADDRESS /16 etc.. (not /32). - In many instances third party VPNs also give out an IP address on a wide ranging network. This does not pose any siginficant problems for the MT device. Simply add the address to your IP address for the wireguard interface 10.10.10.2/16 for example. The <DAC> route will be created and with source nat applied all local traffic should work fine out the tunnel.

8. TWO ACCOUNTS FROM SAME THIRD PARTY VPN - What do you do if you need two different locations for your tunnels and the provider gives you a second account but with the exact same IP address. NO PROBLEM but you will need to create a SECOND wireguard interface. Use the same IP address but with a different interface name.
/ip address
add address=10.10.10.2/16 interface=wireguard1
add address=10.10.10.2/16 interface=wireguard2

This will create two DAC routes
<DAC> dst-address=10.10.10.0/16 interface=wireguard1 table=main
<DAC> dst-address=10.10.10.0/16 interface=wireguard2 table=main


(9) Port Forwarding Interference! Sometimes the admin forgets that a port forwarding range may overlap the wireguard listening port. Ensure they are separated otherwise DST NAT will take precedence and one will not have wireguard connectivity.

(8) BEHIND ANOTHER ROUTER ---> WHY SOURCE-NAT?

The Problem: Remote users are exiting the tunnel locally at your MT Server for the purpose of accessing your ISP connection to the local internet. The remote traffic exits the tunnel on your MT device and by firewall rules and routing exits the MT Wan port and then gets sent out the FIrst/Main Router's WAN port to the internet. The return traffic, from remote users, hits the First/Main router and the router looks at the source address of the traffic, ( the subnet IPs of the remote users that came into the tunnel ) and does not recognize the traffic as being valid for any of the First/Main router's own subnets. Nothing is 'routable' from the router's perspective and the traffic is dropped (never reaches the MT device).

The Solution: SOURCE NAT the incoming remote traffic, exiting the wireguard tunnel, to the WANIP of the 'natted" MT device!!
Now the returning traffic from the internet will hit the First/Main router and the router will look at the source address and say, Oh yeah I recognize that, I have a subnet for that traffic that is 'routable' and thus I will send it to the MT Devices WAN PORT!! The MT router detects the source-natting on this arriving traffic and then UN-SRC-NATS the traffic back to the applicable remote users IP addresses, which the MT Device further recognizes is valid return traffic and 'routable' (due to existing IP routes for remote user subnet(s)) and sends the traffic to the wireguard interface.

CASE1: MT Device is behind an MT ROUTER. This is the best case scenario as we have full flexibility to create static routes for return traffic on the First/Main router, if we choose do so. Source-NAT is also a viable option. It is assumed that one has the capacity to port forward the wireguard port via destination NAT, from the MT Router to the MT device.
CASE2: MT Device is behind ANOTHER ROUTER. Some routers allow both static routes and port forwarding and thus the solution will be predicated upon the First/Main Routers capabilities.

(Note: if the First/Main Other Router is incapable of forwarding ports see Para 9. (A).)

(1) Static Route - on ISP Router: If the ISP router is capable of static routes then the following equivalent could be be constructed:
dst=address=subnet_of_users gwy=WANIP of second router table=main

(2) Source NAT - on Server Router: With only the ability to forward ports on the ISP router, the preferred solution is to SRC NAT the remote traffic, that will exit the tunnel, to the WANIP of the Mikrotik Server device.
add chain=src-nat action=masquerade out-interface-list=WAN src-address='subnet_of_remote-users'

(3) Source NAT to a PI WG Server behind a REMOTE SERVER Router - from an MT Client Device: If you have a PI server behind an ISP router (with PI WG parameter interface IP Address = 10.6.0.5/24) and want to use your MT device as a client, with user subnet 192.168.20.0/24, to reach the remote ISP internet connection one will need to consider a route back for return traffic at the PI server. If the PI server (OR ISP Router) cannot create a static route and the PI Server cannot do source nat, for 192.168.20.0/24, all the return traffic packets to go back through the tunnel, will be dropped. Consider using source-nat at the MT Client device.
/ip firewall nat add chain=srcnat action=src-nat src-address=192.168.20.0/24 out-interface=Wireguard to-addresses=10.6.0.254

This is the problem, the PI server has no way to route the return traffic from the remote subnet (your MT Device users). Remember the ISP router the PI server is on, has no knowledge of the subnets on your MT device and there is no way for you to add any routes on the remote ISP router. Thus, if you source-nat all your local client IPs to WITHIN the wireguard structure of the wireguard pi server, then the router will assume the return traffic needs to go back to the PI Server which will then route the traffic out the PI wireguard tunnel.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

(9) OTHER CONSIDERATIONS

A. UH OH - BOTH MY DEVICES DON'T HAVE A PUBLIC IP
In some rare cases you will have a situation where both Mikrotik devices are behind ISP routers that provide a public IP and worse, they are not able to be accessed to port forward the all important listening port!! Please check out this thread for ideas on how to acquire a usable Public IP - viewtopic.php?t=183427

B. USING FIREWALL ADDRESSES & MANGLING

When one needs to IDENTIFY or force traffic for a group of IPs, and not a single source address, or destination address, or interface, or subnet, the only option left to identify such a grouping is by Firewall Address List. However, this entity is not definable as a destination address on an IP route, nor is it definable on the Routing Rule.
There are TWO OPTIONS:

1- Make as many Route Rules as there are single IPs (if less than a subnet or a mix of IPs from various subnets) and use source address (no mangling)!

2-Make a single Route Rule but with mangling and USE ROUTE MARK as the entry argument in the Route rule!

BASIC EXAMPLE. MIxed bag of IP addresses go through tunnel, but too many for option1!
a. capture the traffic via marks in pre-routing
b. capture the marks via route marking in pre-routing
c. apply the route mark in the applicable Routing Rule
d. disable fast track.

ADVANCED EXAMPLE - All traffic must go through the tunnel, all IPs, subnets etc.......
In this case we want ALL SUBNET Traffic to go out the tunnel using Table=MAIN

How to ensure that the initial handshake that should go out the normal ISP WAN pathway is taken if there is no IP route for this.
Solution: Make use of Mangle and output chain (no effect on fastrack!!). The trick is to use the route-mark name as also the routing table name.

Step1: Identify the firewall address for our config
/ip/firewall/address-list add list=WG-Server-Router address= sn.mynetname.net (address=fqdn-of-remote-peer)
Step2: Create the mangle rule........
/ip firewall mangle
add action=mark-routing chain=output dst-address-list=Wireguard_Server-Router new-routing-mark=useWAN passthrough=yes
Step3: Create the Routing Table
/routing table add name=useWAN fib
Step4: Create the IP route
/ip route
dst-address=0.0.0.0/0 gwy=ISP gateway table=useWAN

C. UNDERSTANDING THE CRYPTO KEY ROUTING PROCESS (CKRP)

If you want to know when and how encryption is applied and used during Wireguard transactions this article is probably the clearest to be found. https://www.wireguard.com/#cryptokey-routing

Suffice to say Mikrotik IP routing and Wireguard Crypto Key Routing work together to ensure authorized traffic flows to where it needs to be. In a very general sense, IP Routing brings the traffic to the Wireguard Protocol or takes traffic output by the Wireguard Protocol for dissemination while the Wireguard Protocol does its internal Routing as required. A routing sandwich if you will where CKRP is the meat between the bread of IP ROUTING. ;-)

To help understand the above article this explanation may be helpful.
What the new person, beginner, should focus on is that Crypto Key Routing Process (CKRP) runs in the background and has to do mainly with two processes. However, for crypto routing to occur, it is the responsibility of the admin, to first accurately state the Allowed IPs for each peer (key word being peer=remote site). More specifically the admin should, at any local device, consider the Allowed IPs as they relate to the remote end for two distinct populations of addresses, a. the destination addresses at the remote end, for local users heading outbound and entering the tunnel, and b. the source addresses for users at the remote end, heading inbound and will be exiting the tunnel.

Now that the Allowed IPs are correctly established by the admin, Crypto Routing can carry out its two integrated processes, and the really core bit MAPPING KEYS TO PEERS, uses the admin Allowed IPs to ensure the right peers and right keys are matched to the local traffic entering the tunnel so that the right destination information is added and subsequently at the other again compare Keys and peers and then allowed IPs to ensure authorized traffic is allowed to exit the tunnel. The other process which occurs is the encryption and decryption (not as exciting). That is enough detail for the new beginner at the start of their journey.

In order to provide a bit more detail for the beginner this explanation may be useful.

For LOCAL OUTBOUND TRAFFIC.
User Traffic (payload) ---> Destination address ----> MT device -----> IP Routes
IP Routes ---- > gwy=wireguard interface ---> Crypto Key Routing Process

Wireguard Protocol ( CKRP) - think of Wireguard as a Mini Router
CKRP attemps to find a match of destination address with Allowed IP in the list of Peers starting at Peer1 (order is important!)
Match found ----> Peer Selection ----> encrypt payload (right public key) ----> add associated destination address and destination port for that peer --->create transport packet
Transport packet ----> Exit CKRP --->IP Routes
IP Routes ----> gwy= ISP gateway IP table=main ---> WWW.

FOR LOCAL INBOUND TRAFFIC,
Incoming Transport packet ---> Microtik Device ----> Incoming destination port exists on device ------> IP routing
IP Routing ---> Due to destination port on transport packet ------>Wireguard Mini Router ---> CRKP
CKRP ---> based on dest port, CRKP attempts to authenticate with available associated public keys until successful,
CKRP ---> the public key is used to decrypt transport packet into payload and reveals Source IP address
---> Compare source IP to Peer Allowed IPs from the Peer used for decryption of payload
---> Source IP exists ----->Exit CKRP---> send payload to IP Routes
IP Routes---> Route to correct interface via destination address and firewall rules.

D. MTU-MSS ISSUES Typically observerd when unable to browse or very very slow through wireguard tunnel.

1 - Ensure ICMP is not blocked, this affects PMTUD, which apparently is some function that manages MTU and MSS settings.
2 - Try setting the MTU value at both client and server to 1500.
3 - On the Client end ONLY: Try MSS Clamping - ref forum thread --> viewtopic.php?t=150377#p740866
/ip firewall mangle
add action=change-mss chain=forward comment="Clamp MSS to PMTU for Outgoing packets" new-mss=clamp-to-pmtu out-interface=wireguard1 passthrough=yes protocol=tcp tcp-flags=syn

OR (with mtu default of 1420)
/ip firewall mangle
add action=change-mss chain=forward new-mss=1380 out-interface=wireguard1 protocol=tcp tcp-flags=syn tcp-mss=1381-65535

4- If the above do not work go to (10) below and try an LT2P tunnel where other MTU settings can be massaged.

E. NETWORK DIAGRAM

Use a network diagram to fully describe your plan and it will be intuitively easy to understand the requirements when posting on the forum.

(10) L2TP thru WIREGUARD for MTU Issues
Drawingl2tpWG5.png
For whatever reasons, sometimes connectivity even through a Wireguard Tunnel creates, or does not solve, MTU issues. One possible solution is to use L2TP through the wireguard tunnel, not for encryption but because L2TP settings allow MRRU through MLPPP. One uses the very basic L2TP settings and ensures MRRU is set at 1504 at both ends of the L2TP connection.

The following example will detail an initiating device (RB450G) for wireguard (client for connection) and a receiver device (RB4011) for wireguard (server for connection). Currently, the RBG uses wireguard to send subnet B out the internet connection of the RB4011. Users from Subnet A, require access to servers on subnet Y on the RB4011. In addition, the admin at RB4011 uses the connection to config the router at RBG.

Problem: Users from RBG subnet B, are using IPTV and when they go out internet on RB4011 they encounter issues connecting and it is suspected that MTU issues are at play.
Solution: Funnel such traffic through a plain L2TP tunnel where one can adjust MRU to 1504 and thereby alleviate the issue (dont ask me why or for details but if you wish to provide the why would be appreciated). All user traffic will be sent through the L2TP tunnel to fully explore L2TP settings.

Transport vs Payload

The public IP addresses of the two routers are used for the wireguard transport packets, the sole payloads of the wireguard tunnel are the L2TP transport packets running between the two wireguard IP addresses, and the L2TP payload is used to carry the actual payload (whatever subnet/user traffic we push through the tunnel). The internal L2TP addresses are there to be confirm the L2TP tunnel is ready for payload traffic (both sides are reachable) and they can be used as gateway IP addresses in IP Routes.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Lets setup the RB4011 For Wireguard Connectivity Only
/RB4011 info
/interface wireguard
listening port 15551  mtu=1420 name=wireguard-home
/interface wireguard peers
add allowed-address=192.168.50.2 interface=wireguard-home public-key="---"
/ip address
add address=192.168.50.1/24 interface=wireguard-home
/ip firewall filter { input chain }
add chain=input action=accept dst-port=15551 protocol=udp
Lets setup the RB450GFor Wireguard Connectivity Only
/RB450G info
/interface wireguard
listening port 10771  mtu=1420 name=wireguard-client
/interface wireguard peers
add allowed-address=192.168.50.0/24  endpoint-address=mynetnameRB4011 endpoint-port=15551 interface=wireguard-client public-key="..." \
persistant keep-alive=35sec
/ip address
add address=192.168.50.2/24 interface=wireguard-client
++++++++++++++++====================++++++++++++++++++++++++==========================

Now lets layer in transparently the L2TP tunnel, but connect it through *****WIREGUARD!!

L2TP Server (RB4011)

One of the first things to do, on the server router, is create an Interface List Entry so that we can statically set an interface to be used in firewall rules. It is then referenced/selectable in the Profile setting for L2TP. The equivalent to this on the Client Router is the name of the L2TP client itself (default is l2tp-out1 and in our case we are using l2tp-to-RB4011).
The two addresses we set on the Server Router, under PROFILE, for local and remote addresses are internal dynamic addresses assigned to both interfaces and are KEY as they can be used for gateway IP addresses in Routes! We ensure that the User Name on the Secrets setting on the server router matches the Client Name on the l2tp client router settings.
To connect the L2TP tunnel to Wireguard we set on the L2TP client on the connection selection, the wireguard IP address of the the server router and we set on the source address selection, the IP address of the local Wireguard interface. Since the wireguard tunnel is already established the L2TP tunnel is now piggybacking through it.
.............
/RB4011
/interface list
add name=LT2P-Interface
/interface l2tp-server server
set enabled=yes mrru=1504
/ppp profile
add interface-list=LT2P-Interface local-address=172.16.5.2 name=L2TP-Server remote-address=172.16.5.5
/ppp secret
add name= l2tp-to-RB4011 password=site1 profile=L2TP-Server service=l2tp
/ip firewall filter { input chain }
add action=accept chain=input comment="Allow L2TP Client to RB4011" dst-port=1701 protocol=udp  in-interface=wireguard-home
...

L2TP Client (RBG)
....
/RB450G
/interface l2tp-client
add connect-to=192.168.50.1 mrru=1504 name=l2tp-out1 password=site1 src-address=192.168.50.2 user=l2tp-to-RB4011

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

RB4011 Changes/Additions

1 - Allow initiating L2TP traffic from client router to reach and connect to the L2TP Router Service, as per the input chain rule shown.

2. - Allow Subnet A (from client) to reach Subnet Y on Local Router
add chain=forward action=accept in-interface-list=L2TP_Interface src-address=10.10.20.0/24 dst-address=192.168.20.0/24

3.- Allow Subnet B (from client) to reach internet on Local Router
add chain=forward action=accept in-interface-list=L2TP_Interface src-address=10.10.10.0/24 out-interface-list=WAN

4. - Allow admin on Local Router to enter tunnel to later config client Router
add chain=forward action=accept src-address=192.168.10.15 out-interface-list=L2TP_Interface

5. Create Necessary Routes for traffic into the L2TP Tunnel
add dst-address=10.10.20.0/24 gwy=172.16.5.2 table=main
add dst-address=10.10.10.0/24 gwy=172.16.5.2 table=main

Note: The admin will be able to access the client router for config purposes using an existing route (for ex. 10.10.20.1:XXX where XXX=winbox port) and no separate routing is required.

RB450G Changes/Additions

6. Allow admin from RB4011 to exit tunnel to configure client router
add chain=input action=accept in-interface=l2tp-to-RB4011 src-address=192.168.10.15 dst-port=winbox_port protocol=udp

7. Allow Subnet A to enter the tunnel to access the Server Subnet
add chain=forward action=accept src-address=10.10.20.0/24 dst-address=192.168.20.0/24 out-interface=l2tp-to-RB4011

8. Allow Subnet B to enter the tunnel to access the internet on the Server WAN
add chain=forward action=accept src-address=10.10.10.0/24 out-interface=l2tp-to-RB4011

9. Create the necessary Routes etc. for traffic to RB4011
add dst-address=192.168.20.0/24 gwy=172.16.5.5 table=main
add dst-address=192.168.10.15 gwy=172.16.5.5 table=main

10. For the internet Bound Traffic.
/routing table add name=useL2TP fib
/routing rule dst-address=10.10.20.0/24 action=lookup table=main {optional, in case you want subnet B to be able to reach subnet A and not go out internet }
/routing rule src-address=10.10.10.0/24 action=lookup-only-in-table table=useL2TP
/ip route add dst-address=0.0.0.0/0 gwy=L2TP-client table=useL2TP

Done! Confirm the LT2P tunnel is established by checking on the RB4011 under Secrets for L2TP Client if the local and remote address are now populated.

The challenge to the reader is that you can selectively choose what traffic you want to go through both tunnel interfaces or just the wireguard tunnel interface.
In other words, you can selectively decide which traffic goes through L2TP, and just stick to the standard wireguard tunnel for the rest of the traffic.
For example in the above case, ONLY the subnetB heading out the internet of the Server Router has to really go through the L2TP tunnel.

================================================================================================
(15) SCENARIOS

TOC:
Scenario 1 - (HARD) Traversing Two Wireguard Interfaces on one Router and Third Party VPN
Scenario 2 - (MEDIUM) Initiating a Wireguard tunnel from Both Sites
Scenario 3 - (EASY) Initiating a Tunnel From One Site to Allow Traffic in the Opposite Direction.
Scenario 4 - (MEDIUM) Peer to Peer tunnelling with one Wireguard interface & Use of IP addresses for Wireguard interfaces.
Scenario 5 - (MEDIUM) ADGUARD Through WG
Scenario 6 - (HARD) PORT FORWARD TO CGNAT CLIENT
================================================================================================

SCENARIO-1:
............
Scen1.jpg
...........

I have two sets of users coming from the internet through my Local MT Router. One is a subnet from a Remote MT Router 10.1.10.0/24 and the other is an IPHONE user, which we will assign an IP of 172.16.1.2/32. The remote subnet should be able to access my Local MT Router for internet access only. The Iphone user should be able to access my subnet 192.168.50.0/24 but also use an existing vpn connection through 3rd Party Wireguard provider called BiteMe for internet. I want one of my subnets on my Local MT Router 192.168.20.0/24 to go out the third party provider for internet as well. I want to be able to config the Remote Router from my admin PC, 192.168.10.15/32 and the winbox port on the Remote Router is 6969
As an aside, to access the Remote MT router by winbox, via wireguard, one needs to use any Remote Router local Ip address and thus I like to choose the IP address of one of the subnets (a trusted subnet for example). Lets say the trusted subnet of the home-lan at the remote site is 10.1.50.0/24.

Construct the Wireguard Network Primary
LOCAL WG Router - add address=172.16.1.1/24
REMOTE WG Router - add address=172.16.1.3/24
IPHone device - add address=172.16.1.2/32

Identify the Third Party VPN Network
add address=10.10.10.20/24 - LOCAL ROUTER

LOCAL ROUTER WIREGUARD INTERFACE1 (Server for establishing tunnel with Remote Router)
Wireguard Settings
name=WG-Local
listening port=15555
public key generated= xxx (to be used on both iphone and Remote Router peer addresses)

Peer Settings - Applicable for Remote Router
allowed IPs (addresses)=172.16.1.3/32, 10.1.10.0/24 ( the first address is the wireguard ID for the remote router (allows admin to ping the router or access router for config purposes), and the other is the incoming remote subnet)
public key=yyy (from Remote Router)

Peer Settings - Applicable for Iphone
allowed IPs (addresses)=172.16.1.2/32 ( traffic from this IP will be allowed to exit the tunnel at the Local Router )
public key=iii (from iphone)

---------------------------------------------------------------------------

LOCAL ROUTER WIREGUARD INTERFACE 2 (Client for establishing tunnel to third party)
Wireguard Settings
name=WG-BiteMe
listening port=n/r
public key generated= ccc (to be given to BiteMe, unless BiteME provides a private key to use as my private key for this interface and thus they will have the public key)

Peer Settings
allowed IPs (addresses)=0.0.0.0/0 ( this will match and select all internet bound traffic, that should go through the vpn provider, to enter the tunnel )
endpoint address= publicIP address provided by BiteMe
endpoint port=port provided by BiteMe
public key=ddd ( public key provided by BiteMe )
persistent keep alive= 40 secs

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

REMOTE ROUTER
Wireguard Settings
name=WG-Remote
listening port=15555
public key generated= yyy

Peer Settings
allowed IPs=0.0.0.0/0 (this will match and select all internet bound traffic, that should enter the tunnel at the remote router and exit at the Local Router and use its public WANI,P and in addition includes also any subnets remote router users may want to visit on the local route and any incoming admin traffic to config the remote router )
public key=xxx (From Local Router)
persistent keep alive=30 secs

IPHONE
Wireguard Settings
name=mywg
address=172.16.1.2/32
public key generated=iii
DNS Servers= 1.1.1.2, 9.9.9.9

Peer Settings
allowed IPs=0.0.0.0/0 (to eventually access the BiteMe wireguard tunnel, and allows subnet access on the Server Router or config both routers)
public key=xxx (From router)

===================================================================================================
ROUTER SETTINGS - ROUTES

LOCAL ROUTER (Server)

IP Routes ( assumes there is a Local WANIP route alread: dst-address=0.0.0.0/0 gwy=ISP table=main )
<dac> dst-address=172.16.1.0/24 gwy=WG-Local table=main {auto generated by router and ensures all iphone data and any pinging between wireguard devices is routed}
dst=10.1.10.0/24 gwy=WG-Local table=main { ensures return traffic (replies) gets routed back to the subnet user(s) via the tunnel }
dst=0.0.0.0/0 gwy=WG-BiteMe table=useBM { to be used by LOCAL subnet 192.168.20.0/24 and IPhone user }

/routing rule (order is important)
add action=lookup-only-in-table dst-address=192.168.50.0/24 table=main { ensures iphone traffic fore example, for shared devices is captured prior to other rules }
add action=lookup-only-in-table src-address=192.168.20.0/24 table=useBM { ensures local subnet users enter tunnel for 3rd party VPN provider internet}
add action=lookup-only-in-table src-address=172.16.1.2/32 table=useBM {ensures Iphone enters tunnerl for 3rd party VPN}

/routing table add name=useBM fib

SourceNAT - Required to satisfy the thirdparty VPN provider which is only expecting traffic from 10.10.10.20 !!, thus need
add action=masquerade chain=srcnat out-interface=WG-BiteMe

REMOTE ROUTER

IP Routes ( assumes a standard ISP route already exists dst-address=0.0.0.0/0 gwy=ISP table=main )
dst-address=0.0.0.0/0 gwy=WG-Remote table=useWG { to force subnet into tunnel }
/routing rule
add action=lookup-only-in-table src-address=10.0.1.0/24 table=useWG
/routing table add name=useWG fib

ROUTER SETTING - FIREWALL RULES

LOCAL ROUTER(server)
/input chain
add chain=input action=accept dst-port=15555 protocol=udp { if applicable assumes ISP router is port forwarding 15555 to the WANIP of the MT Router }
...
add chain=input action=drop
/forward chain
add chain=forward action=accept in-interface=WG-Local out-interface=WG-BiteMe src-address=172.16.1.2/32
add chain=forward action=accept in-interface=WG-Local src-address=10.0.1.0/24 out-interface-list=WAN
add chain=forward action=accept src-address=192.168.20.0/24 out-interface=WG-BiteMe
...
add chain=forward action=drop

REMOTE ROUTER
/input chain
add chain=input action=accept in-interface=WG-Remote scr-address=192.168.10.15/32 { allow admin access to config }
...
add chain=input action=drop

/forward chain
add chain=forward action=accept src-address=10.1.10.0/24 out-interface=WG-Remote
....
add chain=forward action=drop
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

SCENARIO-2: - https://www.procustodibus.com/blog/2020 ... -wireguard

This is a simpler scenario, WHERE USER 1A, needs to wireguard tunnel to an HTTP SERVER 1B .
This scenario also demonstrates a situation where both MT devices have either a public reachable IP address or private IP where one can port forward from the ISP modem/router. This approach will support any situation where the tunnels are not operating for some reason and either side can initiate the tunnel for their needs. I have thus added to the linked scenario, a reverse requirement where a USER (2B) on Router B, needs to access an HTTPS server (2A) on Router A.
.....
.....

ROUTER A -------------------------------------------------------- ROUTER B
1A- 192.168.1.11 USER on subnet 192.168.1.0/24 ... 1B- 192.168.200.22 Server on subnet 192.168.200.0/24
2A- 192.168.5.3 Server on subnet 192.168.5.0/24 ..... 2B- 192.168.60.7 User on subnet 192.168.60.0/24

Lets Construct the Wireguard Networks
Router A - add address=10.10.10.1/24
Router B - add address=10.10.10.2/24

ROUTER A CONFIG

INTERFACE
Interface Name = WG-A
ListenPort = 51841
Public Key Generated --> To be entered on peer settings Router B

PEERS
PublicKey ---> to be entered is from Router B
Endpoint = 203.0.113.2: ( we need endpoint information from Router B here if router A needs to originate the tunnel )
Endpoint port = 51822 [/b]
Allowed IPs=10.10.10.2, 192.168.200.22,192.168.60.7 { first to allow pinging, second for dst traffic, third for remote incoming traffic }
keep alive=25 seconds ( needed if originating the tunnel )

IP FIREWALL RULES -
add chain=input action=accept dst=port=51841 protocol=udp
add chain=forward action=accept src-address=192.168.60.7 dst-address=192.168.5.3 dst-port=443 in-interface=WG-A
add chain=forward action=accept src-address=192.168.1.11 dst-address=192.168.200.22 dst-port=80 out-interface=WG-A



IP ROUTES

dst-address=192.168.60.7/32 gwy=WG-A table=main ( ensures replies from Server 2A go back through the tunnel to user 2B )
dst-address=192.168.200.22/32 gwy=WG-A table=main ( ensures local user get sent out tunnel to Router B )

Note: The wireguard interface WG-A and also on the other router WG-B, can be identified/selected on interface list members but cannot be added to a bridge!

ROUTER B CONFIG

INTERFACE
Interface Name = WG-B
ListenPort = 51822[/b]
Public Key Generated--> To be entered on peer settings Router A

PEERS
PublicKey ---> to be entered is from Router A
Endpoint = mynetname-Router_A: ( Router A has a private IP and a dyndns name is required for example )
Endpoint port = 51841
Allowed IPs=10.10.10.1/32, 192.168.5.3/32,192.168.1.11/32
keep alive=30 secs

IP FIREWALL RULES -
add chain=input action=accept dst=port=51822 protocol=udp
add chain=forward action=accept src-address=192.168.1.11 dst-address=192.168.200.22 dst-port=80 in-interface=WG-B
add chain=forward action=accept src-address=192.168.60.7 dst-address=192.168.5.3 dst-port=443 out-interface=WG-B


IP ROUTES
dst-address=192.168.1.11/32 gwy=WG-B table=main ( ensures replies from Server 1B go back through the tunnel to user 1A )
dst-address=192.168.5.3/32 gwy=WG-B table=main ( ensures local user gets sent through the tunnel to Router A)

Admin access to config remote router from local router. - If this is desired then one would have to add either the subnet in allowed IPs that the incoming admin is located upon ( easy if its hte same subnet you already have one user coming in on, or the individual's subnet IP. A corresponding input chain firewall rule will also be needed to allow that IP, to access winbox.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

SCENARIO-3:

This is a basic scenario where Site B has an MT Map behind an ISP router, with no access to the ISP Router ( to forward ports or create routes ). The admin, located at Site A, needs to accomplish two functions at Site B: a. to access a certain device on the Map LAN subnet and b. to be able to configure the Map remotely. To accomplish this we are going to have to establish the tunnel with the Map at Site B being the initiating Client device and the MT Router at Site A to be the receiving Server device. In other words we are establishing the tunnel in one direction but all the data traffic will originate at Site A and thus flow in the opposite direction. To make it slightly more interesting, the Site A MT Router (wireguard server) is also behind an ISP router. We are limited by this but we can port forward the listening port to the MT Router. The Map is also interesting. In this example it has no LAN subnet, it simplly bridges the LANIP subnet from the ISP router to ether 2 and other ports.
.....
example3.JPG
.....

Configure the Wireguard Networks
WG-SiteA - add address=10.20.30.1/24
WG-SiteB - add address=10.20.30.2/24

ROUTER A CONFIG

INTERFACE
Interface Name = WG-SiteA
ListenPort = 8090
Public Key Generated --> To be entered on peer settings Router B

PEERS
PublicKey ---> to be entered is from Router B
Allowed IPs =10.20.30.2, 172.18.1.0/24 { the first to be able to ping the map and the second for a target device on the remote LAN }
We set the LAN as an allowed IP in case the admin or users may wish to access other devices on the remote LAN.

IP FIREWALL RULES
add chain=input action=accept dst=port=8090 protocol=udp { for initial connection from Router B } ( this will be port forwarded on the ISP router to the Routers OS VM, 192.168.1.250 )
add chain=input action=accept dst-port=winbox src-address=LANIPof Admin
add chain=forward action=accept src-address=192.168.0.0/24 out-interface=WG-SiteA { to allow admin and if necessary various users to Router B }

IP ROUTES
<dac> dst-address=10.20.30.0/24 gwy=WG-A table=main { auto generated by router }
dst-address=172.18.1.0/24 gwy=WG-A table=main { traffic heading for Router B will get pushed into the tunnel }

IP Cloud: mynetnameWGSite-A

ROUTER B CONFIG

INTERFACE
Interface Name = WG-B
ListenPort = 80902 { not really required }
Public Key Generated--> To be entered on peer settings Router A

PEERS
PublicKey ---> to be entered is from Router A
Endpoint =mynetnameWGSite-A: ( Router at Site A has a private IP and a dyndns name is required for example )
Endpoint port = 8090
Allowed IPs=10.20.30.0/24, 192.168.0.0/24 {allows pinging of other wg devices and second to allow incoming users to exit the tunnel }
keep alive=30 secs

IP FIREWALL RULES - { need to allow users to access device and admin to access router }
add chain=input action=accept in-interface=WG-B adminLANIP dst-port='winboxport { allows admin from Site A with IP 192.168.0.x, to access MAP device }
add chain=forward action=accept in-interface=WG-B src-address=192.168.0.0/24 dst-address=172.18.1.22/32 { allow remote access to local server }

IP ROUTES
<dac> dst-address=10.20.30.0/24 gwy=WG-B table=main { auto generated }
dst-address=192.168.0.0/242 gwy=WG-B table=main { ensures replies from SiteB go back through the tunnel to Site A users }

====================================================
What is not covered/dicussed above is how to set MAP for bridging of LAN to all ports. The MAP needs only a few settings.
...............
/interface bridge
add ingress-filtering=no name=bridgemap
/interface list
add name=management
/interface bridge port
add bridge=bridgemap interface=ether1
add bridge=bridgemap  interface=ether2
add bridge=bridgemap  interface=ether3
add bridge=bridgemap interface=WLAN
/ip neighbor discovery-settings
set discover-interface-list=management
/interface list member
add interface=bridgemap list=management
/ip address
add address=172.18.1.28/24 interface=bridgemap network=172.18.1.0
/ip dns
set allow-remote-requests=yes servers=172.18.1.1 comment="dns through trusted subnet gateway
/ip route
add disabled=no dst-address=0.0.0.0/0 gateway=172.18.1.1 comment="ensures route avail through trusted subnet gateway"
/ip service
set winbox address=172.18.1.xx,192.168.0.x comment="local and remote winbox access"
/tool mac-server mac-winbox
set allowed-interface-list=management
....

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

SCENARIO-4:

This is an interesting scenario where the admin can access Site A (publicly available WANIP) but cannot access Site B. The admin does not work from either site and must use a laptop/smartphone to connect to the Routers. The admin wants to be able to config both Routers and he wants to be able to reach a Server at Site B (10.0.1.44). The users at Site B (subnet 10.0.1.0/24) also need to use Site A for all internet traffic.

Admin Requirements:
Needs access to site A, in order to config Router A (which has a public IP and is thus reachable).
Needs access to site B, in order to config Router B and reach a Server on Router B (which is not reachable, not a public IP and has no control/access to ISP router),
Hence, the configs must allow the admin to reach Router B FROM Router A.

User Requirements:
Users at site B must use Site A for all internet.
....
STEP1: Design the WG interface network.
/ip address
add address=172.16.0.1/24 interface=wg-server network=172.16.0.0 {Router A}
add address=172.16.0.2/32 ( wg address on admin laptop (or smartphone etc)
add address=172.16.0.3/24 interface=wg-client network=172.16.0.0 {Router B}

.....
STEP2: ROUTER A CONFIG

Router A WG Interface & Peer Interface

Interface Name = wg-server
ListenPort = 6868
Public Key Generated --> To be entered on peer settings Router B and peer setttings on admin (laptop or smartphone)

PEERS
Peer1 (Router B)
PublicKey ---> to be entered is from Router B
Allowed IPs=10.0.1.0/24,172.16.0.3/32 - remote subnet from Router B exitiing the tunnel, and RouterBs, wireguard address

Peer2 ( admin )
Public Key ---> to be entered from admin laptop (or smartphone)
Allowed IPs=172.16.0.2/32 - admin device exiting the tunnel to reach server on Router A, config Router A, to get relayed to Router B for config and reach server on Router B

Router A IP FIREWALL RULES
add chain=input action=accept dst=port=6868 protocol=udp { for initial connection by admin devices and Router B }
add chain=input action=accept dst-port=WINBOXPORT in-interface=wg-server src-address=172.16.0.2/32 { access by admin to config Router A }
***add chain=forward action=accept in-interface=wg-server out-interface-list=WAN src-address=10.0.1.0/24 { allows Remote site users to access internet through Main router }
add chain=forward action=accept src-address=172.16.0.2 dst-address=10.0.1.0/24 out-interface=wg-server { allows admin after exiting the tunnel to re-enter the tunnel heading for the other peer if heading to the other Peers valid subnet! Note: that we will use the firewall rules at Router B to specify which IPs if required/desired }

***Alternate Option: add wg-server to interface list = LAN, in that way Router B subnet users will not require a separate wg forward chain lan to wan rule, as they can use the existing default rule:
add chain=forward action=accept in-interface-list=LAN out-interface-list=WAN

IP ROUTES General -
Note: Since you have IP addresses assigned to the Wireguard Interfaces (as per Step 1), the router automatically creates a routing for wireguard network traffic on both Routers A, B,
<dac> dst-address=172.16.0.0/24 gwy=wg-server table=main (router A)
<dac> dst-address=172.16.0.0/24 gwy=wg-client table=main (router B)

In effect this means we do NOT need to create any routes for pinging via wireguard addresses and more importantly, for any single clients (road warriors) assigned a single wireguard IP address.
HOWEVER, we do need to create routes for remote subnets that visit a local router to let the router know where the return traffic (be it from the internet, or from local servers) needs to go as those subnets are not native to the local router.

Router A Routes......
add dst=10.0.1.0/24 gwy=wg-server table=main


STEP3 ROUTER B CONFIG

INTERFACE
Interface Name = wg-client
ListenPort = 6868 (not really required }
Public Key Generated--> To be entered on peer settings Router A

PEERS
PublicKey ---> to be entered is from Router A
Endpoint = mynetname-Router_A: ( Router A has a public dynamic IP )
Endpoint port = 6868
Allowed IPs=0.0.0.0/0 ( includes, internet addresses, the wireguard address and not in this case but any subnets on Router A)
keep alive=30 secs

IP FIREWALL RULES - { need to allow admin to access Router and Server on Router B }
add chain=input action=accept in-interface=wg-client src-address=172.16.0.2 dst-port=winboxport
add chain=forward action=accept in-interface=wg-client rc-address=172.168.0.2 dst-address=IPofServer
Note: If the admin wanted access to the whole LAN subnet - dst-address=10.0.1.0/24.

IP ROUTES In this case the challenge is to ensure all subnet users enter the wg for internet and not the local WAN on Router B.
This is a three step process (create table, add an additional route, and add the associated wireguard rule~

/routing table add fib name=useWG
dst-address=0.0.0.0/0 gwy=wg-client table=useWG
/routing rule add action=lookup-only-in-table src-address=10.0.1.0/24 table=useWG


Note: If you wanted local subnet users to be able to access the local WAN if the wireguard internet was not available then change to "action=lookup"No other routes are required as the IP address (see below) for the wireguard interface will automatically route replies from the admin back through the tunnel.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

SCENARIO-5:

In this scenario, we have an MT Router that has TWO wireguard interfaces, a Wireguard Remote (WG-R) interface ( to access the router remotely ) and Third Party Wireguard ( WG-3P ), which is what all subnets behind the RB should use except for one subnet. In addition, a raspberry PI is on one of the VLANs going out the WG-3rdP. Besides wireguard, which is pretty straightforward in terms of needing a table, a route and some routing rules, the additional headache of using adguard which is going out the tunnel is fun. In addition, users on one of the outgoing subnet also needs access to a printer on another subnet.
Subnets are vlan10,vlan20,vlan30 and the one subnet that will use local internet is vlan40. If wireguard does go down then all the subnets should revert to local internet. The admin will use his other wireguard interface, to remotely connect to the router and access the adguard server to RE-AIM the adguard to a reachable DNS.
........
# model = MT Device
/interface bridge
add ingress-filtering=no name=Bridge vlan-filtering=yes
/interface ethernet
set [ find default-name=ether5 ] name=ether5-emerg
/interface wireguard
add listen-port=14221 mtu=1420 name=WG-R
/interface vlan
add interface=Bridge name=VLAN10-LAN vlan-id=10
add interface=Bridge name=VLAN20-IoT vlan-id=20
add interface=Bridge name=VLAN30-Guest vlan-id=30
add interface=Bridge name=VLAN40-NoVPN vlan-id=40
/interface list
add comment=defconf name=WAN
add comment=defconf name=LAN
add name=MGMT  { used to ensure all smart devices are on the same isolated VLAN }
/ip pool
add name="DHCP VLAN20" ranges=10.0.20.150-10.0.20.254
add name="DHCP VLAN30" ranges=10.0.30.150-10.0.30.254
add name="DHCP VLAN10" ranges=10.0.10.100-10.0.10.254
add name="DHCP VLAN40" ranges=10.0.40.150-10.0.40.200
/ip dhcp-server
add address-pool="DHCP VLAN20" interface=VLAN20-IoT lease-time=1d name=\
    "DHCP VLAN20"
add address-pool="DHCP VLAN30" interface=VLAN30-Guest lease-time=1d name=\
    "DHCP VLAN30"
add address-pool="DHCP VLAN10" interface=VLAN10-LAN lease-time=1d name=\
    "DHCP VLAN10"
add address-pool="DHCP VLAN40" interface=VLAN40-NoVPN lease-time=1d30m name=\
    DHCP-VLAN40
/routing table
add disabled=no fib name=use-WG
/interface bridge port
add bridge=Bridge ingress-filtering=yes frame-types=admit-only-vlan-tagged interface=ether2  { trunk port to smart switch }
add bridge=Bridge ingress-filtering=no interface=ether3 pvid=10 { hybrid port to AP } 
add bridge=Bridge ingress-filtering=no interface=ether4 pvid=10  { hybrid port to AP }
add bridge=Bridge ingress-filtering=yes frame-types=admit-only-untagged-and-priority-tagged interface=ether6 pvid=20 { access port }
add bridge=Bridge ingress-filtering=yes frame-types=admit-only-untagged-and-priority-tagged interface=ether7 pvid=10  { access port }
/interface bridge vlan
add bridge=Bridge tagged=Bridge,ether2 untagged=ether3,ether4,ether7 vlan-ids=10
add bridge=Bridge tagged=Bridge,ether2,ether3,ether4 untagged=ether6 vlan-ids=20
add bridge=Bridge tagged=Bridge,ether3,ether4 vlan-ids=30
add bridge=Bridge tagged=Bridge,ether2,ether3,ether4 vlan-ids=40
/ip firewall connection tracking
set loose-tcp-tracking=no
/ip neighbor discovery-settings
set discover-interface-list=MGMT
/ip settings
set rp-filter=loose
/ipv6 settings
set disable-ipv6=yes
/interface list member
add interface=ether1 list=WAN
add interface=VLAN10-LAN list=LAN
add interface=VLAN20-IoT list=LAN
add interface=VLAN30-Guest list=LAN
add interface=VLAN40-NoVPN list=LAN
add interface=ether5-emerg list=LAN
add interface=VLAN10-LAN list=MGMT  { trusted subnet }
add interface=WG-R list=MGMT
add interface=ether5-emerg list=MGMT
/interface wireguard peers
add allowed-address=192.168.0.2/32 interface=WG-R public-key="..."  { admin laptop remote }
add allowed-address=192.168.0.3/32 interface=WG-R public-key="..."   { admin smartphone remote }
add allowed-address=0.0.0.0/0 endpoint-address=123.456.789.12 endpoint-port=\  { to Third Party Server }
    42740 interface=WG-3P persistent-keepalive=35s public-key="..."
/ip address
add address=10.0.10.1/24 interface=VLAN10-LAN network=10.0.10.0
add address=10.0.20.1/24 interface=VLAN20-IoT network=10.0.20.0
add address=10.0.30.1/24 interface=VLAN30-Guest network=10.0.30.0
add address=10.0.40.1/24 interface=VLAN40-NoVPN network=10.0.40.0
add address=192.168.55.1/24 interface=ether5-emerg network=192.168.55.0
add address=192.168.0.1/24 interface=WG-R network=192.168.0.0
add address=10.45.77.12/24 interface=wg-3P network=10.45.77.0
/ip dhcp-client
add add-default-route=no dhcp-options=clientid,hostname interface=ether1\
/ip dhcp-server network
add address=10.0.10.0/24 dns-server=10.0.10.8 gateway=10.0.10.1   { raspberry PI adguard ip=10.0.10.8, since dns-server is not 10.0.10.1 dont need hairpin nat rule }
add address=10.0.20.0/24 dns-server=10.0.10.8  gateway=10.0.20.1 
add address=10.0.30.0/24 dns-server=10.0.10.8  gateway=10.0.30.1  
add address=10.0.40.0/24 dns-server=10.0.40.1 gateway=10.0.40.1
/ip dns
set allow-remote-requests=yes servers=public-server-of-choice use-doh-server=\  { vlan40 goes out local DOH dns }
    https://your-doh-server-of-choice verify-doh-cert=yes
/ip firewall address-list
add address=Local-IP1-on-Vlan10  list=AllowWinBox   { admin desktop }
add address=Local-IP2-on-Vlan10 list=AllowWinBox  { admin smartphone }
add address=192.168.55.55 list=AllowWinBox { off bridge access }
add address=192.168.0.0/24 list=AllowWinBox  { admin can remote in to Router via WG-R }
add address=10.0.10.8  list=Excluded  { so adguard server is excluded from dstnat rule }
add address=10.0.40.0/24 list=Excluded  { so vlan40 subnet is excluded from dstnat rule }
add address=192.168.0.0/24 list=Excluded  { so admin remote traffic via WG  is excluded from dstnat rule }
/ip firewall filter
add action=accept chain=input comment=\
    "defconf: accept established,related,untracked" connection-state=\
    established,related,untracked
add action=drop chain=input comment="defconf: drop invalid" connection-state=\
    invalid
add action=accept chain=input comment="defconf: accept ICMP" protocol=icmp
add action=accept chain=input comment=\
    "defconf: accept to local loopback (for CAPsMAN)" dst-address=127.0.0.1
add action=accept chain=input comment=WireGuard dst-port=14221 protocol=udp
add action=accept chain=input comment="Allow Admin to Router" \
    src-address-list=AllowWinBox
add action=accept chain=input comment="Allow Users DNS TCP" dst-port=53 \
    in-interface-list=LAN protocol=tcp
add action=accept chain=input comment="Allow Users DNS  UDP" dst-port=53,123 \
    in-interface-list=LAN protocol=udp
add action=accept chain=input comment="DNS TCP for wg-remote" dst-port=53 \  { Allow remote user access to DNS on router }
    in-interface=WG-R protocol=tcp
add action=accept chain=input comment="DNS UDP for wg-remote" dst-port=53 \  { Allow remote user access to DNS on router }
    in-interface=WG-R protocol=udp
add action=drop chain=input comment="Drop all else"
add action=fasttrack-connection chain=forward comment="defconf: fasttrack" \
    connection-state=established,related hw-offload=yes
add action=accept chain=forward comment=\
    "defconf: accept established,related, untracked" connection-state=\
    established,related,untracked
add action=drop chain=forward comment="defconf: drop invalid" \
    connection-state=invalid
add action=accept chain=forward in-interface-list=LAN out-interface=WG-3P  { allows users into tunnel }
add action=accept chain=forward comment="Allow Local Internet Traffic" \
    in-interface-list=LAN out-interface-list=WAN
add action=accept chain=forward comment="Local Internet for wg-remote" \
    in-interface=WG-R out-interface-list=WAN
add action=accept chain=forward comment="Admin to all VLANS" \
    out-interface-list=LAN src-address-list=AllowWinBox
add action=accept chain=forward comment="WG/Admin to all VLANS" in-interface=\
    WG-R out-interface-list=LAN
add action=accept chain=forward comment="Allow access to print from VLAN30" \  { common  printer on vlan10 - 10.0.10.13 }
    dst-address=10.0.10.13 src-address=10.0.30.0/24
add action=accept chain=forward comment="Allow all users to Adguard" \
    dst-address=10.0.10.8 in-interface-list=LAN
add action=drop chain=forward comment="Drop all else"
/ip firewall mangle
add action=change-mss chain=forward new-mss=clamp-to-pmtu out-interface=\  { may not be required }
    WG-3P passthrough=yes protocol=tcp tcp-flags=syn
/ip firewall nat
add action=masquerade chain=srcnat out-interface=WG-3P  { All user traffic assigned client wg-r IP address }
add action=masquerade chain=srcnat comment="defconf: masquerade" \
    ipsec-policy=out,none out-interface-list=WAN
add action=dst-nat chain=dstnat comment="Force User out Adguard tcp" \
    dst-port=53 in-interface-list=LAN protocol=tcp src-address-list=!Excluded \
    to-addresses=10.0.10.8
add action=dst-nat chain=dstnat comment="Force User out Adguard udp" \
    dst-port=53 in-interface-list=LAN protocol=udp src-address-list=!Excluded \
    to-addresses=10.0.10.8
/ip firewall service-port
set ftp disabled=yes
set tftp disabled=yes
set h323 disabled=yes
set sip disabled=yes
set pptp disabled=yes
/ip route
add disabled=no distance=1 dst-address=0.0.0.0/0 gateway=ISPgatewayIP \
    pref-src="" routing-table=main scope=30 suppress-hw-offload=no \
    target-scope=10
add disabled=no dst-address=0.0.0.0/0 gateway=WG-3P routing-table=\
    use-WG suppress-hw-offload=no
/ip service
set telnet disabled=yes
set ftp disabled=yes
set www disabled=yes
set ssh disabled=yes
set api disabled=yes
set winbox port=XXXXXX
set api-ssl disabled=yes
/routing rule
add action=lookup-only-in-table disabled=no dst-address=10.0.0.0/16  src-address=10.0.0.0/16 table=main \ { Ensures any permitted local traffic between vlans 10,20,30,40 occurs vice being sent out tunnel }
add action=lookup-only-in-table comment="return traffic to wg-remote" disabled=no dst-address=192.168.0.0/24 src-address=10.0.0.0/16 table=main \  { Ensures any remote Admin wg-r traffic to Vlans is returned and does not go out tunnel }
add action=lookup disabled=no src-address=10.0.10.0/24 table=use-WG  { action=lookup means router will go to table main in case use-WG is not available }
add action=lookup disabled=no src-address=10.0.20.0/24 table=use-WG
add action=lookup disabled=no src-address=10.0.30.0/24 table=use-WG
/system ntp client
set enabled=yes
/system ntp client servers
add address=ca.pool.ntp.org
/tool mac-server
set allowed-interface-list=none
/tool mac-server mac-winbox
set allowed-interface-list=MGMT
.....

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

SCENARIO-6:

In this scenario we have a REMOTE MT router with only a CGNAT type internet connection ( lets say Starlink ). Behind this router we will have two subnets, one for local internet and one that contains a control device of some sort which will be tunnel accessible. VLANs 10 and 20. The other MT device is local to the admin and is behind another Brand Puke Name Router but we can forward ports and it has a publicly accessible IP. Lets say the other MT device is a hex router. Here comes the tough part, the control device is accessed via an AP.
Thus users have to access the IP of the Public IP on Brand Name router on a specific port. This port will be key to port forwarding from the HEX router into the wireguard tunnel.

Enjoy...............
You do not have the required permissions to view the files attached to this post.
Last edited by anav on Sun Dec 03, 2023 6:46 pm, edited 307 times in total.
 
Sob
Forum Guru
Forum Guru
Posts: 9185
Joined: Mon Apr 20, 2009 9:11 pm

Re: Planning Your WIREGUARD CONNECTION!

Tue Jan 18, 2022 4:02 am

You should make it clearer that the whole business with another routing table is only needed (unless you're doing something special) when you want to use the tunnel to access internet (i.e. with 0.0.0.0/0). If it's simple site to site, LAN to LAN, route in main routing table to remote LAN is enough.
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 18168
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Planning Your WIREGUARD CONNECTION!

Tue Jan 18, 2022 1:52 pm

.....................
Last edited by anav on Sun Mar 13, 2022 4:36 am, edited 1 time in total.
 
msatter
Forum Guru
Forum Guru
Posts: 2887
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

Re: Planning Your WIREGUARD CONNECTION!

Tue Jan 18, 2022 2:19 pm

For connecting to a VPN provider that supports WireGuard you can find here two scripts I wrote. It uses the config files generated or provided by the VPN providers and it will create the WireGuard lines, routing, NAT. You have then decide yourself which traffic can use the VPN by marking the routing in Mangle.

The dynamic script (first one) needs a bit of TLC and on the WG lines itself. As soon I have some more time I will adapt that. That skript is for high-jacking a current WG connection created by a external client connection on a other device.

Link to my posting: viewtopic.php?p=906167
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 18168
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Planning Your WIREGUARD CONNECTION!

Tue Jan 18, 2022 2:23 pm

.......................
Last edited by anav on Sun Mar 13, 2022 4:37 am, edited 2 times in total.
 
User avatar
mozerd
Forum Veteran
Forum Veteran
Posts: 867
Joined: Thu Oct 05, 2017 3:39 pm
Location: Canada
Contact:

Re: Planning Your WIREGUARD CONNECTION!

Tue Jan 18, 2022 3:05 pm

Very Nice work @anav --- many will enjoy it 4 certain ....

BUT but But .... there is ABSOLUTLY no Client/Server relationships using WireGuard .... there is only Peer to Peer and YES each PEER can act like a HUB where other Peers can have orgasmic relationships .... and that is called a sexy MESH .... I do understand that many will want to remain in the Client/Server world because of habitual habits gained from many years of slavery to that concept. So dump the slavery and become FREE to enjoy a true PEER to PEER joining much like men and women do in privacy .... and not like an an orgy clients being served by a Server ... :)
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 18168
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Planning Your WIREGUARD CONNECTION!

Tue Jan 18, 2022 3:47 pm

.....................
Last edited by anav on Sun Mar 13, 2022 4:37 am, edited 1 time in total.
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 18168
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Planning Your WIREGUARD CONNECTION!

Tue Jan 18, 2022 4:13 pm

............................
Last edited by anav on Sun Mar 13, 2022 4:37 am, edited 1 time in total.
 
Zacharias
Forum Guru
Forum Guru
Posts: 3470
Joined: Tue Dec 12, 2017 12:58 am
Location: Greece

Re: Planning Your WIREGUARD CONNECTION!

Tue Jan 18, 2022 4:43 pm

Nice, but you should include configuration examples...
 
User avatar
mozerd
Forum Veteran
Forum Veteran
Posts: 867
Joined: Thu Oct 05, 2017 3:39 pm
Location: Canada
Contact:

Re: Planning Your WIREGUARD CONNECTION!

Tue Jan 18, 2022 5:26 pm

For connecting to a VPN provider that supports WireGuard you can find here two scripts I wrote. It uses the config files generated or provided by the VPN providers and it will create the WireGuard lines,
…… …….
IMO mixing VPN providers with your private WireGuard establishment is not a good idea … it may be convenient but a bad security practice.
one can create multiple WireGuard Interfaces … each can be dedicated to the Purpose intended …
wg_ipvanish
wg_home
etc..
 
Sob
Forum Guru
Forum Guru
Posts: 9185
Joined: Mon Apr 20, 2009 9:11 pm

Re: Planning Your WIREGUARD CONNECTION!

Tue Jan 18, 2022 6:52 pm

.... there is ABSOLUTLY no Client/Server relationships using WireGuard ....
Of course there is, not on protocol level, but for example all these "browse internet through us" VPNs are clearly functioning in client/server mode, you as client are connecting to their server, not the other way.
 
User avatar
own3r1138
Long time Member
Long time Member
Posts: 678
Joined: Sun Feb 14, 2021 12:33 am
Location: Pleiades
Contact:

Re: Planning Your WIREGUARD CONNECTION!

Tue Jan 18, 2022 7:26 pm

@anav
Thank you for the post, I enjoyed reading this.
 
User avatar
mozerd
Forum Veteran
Forum Veteran
Posts: 867
Joined: Thu Oct 05, 2017 3:39 pm
Location: Canada
Contact:

Re: Planning Your WIREGUARD CONNECTION!

Tue Jan 18, 2022 7:43 pm

@Sob
So you want to be picky "eh" and diverge into the client/server model where content served is king "eh"

Not going to cut it with me because Peer's are bidirectional unlike C/S ... however you can choose to look at it in your distinct way. Certainly a Peer has access to content in many forms on a Peer to Peer basis and a Peer can be served by a server residing within the Peer's domain.

What’s the difference between peer-to-peer (P2P) networks and client-server? A good read :)
 
gigabyte091
Forum Veteran
Forum Veteran
Posts: 838
Joined: Fri Dec 31, 2021 11:44 am
Location: Croatia

Re: Planning Your WIREGUARD CONNECTION!

Tue Jan 18, 2022 7:44 pm

@anav

Wow that's really nice post, lots of effort is put into it, I hope this will help a lot of people who also want to setup WG. I can help with practical section, testing various configurations and so on as I have quite a lot mikrotik's routers.
 
Sob
Forum Guru
Forum Guru
Posts: 9185
Joined: Mon Apr 20, 2009 9:11 pm

Re: Planning Your WIREGUARD CONNECTION!

Tue Jan 18, 2022 8:01 pm

@mozerd: I'm just saying that even though Wireguard as protocol is peer to peer, it's not always used that way. You know those VPNs I mentioned, right? Every single client is connecting to their server, no two clients are connecting to each other, because they don't need it, they don't want to communicate with each other. Same for "access to my home NAS" scenario, I may want to do it for multiple devices, but if those devices all need to access only NAS and don't need to communicate with each other, it's again simple client/server. There's no need for any p2p mesh, it would be completely useless, because those devices simply don't need to communicate with each other.
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 18168
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Planning Your WIREGUARD CONNECTION!

Tue Jan 18, 2022 8:11 pm

...........................
Last edited by anav on Sun Mar 13, 2022 4:37 am, edited 1 time in total.
 
Zacharias
Forum Guru
Forum Guru
Posts: 3470
Joined: Tue Dec 12, 2017 12:58 am
Location: Greece

Re: Planning Your WIREGUARD CONNECTION!

Tue Jan 18, 2022 8:14 pm

Keep alive: Set it to something between 20-45 secs for example..
@anav can you elaborate more on this ... ?
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 18168
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Planning Your WIREGUARD CONNECTION!

Tue Jan 18, 2022 8:24 pm

...........................
Last edited by anav on Sun Mar 13, 2022 4:37 am, edited 1 time in total.
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 18168
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Planning Your WIREGUARD CONNECTION!

Tue Jan 18, 2022 8:32 pm

.........................
Last edited by anav on Sun Mar 13, 2022 4:37 am, edited 1 time in total.
 
msatter
Forum Guru
Forum Guru
Posts: 2887
Joined: Tue Feb 18, 2014 12:56 am
Location: Netherlands / Nīderlande

Re: Planning Your WIREGUARD CONNECTION!

Tue Jan 18, 2022 8:37 pm

If routerOS can reconnect to the other side, the keep-alive can be long not needing the connection open all the time.

I have a VPN provider that gives only one-connect-privatekey. If the connection closes due reboot or connection loss, a new private key has to be obtained. For this connection, I use a short keep-alive so that it stays open till the connection is lost or ended by either side.

I rather use reconnect so that when not needed it can be disconnected and reconnected when needed. Takes few seconds or less to do that.
 
Sob
Forum Guru
Forum Guru
Posts: 9185
Joined: Mon Apr 20, 2009 9:11 pm

Re: Planning Your WIREGUARD CONNECTION!

Tue Jan 18, 2022 8:44 pm

It depends on what timeouts other routers with stateful firewalls, that will be in the way, have. If you going to have site to site config with both peers having either public address, or at least forwarded port, you don't need keepalive, because each can contact the other one at any time. But if one peer is going to be behind NAT, with no incoming connections possible, then you want keepalive, to keep the tunnel working even when nothing uses it for a while. The peer behind NAT (client) can always contact server, but from other side it's not possible, so any communication initiated from server's side would have to wait until client connects.

RouterOS has this as default:
udp-timeout (time; Default: 10s) - Specifies the timeout for udp connections that has seen packets in one direction
udp-stream-timeout (time; Default: 3m) - Specifies the timeout of udp connections that has seen packets in both directions
But important is what other routers have, I don't know if there's any standard for it.
 
Zacharias
Forum Guru
Forum Guru
Posts: 3470
Joined: Tue Dec 12, 2017 12:58 am
Location: Greece

Re: Planning Your WIREGUARD CONNECTION!

Wed Jan 19, 2022 8:26 pm

@sob the manual indicates that 25s ok keep alive time for a host behind NAT would benefit the connection...
So am not sure if that relates to the 10s UDP time out...

By the way yesterday i was configuring a wireguard server that is behind a Main Router, so the wireguard port was dst nated to the wireguard server from the main router and ofcorse accepted on input chain on the later... i was keep getting that the handshake for peer did not complete again and again although it was successfully completed if i was connecting to the wireguard server through another VPN just for testing, so it was not a matter of keys or anything... after trying almost everything i just changed the default UDP port of wireguard and to my surprise it worked, the handshake completed... I can only guess the default port was blocked somewhere along the way...
 
Sob
Forum Guru
Forum Guru
Posts: 9185
Joined: Mon Apr 20, 2009 9:11 pm

Re: Planning Your WIREGUARD CONNECTION!

Sun Jan 23, 2022 3:43 am

10s is for "connections" (udp don't really have any) that have packets only in one direction (so no responses). WG will have some packets in both directions, so the timeout will be 3m. And then even packets in one direction should be enough to keep it open. But these are just ROS defaults, other routers may have shorter timeouts.
 
Zacharias
Forum Guru
Forum Guru
Posts: 3470
Joined: Tue Dec 12, 2017 12:58 am
Location: Greece

Re: Planning Your WIREGUARD CONNECTION!

Sun Jan 23, 2022 7:52 pm

ok @sob, good to know that...
But if one peer is going to be behind NAT, with no incoming connections possible, then you want keepalive, to keep the tunnel working even when nothing uses it for a while
So an example of needing keepalive would be road warriors ?
 
holvoetn
Forum Guru
Forum Guru
Posts: 4317
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: Planning Your WIREGUARD CONNECTION!

Sun Jan 23, 2022 7:57 pm

Not sob but Yes.
Or e.g. LTE devices behind cgnat.
 
Zacharias
Forum Guru
Forum Guru
Posts: 3470
Joined: Tue Dec 12, 2017 12:58 am
Location: Greece

Re: Planning Your WIREGUARD CONNECTION!

Sun Jan 23, 2022 8:08 pm

ok...

In case of site to site WG connections, if you don't define the endpoint on both peers but only on one, then is it still true that each peer can reach the other one or not ( in order to keep the tunnel up ) ? How does the peer with no endpoint defined knows who is the peer to contact ?
So, would we still need keepalive in such case ?
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 18168
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Planning Your WIREGUARD CONNECTION!

Sun Jan 23, 2022 8:16 pm

........................
Last edited by anav on Sun Mar 13, 2022 4:38 am, edited 1 time in total.
 
Zacharias
Forum Guru
Forum Guru
Posts: 3470
Joined: Tue Dec 12, 2017 12:58 am
Location: Greece

Re: Planning Your WIREGUARD CONNECTION!

Sun Jan 23, 2022 8:28 pm

My understanding is that the peer keep alive initiated by the client side should keep the tunnel open for two way traffic.
ok, but what if the client for some reason delays to reach the server, then the tunnel will drop.
 
User avatar
mozerd
Forum Veteran
Forum Veteran
Posts: 867
Joined: Thu Oct 05, 2017 3:39 pm
Location: Canada
Contact:

Re: Planning Your WIREGUARD CONNECTION!

Sun Jan 23, 2022 8:36 pm

My understanding is that the peer keep alive initiated by the client side should keep the tunnel open for two way traffic.
Once understood no further info is required as per the following:
https://www.wireguard.com/quickstart/
NAT and Firewall Traversal Persistence
By default, WireGuard tries to be as silent as possible when not being used; it is not a chatty protocol. For the most part, it only transmits data when a peer wishes to send packets. When it's not being asked to send packets, it stops sending packets until it is asked again. In the majority of configurations, this works well.

However, when a peer is behind NAT or a firewall, it might wish to be able to receive incoming packets even when it is not sending any packets. Because NAT and stateful firewalls keep track of "connections", if a peer behind NAT or a firewall wishes to receive incoming packets, he must keep the NAT/firewall mapping valid, by periodically sending keepalive packets.

This is called persistent keepalives. When this option is enabled, a keepalive packet is sent to the server endpoint once every interval seconds. A sensible interval that works with a wide variety of firewalls is 25 seconds. Setting it to 0 turns the feature off, which is the default, since most users will not need this, and it makes WireGuard slightly more chatty. This feature may be specified by adding the PersistentKeepalive = field to a peer in the configuration file, or setting persistent-keepalive at the command line. If you don't need this feature, don't enable it. But if you're behind NAT or a firewall and you want to receive incoming connections long after network traffic has gone silent, this option will keep the "connection" open in the eyes of NAT.
 
Zacharias
Forum Guru
Forum Guru
Posts: 3470
Joined: Tue Dec 12, 2017 12:58 am
Location: Greece

Re: Planning Your WIREGUARD CONNECTION!

Sun Jan 23, 2022 9:03 pm

@mozerd thanks...
But then to my understanding it has to do with site to site connections as well...
 
User avatar
mozerd
Forum Veteran
Forum Veteran
Posts: 867
Joined: Thu Oct 05, 2017 3:39 pm
Location: Canada
Contact:

Re: Planning Your WIREGUARD CONNECTION!

Sun Jan 23, 2022 9:41 pm

But then to my understanding it has to do with site to site connections as well...
Regardless of network topology it’s ALL Peer to Peer, so the key aspects to consider is if NAT and/or Stateful Firewall where connection tracking is used the PersistentKeepalive = should be used ….. I use 25 seconds and that works well for me.
 
Sob
Forum Guru
Forum Guru
Posts: 9185
Joined: Mon Apr 20, 2009 9:11 pm

Re: Planning Your WIREGUARD CONNECTION!

Sun Jan 23, 2022 10:31 pm

Ideal site to site is between two static public addresses (both stay the same and accept incoming connections). If you have that, there's no need for keepalive. Otherwise you probably want it. If one side is behind NAT and can't accept incoming connections, then for sure. And even if it can, but has dynamic address, it's useful, because instead of waiting until some hostname updates to new address, keepalive will notify the other side about changed address earlier.
 
Zacharias
Forum Guru
Forum Guru
Posts: 3470
Joined: Tue Dec 12, 2017 12:58 am
Location: Greece

Re: Planning Your WIREGUARD CONNECTION!

Sun Jan 23, 2022 10:40 pm

@sob i agree...
But since it only transmits data when a peer wants to send a packet, that remains the same whether it is a site to site connection or not...
On a site to site connection you still have a connection tracking table, so i guess the connections will timeout unless keepalive is being set... since nor the client nor the server endpoints will try to reach each other unless data are being requested...
 
holvoetn
Forum Guru
Forum Guru
Posts: 4317
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: Planning Your WIREGUARD CONNECTION!

Sun Jan 23, 2022 10:49 pm

Hence the name " keepalive", no ?
 
Sob
Forum Guru
Forum Guru
Posts: 9185
Joined: Mon Apr 20, 2009 9:11 pm

Re: Planning Your WIREGUARD CONNECTION!

Sun Jan 23, 2022 11:49 pm

I'll make @mozerd happy, there's nothing special about site to site or road warrior, it's always connection between two peers (and then there can be other connections between more peers, but that's not the point here). If peer has behind it just single address, subnet, multiple subnets, it doesn't matter. The only difference is whether both peers are at any time reachable from the other one. That's the case when both have static public addresses and accept incoming connections. Then it doesn't matter if connection times out, because any of them can always open new one.
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 18168
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Planning Your WIREGUARD CONNECTION!

Mon Jan 24, 2022 3:17 am

.......................
Last edited by anav on Sun Mar 13, 2022 4:38 am, edited 1 time in total.
 
Sob
Forum Guru
Forum Guru
Posts: 9185
Joined: Mon Apr 20, 2009 9:11 pm

Re: Planning Your WIREGUARD CONNECTION!

Mon Jan 24, 2022 5:06 am

Right now I can tell you one thing, it desperately needs an image, diagram showing what is where. There's too many unfamiliar subnets at once, it's too easy to get lost in that.

And if it was me, I'd start with something much simpler, site to site as one config, road warriors as another, connection to "browse internet through us" VPN (is there any short commonly used term for that?), show the basic principles without having too many different things at the same time, and only then I'd put all that together. Because target group is mainly beginners who don't know much about it, and will often need only one of those configs. If you're familiar with routing, you don't need a guide like this, it's all pretty much obvious.
 
Zacharias
Forum Guru
Forum Guru
Posts: 3470
Joined: Tue Dec 12, 2017 12:58 am
Location: Greece

Re: Planning Your WIREGUARD CONNECTION!

Mon Jan 24, 2022 12:10 pm

Has anyone else noticed that every 2 minutes that the handshake takes place, the old keypairs are destroyed and new ones are created ?
I 've looked at it and they keys are actually rotated ( rotating keys ), so the old ones are destroyed and new session keypairs are created...
https://www.wireguard.com/protocol/

Anyone else noticed that ?
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 18168
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Planning Your WIREGUARD CONNECTION!

Mon Jan 24, 2022 2:00 pm

............................
Last edited by anav on Sun Mar 13, 2022 4:38 am, edited 1 time in total.
 
holvoetn
Forum Guru
Forum Guru
Posts: 4317
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: Planning Your WIREGUARD CONNECTION!

Mon Jan 24, 2022 3:34 pm

...and yet some drawings would indeed make it a lot more clear :D
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 18168
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Planning Your WIREGUARD CONNECTION!

Mon Jan 24, 2022 3:38 pm

...................
Last edited by anav on Sun Mar 13, 2022 4:38 am, edited 1 time in total.
 
holvoetn
Forum Guru
Forum Guru
Posts: 4317
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: Planning Your WIREGUARD CONNECTION!

Mon Jan 24, 2022 6:28 pm

Say what ? Huh ? :lol:
 
Sob
Forum Guru
Forum Guru
Posts: 9185
Joined: Mon Apr 20, 2009 9:11 pm

Re: PLAN Your WIREGUARD Connection!

Wed Feb 16, 2022 5:09 am

Problems with SCENARIO-4:

- no admin's client in image
- no 172.16.0.x addresses in image
- not clear enough description that Router A has two WG peers; it looks like there's one with two allowed subnets, but it's two with one subnet each (and for admin it should be just single address)
- 10.0.1.254/24 on Router A doesn't make sense when it's Router B's subnet
- mixed masks 172.16.0.254/24 / 172.16.0.0/30
 
404Network
Member
Member
Posts: 316
Joined: Wed Feb 16, 2022 2:04 pm

Re: PLAN Your WIREGUARD Connection!

Thu Feb 17, 2022 3:08 am

.........................
Last edited by 404Network on Sun Mar 13, 2022 4:49 am, edited 1 time in total.
 
Sob
Forum Guru
Forum Guru
Posts: 9185
Joined: Mon Apr 20, 2009 9:11 pm

Re: PLAN Your WIREGUARD Connection!

Thu Feb 17, 2022 3:37 am

You can assign as many addresses as you need, that's ok. But if 10.0.1.0/24 is Router B's LAN, what is 10.0.1.254/24 doing on Router A? Yes, it will provide working route from Router A to this remote subnet, but also useless address that won't be reachable from any other 10.0.1.x connected behind Router B (unless you enable proxy ARP on Router B's LAN interface). So why not just add simple non-confusing route to 10.0.1.0/24?

About masks, example has one peer, so why /30 with four addresses? Yes, it will work, but is it supposed to be somehow better with /30 than just with admin's one 172.16.0.x/32? And what address and allowed addresses will admin as client have? If 172.16.0.254/24 should be reachable, then allowed addresses will have to include either that one address or whole 172.16.0.0/24. There's no place for /30 there either, so only thing it does is to confuse reader.
 
404Network
Member
Member
Posts: 316
Joined: Wed Feb 16, 2022 2:04 pm

Re: PLAN Your WIREGUARD Connection!

Thu Feb 17, 2022 2:44 pm

.....................
Last edited by 404Network on Sun Mar 13, 2022 4:50 am, edited 1 time in total.
 
User avatar
mozerd
Forum Veteran
Forum Veteran
Posts: 867
Joined: Thu Oct 05, 2017 3:39 pm
Location: Canada
Contact:

Re: PLAN Your WIREGUARD Connection!

Thu Feb 17, 2022 4:17 pm

Hence, it makes sense to limit firewall rules and allowed IPs to just that smaller set.
100% agree ...
 
404Network
Member
Member
Posts: 316
Joined: Wed Feb 16, 2022 2:04 pm

Re: PLAN Your WIREGUARD Connection!

Thu Feb 17, 2022 5:58 pm

................
Last edited by 404Network on Sun Mar 13, 2022 4:50 am, edited 1 time in total.
 
Sob
Forum Guru
Forum Guru
Posts: 9185
Joined: Mon Apr 20, 2009 9:11 pm

Re: PLAN Your WIREGUARD Connection!

Thu Feb 17, 2022 6:47 pm

The 10.0.1.254/24 is an IP address for the WIREGUARD INTERFACE, and it WORKS.
It depends on how you define "works". I agree that it sort of does, but only accidentally, such config is still nonsense. Once more, in different words, this is what Router B has, including addresses shown only in image:
/ip address
add address=10.0.0.1/24 interface=WAN
add address=10.0.1.1/24 interface=LAN
add address=172.16.0.254/24 interface=wireguardR
Do you see the 10.0.1.1/24 on LAN? Then how can 10.0.1.254/24 from same subnet be on Router A? It "works" because Router A needs route to 10.0.1.0/24 pointing to WG interface and this address creates it. When connecting from 192.168.50.x (device in LAN A) to 10.0.1.x (device in LAN B), if it was allowed, it would work fine. Same for admin's access to LAN B. But if you try to access 10.0.1.x in LAN B from Router A itself, it won't work, because it will use 10.0.1.254 as source, so packet will reach target, but there won't be any response. Device in LAN B will see 10.0.1.254 as local reachable address, will send ARP request for it, but won't get any response, because that address is not in LAN B. And I was wrong before, proxy ARP wouldn't help either, because not even Router B has any idea that 10.0.1.254 is at Router A.
The /30 expresses the fact that the admin has at least 3 devices laptop, desktop, smartphone that they may wish to use at any time to connect to the Router.
Nothing against that, but it should be explicitly mentioned that admin needs multiple simultaneously connected devices. Otherwise you'll have people wondering why there's /30 for one device.
 
404Network
Member
Member
Posts: 316
Joined: Wed Feb 16, 2022 2:04 pm

Re: PLAN Your WIREGUARD Connection!

Thu Feb 17, 2022 7:17 pm

......................
Last edited by 404Network on Sun Mar 13, 2022 4:50 am, edited 1 time in total.
 
404Network
Member
Member
Posts: 316
Joined: Wed Feb 16, 2022 2:04 pm

Re: PLAN Your WIREGUARD Connection!

Thu Feb 17, 2022 7:21 pm

....................
Last edited by 404Network on Sun Mar 13, 2022 4:50 am, edited 1 time in total.
 
Sob
Forum Guru
Forum Guru
Posts: 9185
Joined: Mon Apr 20, 2009 9:11 pm

Re: PLAN Your WIREGUARD Connection!

Thu Feb 17, 2022 7:32 pm

Listen, @anav's brother, it's not difficult. :)

Router A needs route to LAN B (10.0.1.0/24). That can be either simple route with interface as gateway (/ip route add dst-address=10.0.1.0/24 gateway=wireguardM). But since @anav finally decided to try addresses, gateway can be the address on Router B's WG interface (/ip route add dst-address=10.0.1.0/24 gateway=172.16.0.X). Except (another mistate I noticed now) it can't, because he has same 172.16.0.254/24 on both routers. He could use e.g. 172.16.0.1/24 on Router A and then it would work with .254 on Router B (/ip route add dst-address=10.0.1.0/24 gateway=172.16.0.254).

As for your questions, I'm not sure what exactly you mean, and you're inventing addresses not used in example.
 
User avatar
mozerd
Forum Veteran
Forum Veteran
Posts: 867
Joined: Thu Oct 05, 2017 3:39 pm
Location: Canada
Contact:

Re: PLAN Your WIREGUARD Connection!

Thu Feb 17, 2022 7:36 pm

Listen, @anav's brother, it's not difficult. :)
Twin Brother --- :)
 
Sob
Forum Guru
Forum Guru
Posts: 9185
Joined: Mon Apr 20, 2009 9:11 pm

Re: PLAN Your WIREGUARD Connection!

Thu Feb 17, 2022 7:41 pm

And don't even start to think anything about "network" parameter of IP address. Ignore it and never ever set it manually, except in single special case with point to point /32 addresses.
 
404Network
Member
Member
Posts: 316
Joined: Wed Feb 16, 2022 2:04 pm

Re: PLAN Your WIREGUARD Connection!

Thu Feb 17, 2022 7:52 pm

..............................
Last edited by 404Network on Sun Mar 13, 2022 4:50 am, edited 1 time in total.
 
Sob
Forum Guru
Forum Guru
Posts: 9185
Joined: Mon Apr 20, 2009 9:11 pm

Re: PLAN Your WIREGUARD Connection!

Thu Feb 17, 2022 8:32 pm

It's not exercise to exclusively use only IP addresses or only routes. You can have both, they won't bite each other.

If you enter IP address 10.0.1.254/24, then network address is 10.0.1.0/24, and in RouterOS you'll see it as network 10.0.1.0. But you should not worry about this parameter at all, it's computed automatically, you don't need to (and shouldn't) touch it. In fact, it should not be editable at all, only reason for that is that it's also (mis)used for point to point addresses.

Just because something works doesn't mean that it's correct. You can get rid od mice in your house using dynamite, and it will work, there won't be no mice after. But is it the best choice? Nah. What you do here with 10.0.1.254 on Router A won't have such big impact, but it's still wrong.

I wouldn't use /30 here. Except maybe in firewall rules, if I need to match four addresses covered by /30. But not as mask for assigned addresses. If they are private ones, then just use /24, it's simple to understand (subnet contains addresses with any last number) and there's plenty of private addreses, so you don't need to save any.
 
404Network
Member
Member
Posts: 316
Joined: Wed Feb 16, 2022 2:04 pm

Re: PLAN Your WIREGUARD Connection!

Thu Feb 17, 2022 10:13 pm

......................
Last edited by 404Network on Sun Mar 13, 2022 4:51 am, edited 1 time in total.
 
Sob
Forum Guru
Forum Guru
Posts: 9185
Joined: Mon Apr 20, 2009 9:11 pm

Re: PLAN Your WIREGUARD Connection!

Thu Feb 17, 2022 10:34 pm

No, it's not that 10.0.1.254/24 would be wrong. It's perfectly fine, only it's in wrong place.

It's like if you put hat in your pants instead of on your head. It doesn't make the hat wrong, it's just that it doesn't belong there (even though, I guess, it can still do something useful there; I didn't think about it too much :D).
 
User avatar
mozerd
Forum Veteran
Forum Veteran
Posts: 867
Joined: Thu Oct 05, 2017 3:39 pm
Location: Canada
Contact:

Re: PLAN Your WIREGUARD Connection!

Thu Feb 17, 2022 10:51 pm

@404Network
So you wanted to loose your Guru status and decided that 404Error condition would allow you much more leeway ?… very appropriate :? :roll:
 
404Network
Member
Member
Posts: 316
Joined: Wed Feb 16, 2022 2:04 pm

Re: PLAN Your WIREGUARD Connection!

Thu Feb 17, 2022 10:57 pm

........................
Last edited by 404Network on Sun Mar 13, 2022 4:51 am, edited 1 time in total.
 
404Network
Member
Member
Posts: 316
Joined: Wed Feb 16, 2022 2:04 pm

Re: PLAN Your WIREGUARD Connection!

Thu Feb 17, 2022 11:00 pm

.......................
Last edited by 404Network on Sun Mar 13, 2022 4:51 am, edited 1 time in total.
 
Sob
Forum Guru
Forum Guru
Posts: 9185
Joined: Mon Apr 20, 2009 9:11 pm

Re: PLAN Your WIREGUARD Connection!

Thu Feb 17, 2022 11:57 pm

The big round thing with eyes and ears is the head I meant, and yes, it did cross my mind that further clarification will be needed for you. :)

But back to networking stuff, if I simplify your example a little:
     WAN                                         WAN
   a.a.a.a                                     b.b.b.b
      |                                           |
 +----------+                                +----------+
 | Router A |-<address X>----172.16.0.254/24-| Router B |
 +----------+                                +----------+
       |                                          |
192.168.50.0/24                               10.0.1.1/24
      LAN                                        LAN
and tell you that the link between routers is not WG tunnel, but plain old ethernet cable connecting dedicated ports on routers, would you use 10.0.1.254/24 as <address X>? You wouldn't, because it's clearly wrong. As you quickly find out if you don't believe me and try it. It's one of basic rules that you don't have same subnets on different interfaces, I'm sure you heard about that. So why you suddenly want to do this different thing with WG? Where it happens to work, but only partially, as I already explained to you twice.
No without warning they decided to tell me they didnt like me recommending something else for a wireless solution by removing access to my login.
So did they really tell you that, or is it your assumption that it was this one of your crimes that was the reason? Not something else like your quest against addresses, or something? ;) But yeah, this being MikroTik forum, some voices saying "MikroTik is shit, go buy something else" are perhaps a bit too loud, I wouldn't blame them for not liking it.
 
404Network
Member
Member
Posts: 316
Joined: Wed Feb 16, 2022 2:04 pm

Re: PLAN Your WIREGUARD Connection!

Fri Feb 18, 2022 12:39 am

........................
Last edited by 404Network on Sun Mar 13, 2022 4:51 am, edited 1 time in total.
 
Sob
Forum Guru
Forum Guru
Posts: 9185
Joined: Mon Apr 20, 2009 9:11 pm

Re: PLAN Your WIREGUARD Connection!

Fri Feb 18, 2022 1:22 am

You already had 172.16.0.x/24, but ok, let's scrap that and put 192.168.88.1/24 on Router A's WG interface and 192.168.88.2/24 on Router B's WG interface:
     WAN                                              WAN
   a.a.a.a                                          b.b.b.b
      |                                                |
 +----------+                                    +----------+
 | Router A |-192.168.88.1/24----192.168.88.2/24-| Router B |
 +----------+                                    +----------+
       |                                               |
192.168.50.0/24                                   10.0.1.1/24
      LAN                                             LAN
If it was ethernet and not WG, then Router A would have:
/ip route add dst-address=10.0.1.0/24 gateway=192.168.88.2
And Router B would have:
/ip route add dst-address=0.0.0.0/0 gateway=192.168.88.1 table=useWG
And now if it actually is WG, here comes the magic, wait for it, you can have exactly the same thing! And that's why all tutorials for beginners use it, because it's exactly the same as with ethernet, you don't need to remember anything new.
Then How would the Router know to return Internet traffic from 10.0.1.0/24 back to the tunnel.
Same way it does in your example, because there's routing rule saying that anything from 10.0.1.0/24 should look up route in table useWG (which contains exactly one default route pointing to Router A).
The router does not check allowed IPs for traffic returning from the normal ISP WAN.
I have no idea what you mean. WG's allowed IPs have nothing to do with routing, it's different level. Yes, they need to match, because if you route something to tunnel, but it's not allowed for (any) peer, it won't work. But it's something that happens only after routing decision, routing itself doesn't care about that.
 
404Network
Member
Member
Posts: 316
Joined: Wed Feb 16, 2022 2:04 pm

Re: PLAN Your WIREGUARD Connection!

Fri Feb 18, 2022 5:01 am

....................
Last edited by 404Network on Sun Mar 13, 2022 4:51 am, edited 1 time in total.
 
User avatar
mozerd
Forum Veteran
Forum Veteran
Posts: 867
Joined: Thu Oct 05, 2017 3:39 pm
Location: Canada
Contact:

Re: PLAN Your WIREGUARD Connection!

Fri Feb 18, 2022 3:45 pm

I have no idea what you mean. WG's allowed IPs have nothing to do with routing, it's different level. Yes, they need to match, because if you route something to tunnel, but it's not allowed for (any) peer, it won't work. But it's something that happens only after routing decision, routing itself doesn't care about that.
@Sob ... I have to disagree with your comment that WG allowed IPs have nothing to do with routing ....
For the sake of keeping it simple taking the KISS approach:

Lets use the following Site to Site example:
[Interface]
# Name = mox1.mydomain.rocks
PrivateKey = ......
Address = 10.90.99.1/24
ListenPort = 19628

[Peer]
# Name = mox2.mydomain.rocks
PublicKey = ...
AllowedIPs = 10.90.99.2/32, 192.168.100.0/24
PersistentKeepalive = 25
We can see that for the peer mox2.mydomain.rocks the AllowedIPs field is set to 10.90.99.2/32, 192.168.100.0/24.

AllowedIPs does two things:
1. It adds a route to the given networks, i.e. packets addressed to 10.90.99.2/32 or to 192.168.100.0/24 will be routed through the WireGuard interface to that peer
2. It will allow packets with the source IPs 10.90.99.2/32 or 192.168.100.0/24 to be routed from the given peer on the WireGuard interface
As to point 2 --- any packet from the given peer with a source IP address which is not listed in AllowedIPs will be discarded! While this does not replace a firewall, it serves a an integral part of Wireguard’s security model.

IMO, this discussion between you and 404 [anav's twin] is making it far to complicated for the new user. By keeping the model simple to START and the model gets expanded due to added complexity further "routes" can be added. :D Because 404error condition is a networking study in progress small steps are much better that GIANT steps :lol:

For a very GOOD READ on Allowed IPs Justin Ludwig from PRO CUSTODIBUS put a lot of effort in the following article ... highly recommended by me :)
 
404Network
Member
Member
Posts: 316
Joined: Wed Feb 16, 2022 2:04 pm

Re: PLAN Your WIREGUARD Connection!

Fri Feb 18, 2022 6:00 pm

.............................
Last edited by 404Network on Sun Mar 13, 2022 4:51 am, edited 1 time in total.
 
Sob
Forum Guru
Forum Guru
Posts: 9185
Joined: Mon Apr 20, 2009 9:11 pm

Re: PLAN Your WIREGUARD Connection!

Fri Feb 18, 2022 6:47 pm

@404Network: If you insist on either your:

a) less common but not too wrong method without addresses
b) completely messed up method with address on wrong interface and wrong router

Then please stick with a). It may confuse few beginners who will wonder why pretty much every other tutorial has addresses and yours doesn't, but let's be optimistic and assume that it will stimulate them to think about it, and will lead to better understanding of the thing (my usual opinion is that optimists should be shot, but maybe this one time it can work). Option b) could work as curiosity, or as some kind of quiz for advanced users, but it's harmful for beginners.
 
User avatar
mozerd
Forum Veteran
Forum Veteran
Posts: 867
Joined: Thu Oct 05, 2017 3:39 pm
Location: Canada
Contact:

Re: PLAN Your WIREGUARD Connection!

Fri Feb 18, 2022 6:58 pm

..... dont care about wireguard docs that dont pertain to MT setup and their unique wireguard parameter setup ....
I do not happen to agree with your position nor do I like your undisciplined approach towards networking in general ... Sob is trying hard to teach YOU but your stubbornness is inhibiting any progress on your part ........ I was just making a specific comment made by Sob .... RouterOS foundation is Linux as is WireGuard and as such the valuable information I linked to certainly pertains to RouterOS because its LINUX ..... once you inwardly digest the content ESPEICALLY when to add "Routes" and some other revelations of interest.
===============
===============
BACKGROUND
You use the AllowedIPs setting of WireGuard to configure which blocks of IP addresses should be routed through which remote WireGuard peers. If you want to access everything through a peer, configure its AllowedIPs setting to the following:

AllowedIPs = 0.0.0.0/0, ::/0
This indicates to WireGuard that all IPv4 addresses (0.0.0.0/0) and all IPv6 addresses (::/0) should be routed through the peer. Note that you can specify multiple blocks of addresses on the same line, separated by commas, like above; or you can specify them individually on separate lines, like below:

AllowedIPs = 0.0.0.0/0
AllowedIPs = ::/0
If you want to access just a single block of IP addresses through a WireGuard peer, like say a block of IP addresses at a remote site that range from 192.168.100.0 to 192.168.100.255, you’d set the AllowedIPs for it to the following:

AllowedIPs = 192.168.100.0/24
But what if you want the inverse, where you want everything except a single block (or two or three specific blocks) to be routed through a WireGuard peer? In many cases, you have subtract the exceptions from the block of allowed addresses, and set AllowedIPs to the resulting (often long) list of blocks.

For example, say you want to route all Internet traffic through a WireGuard peer, except that you don’t want to route the traffic of your internal networks through it, which use various subnets within the private-use 10.0.0.0/8 block. To make that happen with the AllowedIPs setting, you’d have to configure the peer with the following AllowedIPs:

AllowedIPs = 0.0.0.0/5, 8.0.0.0/7, 11.0.0.0/8, 12.0.0.0/6, 16.0.0.0/4, 32.0.0.0/3, 64.0.0.0/2, 128.0.0.0/1
That’s the list of blocks you get when you subtract 10.0.0.0/8 from 0.0.0.0/0 — conceptually you might express it like the following:

AllowedIPs = +0.0.0.0/0, -10.0.0.0/8
Or another way of expressing it might be:

AllowedIPs = 0.0.0.0/0
DisallowedIPs = 10.0.0.0/8
======================
======================
A BETTER ALTERNATIVE
As you can see, subtracting one block of IP address from another block can result in a painfully long list of blocks to add to the AllowedIPs setting. On some platforms, like mobile phones, you don’t have any other options — but on Linux, you have some powerful routing tools available that can simplify the situation.

In most cases, you can simply add a route to your main routing table to “subtract” a block of IP addresses from those routed via the WireGuard tunnel. And you may even find that the necessary route already exists — in which case you don’t have to do anything at all.

For example, say you want to route everything in the 10.0.0.0/8 block to a WireGuard peer, except for 10.0.1.0/24. Instead of subtracting 10.0.1.0/24 from 10.0.0.0/8 with the above calculator, and setting the peer’s AllowedIPs to the result, just set the peer’s AllowedIPs to the full 10.0.0.0/8 block. Outside of WireGuard, add an explicit route for 10.0.1.0/24 to your main routing table. Because 10.0.1.0/24 has a longer prefix length than 10.0.0.0/8 (/24 vs /8), the Linux routing engine will automatically use the route for 10.0.1.0/24 over the route for 10.0.0.0/8.

In fact, you may find that you have the necessary route for the exceptional block already set up — run the command ip route show table main (or just ip route, which by default lists the routes of your main routing table) on the host to see what (IPv4) routes you have already:

$ ip route show table main
default via 192.168.1.1 dev eth0 proto dhcp metric 1000
10.0.0.0/8 dev wg0 scope link
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.123 metric 100
If do you see a route listed for your exceptional block (10.0.1.0/24 in our example), you won’t have to add anything. If you don’t see it listed, however, you’ll have to add the route yourself. Fortunately, this easy — you just need to know the IP address of the gateway for the block, and the network interface to get there. Often, this will be the same as your default gateway (the line beginning with default in the above listing).

The simplest way to do this is to add the following ip route add and ip route del commands to the PreUp and PostDown scripts in your WireGuard config. To add a route for the 10.0.1.0/24 block with 192.168.1.1 as the gateway using the eth0 interface, add the following PreUp and PostDown settings to the [Interface] section of your WireGuard config:

[Interface]
PrivateKey = ...
PreUp = ip route add 10.0.1.0/24 via 192.168.1.1 dev eth0
PostDown = ip route del 10.0.1.0/24 via 192.168.1.1 dev eth0

[Peer]
PublicKey = ...
AllowedIPs = 10.0.0.0/8
Note that you can have multiple PreUp and PostDown lines in your config (similar to AllowedIPs). Multiple PreUp or PostDown lines are equivalent to a single PreUp or PostDown line joined together by semicolons.

Also note that the ip route commands above apply only to IPv4 addresses — for IPv6 addresses, you have to add the -6 flag (eg ip -6 route show table main).
 
Sob
Forum Guru
Forum Guru
Posts: 9185
Joined: Mon Apr 20, 2009 9:11 pm

Re: PLAN Your WIREGUARD Connection!

Fri Feb 18, 2022 7:07 pm

AllowedIPs does two things:
1. It adds a route to the given networks, i.e. packets addressed to 10.90.99.2/32 or to 192.168.100.0/24 will be routed through the WireGuard interface to that peer
It depends. If I give this config to e.g. WG client on Windows, it will add routes for all AllowedIPs, because it assumes that I want them reachable, otherwise what would be the reason to list them. But WG client on Windows is high level tool. RouterOS on the other hand requires you to configure things manually. So you can have allowed-address=10.90.99.2/32,192.168.100.0/24 and:

a) no manually added route pointing to WG interface (and also no IP address on WG interface that would create connected route) => WG won't be used for any outgoing traffic
b) manually added routes for same destinations pointing to WG interface => same result as with WG client on Windows
c) route to e.g. 192.168.0.0/16 pointing to WG interface => if there's packet to 192.168.1.1, RouterOS will try to route it to WG interface (you will see it in forward chain), but WG will report that it's unreachable.

That's what I meant by "WG's allowed IPs have nothing to do with routing". Feel free to improve wording, but the point stands.
 
404Network
Member
Member
Posts: 316
Joined: Wed Feb 16, 2022 2:04 pm

Re: PLAN Your WIREGUARD Connection!

Fri Feb 18, 2022 7:13 pm

......................
Last edited by 404Network on Sun Mar 13, 2022 4:52 am, edited 1 time in total.
 
Sob
Forum Guru
Forum Guru
Posts: 9185
Joined: Mon Apr 20, 2009 9:11 pm

Re: PLAN Your WIREGUARD Connection!

Fri Feb 18, 2022 7:35 pm

Don't worry, MikroTik won't add any artificial unnecessary limitation only to stop your creativity (I'm not sure if it's the best word ;)). You're not that much important, and this is far from being the only thing in RouterOS that can be misconfigured.
 
404Network
Member
Member
Posts: 316
Joined: Wed Feb 16, 2022 2:04 pm

Re: PLAN Your WIREGUARD Connection!

Fri Feb 18, 2022 7:47 pm

.......................
Last edited by 404Network on Sun Mar 13, 2022 4:52 am, edited 1 time in total.
 
Sob
Forum Guru
Forum Guru
Posts: 9185
Joined: Mon Apr 20, 2009 9:11 pm

Re: PLAN Your WIREGUARD Connection!

Fri Feb 18, 2022 8:44 pm

Main point, in case you missed it:

viewtopic.php?p=913951#p913951

b) is your latest invention with 10.0.1.254 address. Just don't do that. Not because of me, I can take it, but it's really so wrong that no beginner should ever see it.
 
404Network
Member
Member
Posts: 316
Joined: Wed Feb 16, 2022 2:04 pm

Re: PLAN Your WIREGUARD Connection!

Fri Feb 18, 2022 10:12 pm

............................
Last edited by 404Network on Sun Mar 13, 2022 4:52 am, edited 1 time in total.
 
Sob
Forum Guru
Forum Guru
Posts: 9185
Joined: Mon Apr 20, 2009 9:11 pm

Re: PLAN Your WIREGUARD Connection!

Fri Feb 18, 2022 10:56 pm

Once more, it's not the address or its format, it's that the address in your example is in wrong place, on wrong interface and even on wrong router. I told you and then tried to explain it several times, starting in this post:

viewtopic.php?p=913363#p913363

I also told you to ignore the "network" parameter of IP address, just don't touch it, pretend that it doesn't exist, and you can live happily ever after.

And no, you can't blame me for not giving you simple answers to your questions. Sometimes it's possible. But if you ask me something like "is carrot bigger animal than dog?" (some questions feel like that), I really can't give you yes/no answer.
 
404Network
Member
Member
Posts: 316
Joined: Wed Feb 16, 2022 2:04 pm

Re: PLAN Your WIREGUARD Connection!

Sat Feb 19, 2022 1:03 am

........................
Last edited by 404Network on Sun Mar 13, 2022 4:52 am, edited 1 time in total.
 
Sob
Forum Guru
Forum Guru
Posts: 9185
Joined: Mon Apr 20, 2009 9:11 pm

Re: PLAN Your WIREGUARD Connection!

Sat Feb 19, 2022 2:05 am

Let's take the simple ones first:

1) You swapped 10.255.255.1 and 10.255.255.2, I assume it's innocent mistake. Gateway to remote subnet should be the address on remote end of tunnel.

3) We've been over this, it's not what's usually used in tutorials, but ok, it could be like this. You also mentioned gateway=<WG interface> in 1) already.

And now the star of the evening:

2) No. No! NO! Hell NO! It's utter nonsense. It doesn't make any sense whatsoever.

192.168.16.0/24 is MK2's LAN subnet. It belongs on MK2's LAN interface. Why would you take address from MK2's LAN subnet and put it anywhere on MK1? Yes, it will create route to 192.168.16.0/24 pointing to WG tunnel. But if you need route, then just add route, don't add completely useless address (*).

And before that idea gets anywhere close to your brain, no, it's not validation for your original "no addresses needed at all". It's not just two things (addresses / no addresses), it's three (correct use of addresses / no addreses / completely wrong use of addresses). This is the third one.

And what does it have to do with allowed IPs? Didn't I just describe what's the relation between routes and WG's allowed IPs?

--
(*) Unless you're setting traps for enemies who would take over your router, to mess with their brains, then it would be ok. But I'd argue that it's very special case and shouldn't be in tutorial for beginners. Unless it's "Beginner's guide to guerrilla warfare, cyberspace edition".
Last edited by Sob on Sat Feb 19, 2022 2:21 am, edited 1 time in total.
 
Sob
Forum Guru
Forum Guru
Posts: 9185
Joined: Mon Apr 20, 2009 9:11 pm

Re: PLAN Your WIREGUARD Connection!

Sat Feb 19, 2022 2:12 am

And if you still don't understand what's wrong with 2), it's like if you wanted to route traffic to Google's DNS resolvers (8.8.8.8, 8.8.4.4) via tunnel, and you'd do it by assigning 8.8.0.1/16 to your WG interface. It would work (plus it would take "few" more addresses, about 65k of them, but let's skip this small detail). But it would feel wrong, correct? And don't you dare to say it wouldn't.
 
404Network
Member
Member
Posts: 316
Joined: Wed Feb 16, 2022 2:04 pm

Re: PLAN Your WIREGUARD Connection!

Sat Feb 19, 2022 5:31 am

.........................
Last edited by 404Network on Sun Mar 13, 2022 4:53 am, edited 1 time in total.
 
Sob
Forum Guru
Forum Guru
Posts: 9185
Joined: Mon Apr 20, 2009 9:11 pm

Re: PLAN Your WIREGUARD Connection!

Sat Feb 19, 2022 6:13 am

1) Let's say your ISP gives you public address x.x.x.2/29 (static, dhcp, doesn't matter) and default gateway is x.x.x.1. I already spoiled it, but which one you'll use as gateway? Will it be local x.x.x.2? Of course it won't, it will be remote x.x.x.1.

Or if you have large home network with main LAN 192.168.88.0/24, and for some reason you want another LAN 192.168.99.0/24 connected behind another router. Main router has 192.168.88.1 and the other one has 192.168.88.10. On main router you'll add route: /ip route add dst-address=192.168.99.0/24 gateway=192.168.88.X. And the X will be 1 or 10? There's no chance you'll pick wrong answer (I hope), of course it will be remote 10.

And do you remember the pattern I'm bringing over and over, about things being the same? Surprise (not really), it's the same with WG! Gateway is the remote address. But how does WG know that it's there? Well, it doesn't really know for sure that this specific address exists, but if it exists, it knows where it is (reachable using which interface). How? Same way as in previous two examples, because it has address with mask, which defines the subnet, creates connected route pointing to the interface this address is assigned to, and this route tells it that all other addresses from this subnet are on that interface and nowhere else.

There is small difference, in first two examples there's ethernet and router actually checks using ARP if the address exists. With WG there's no ARP, because it's L3 tunnel, so router blindly assumes that all addresses in defined subnet are there (except the one that this router has). And if such address is used as gateway, it's basically saying that traffic should be sent to that interface. It doesn't require doing anything else with that address.

2) No, you don't see people doing this. Something with addresses, yes. Exactly this, no way. Not without some additional config that could make it somewhat acceptable, but still quite unusual, and I haven't seen anyone do that (but let's not get into that, it wouldn't help you to understand what I'm trying to explain, maybe later, when you're ready).
 
404Network
Member
Member
Posts: 316
Joined: Wed Feb 16, 2022 2:04 pm

Re: PLAN Your WIREGUARD Connection!

Sat Feb 19, 2022 3:11 pm

..........................
Last edited by 404Network on Sun Mar 13, 2022 4:53 am, edited 1 time in total.
 
Sob
Forum Guru
Forum Guru
Posts: 9185
Joined: Mon Apr 20, 2009 9:11 pm

Re: PLAN Your WIREGUARD Connection!

Sat Feb 19, 2022 6:49 pm

And what's the problem? You do understand first two examples (gw from ISP, subnet behind another router), right? You must, otherwise I don't know what I've been doing here last four years. So why it suddenly becomes hard to understand with WG?
 
404Network
Member
Member
Posts: 316
Joined: Wed Feb 16, 2022 2:04 pm

Re: PLAN Your WIREGUARD Connection!

Mon Feb 21, 2022 2:51 pm

[......................
Last edited by 404Network on Sun Mar 13, 2022 4:53 am, edited 5 times in total.
 
holvoetn
Forum Guru
Forum Guru
Posts: 4317
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: PLAN Your WIREGUARD Connection!

Mon Feb 21, 2022 2:59 pm

An ip address is 4 octets of 1 byte = 4x 256.
That subnet number is the number of bits to use for the subnet definition.
So v.x.y.z/30 means the first 30 bits stay fixed. 2 bits to play with = 4 combinations within that subnet (of which usually 00b goes for subnet ID and 11b means broadcast).

Gateway is whatever you define it to be. Can even be in a different subnet.
I usually use .1 for my devices.
One of the commercial partners my client uses always defines .254 for their gateway routers.
Where I am now there are 2 subnets in one big LAN x.y.112.0 and x.y.113.0 but there is only one gateway x.y.112.254 for both subnets.
Last edited by holvoetn on Mon Feb 21, 2022 3:02 pm, edited 2 times in total.
 
User avatar
own3r1138
Long time Member
Long time Member
Posts: 678
Joined: Sun Feb 14, 2021 12:33 am
Location: Pleiades
Contact:

Re: PLAN Your WIREGUARD Connection!

Mon Feb 21, 2022 3:00 pm

I think If the subnet is /30 then the first IP would be network and gateway and the last IP is broadcast.
 
404Network
Member
Member
Posts: 316
Joined: Wed Feb 16, 2022 2:04 pm

Re: PLAN Your WIREGUARD Connection!

Mon Feb 21, 2022 3:10 pm

........................
Last edited by 404Network on Sun Mar 13, 2022 4:53 am, edited 1 time in total.
 
404Network
Member
Member
Posts: 316
Joined: Wed Feb 16, 2022 2:04 pm

Re: PLAN Your WIREGUARD Connection!

Mon Feb 21, 2022 3:12 pm

duplicate
 
User avatar
own3r1138
Long time Member
Long time Member
Posts: 678
Joined: Sun Feb 14, 2021 12:33 am
Location: Pleiades
Contact:

Re: PLAN Your WIREGUARD Connection!

Mon Feb 21, 2022 3:23 pm

I think If the subnet is /30 then the first IP would be network and gateway and the last IP is broadcast.
Missing my lack of knowledge /30 which four 0-4 50-54 125-129 etc.........
So if the /30 exist inside a bigger network like /24 then if you use an IP calculator and you set it to calculate a /30 for this specific IP then the 0-4 or 50-54 is happening depending on what specific IP you used for /30 calculation. then it might be 49-53 depending on what is the CIDR for the bigger network.
If it's not a part of a bigger network then it could be whatever you want it to be. if you select 125 then it's 125-129 if you use 50 then the range is 50-54 ( Wrong )
Last edited by own3r1138 on Mon Feb 21, 2022 3:41 pm, edited 1 time in total.
 
holvoetn
Forum Guru
Forum Guru
Posts: 4317
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: PLAN Your WIREGUARD Connection!

Mon Feb 21, 2022 3:26 pm

If it's not a part of a bigger network then it could be whatever you want it to be. if you select 125 then it's 125-129 if you use 50 then the range is 50-54
I don't think so.
125 decimal = 01111101 binary.
If you want to use /30 you need to have multiples of 4 so you can play with the last 2 bits.
So 124 or 128.

.125 would be part of a network 124 (all 0's at the back) with broadcast 127 (all 1's at the back), 125 and 126 are then the 2 adresses you can use.

Binary system is the base.
 
User avatar
own3r1138
Long time Member
Long time Member
Posts: 678
Joined: Sun Feb 14, 2021 12:33 am
Location: Pleiades
Contact:

Re: PLAN Your WIREGUARD Connection!

Mon Feb 21, 2022 3:44 pm

@holvoetn
Correct, Thank you. I need to take care of my network+ too.
 
Sob
Forum Guru
Forum Guru
Posts: 9185
Joined: Mon Apr 20, 2009 9:11 pm

Re: PLAN Your WIREGUARD Connection!

Mon Feb 21, 2022 6:04 pm

To understand subnets and masks, play with http://www.subnetmask.info. Start with defaults, select size of network in third field ("enter the required number of nodes/hosts per network") and click Calculate. Then click List Network to view all networks of that size.

If you enter 256 as number of hosts, you'll get the most common /24 mask. Nice thing about it is that only last number changes (and in full range), so it's always 0/1-254/255 (<network address>/<first usable address>-<last usable address>/<broadcast>).

If you enter 128, it will be /25, so half of /24. And you'll have two: 0/1-126/127 and 128/129-254/255.

If you enter 4, it will be /30, so 0/1-2/3, 4/5-6/7, 8/9-10/11, etc.

Or you can have larger subnets, 512 will give you /23, which spans over two /24s, so e.g. x.x.0.0/x.x.0.1-x.x.1.254/x.x.1.255.
... I dont understand why .1 doesnt work and .2 works sigh...
It's really simple, don't overthink it. Gateway = different device. So gateway address must be address of that device. That's it. If you have .1 and gateway has .2, then .2 is the right choice. And .1 isn't, because it's on your own router, so it doesn't really tell it where else it should send those packets. And yes, sometimes the interface can be used as gateway. But when it's address, it's the remote one.
 
404Network
Member
Member
Posts: 316
Joined: Wed Feb 16, 2022 2:04 pm

Re: PLAN Your WIREGUARD Connection!

Mon Feb 21, 2022 9:07 pm

............................
Last edited by 404Network on Sun Mar 13, 2022 4:53 am, edited 1 time in total.
 
holvoetn
Forum Guru
Forum Guru
Posts: 4317
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: PLAN Your WIREGUARD Connection!

Mon Feb 21, 2022 11:23 pm

Yes, or the interface that ip belongs to
 
404Network
Member
Member
Posts: 316
Joined: Wed Feb 16, 2022 2:04 pm

Re: PLAN Your WIREGUARD Connection!

Tue Feb 22, 2022 1:22 am

.............................
Last edited by 404Network on Sun Mar 13, 2022 4:53 am, edited 1 time in total.
 
Sob
Forum Guru
Forum Guru
Posts: 9185
Joined: Mon Apr 20, 2009 9:11 pm

Re: PLAN Your WIREGUARD Connection!

Tue Feb 22, 2022 2:06 am

In other words, the IP address and the gateway look eerily similar do they not??
Why does Mikrotik call that address the gateway then??
(default ip address 192.168.88.1/24 dns-server=192.168.88.1 GATEWAY=192.168.88.1
Sure they do look similar, because gateway address is also IP address, only on another device. So if router has 192.168.88.1/24 on LAN and in DHCP server config you have gateway=192.168.88.1, it mean that this router is gateway for (or "used by" may be better term) other 192.168.88.x devices in LAN. But gateway for this router is whatever address the upstream router has.
 
Sob
Forum Guru
Forum Guru
Posts: 9185
Joined: Mon Apr 20, 2009 9:11 pm

Re: PLAN Your WIREGUARD Connection!

Tue Feb 22, 2022 2:23 am

It’s the IP address of the virtual network interface that WireGuard sets up for the peer; and as such you can set it to whatever you want (whatever makes sense for the virtual WireGuard network you’re building). AHA!!!!
AHA not. ;) The "you can set it to whatever you want" means that you can choose anything you want, like 192.168.100.x/24, 10.11.12.x/30, 10.56.x.x/16, even public addresses if you have enough of them, whatever makes sense for you network. It does not mean that you should create nonsense config where you replace routes by addresses/subnets that are used elsewhere, as you tried to do.
If we set it to /24, that would indicate to the local host that other addresses in the same /24 block as the address itself (10.0.0.0 to 10.0.0.255) are routable through the interface. BINGO!!
Again, it's not saing what you think. No BINGO. It means that if you're going to have several clients/peers and each will have 192.168.56.x, it makes sense to assign 192.168.56.1/24 to WG interface, to tell router where to look for those 192.168.56.x clients. Assigning 192.168.88.1/24 to local WG interface, when 192.168.88.0/24 is in fact remote subnet connected behind peer is still nonsense.
 
404Network
Member
Member
Posts: 316
Joined: Wed Feb 16, 2022 2:04 pm

Re: PLAN Your WIREGUARD Connection!

Tue Feb 22, 2022 3:13 am

...........................
Last edited by 404Network on Sun Mar 13, 2022 4:54 am, edited 1 time in total.
 
Sob
Forum Guru
Forum Guru
Posts: 9185
Joined: Mon Apr 20, 2009 9:11 pm

Re: PLAN Your WIREGUARD Connection!

Tue Feb 22, 2022 3:56 am

No one can say I didn't try. Let me put it this way, if someone tells you to put anything you want on your pizza, they don't mean rat poison. If it works for you, knock yourself out, but please don't try to serve it to others.
 
User avatar
mozerd
Forum Veteran
Forum Veteran
Posts: 867
Joined: Thu Oct 05, 2017 3:39 pm
Location: Canada
Contact:

Re: PLAN Your WIREGUARD Connection!

Tue Feb 22, 2022 2:07 pm

WireGuard (Site to Site VPN Example) in Pictures and Text

This SUPERB presentation is done by Rick Frey a MikroTik Consultant who is 2nd to none IMO ...

@anav ... MikroTik WireGuard configuration Pictures are far more desirable for the new user ...
and To BOOT properly done by the author [wg-interface=IPaddress] :)

Take note of the following by Rick Frey
Add an address to the WireGuard interface on each router.

This address is unique and special
. WireGuard doesn’t handout IP addresses to the far side like SSTP or OpenVPN. You have to manually add that IP to the WireGuard Interface. That IP address causes a DAC (Dynamic Active Connected) route to be populated in the main routing table and it will be the IP address that we use latter on to create static routes. Whatever the destination address of that DAC route is, it needs to be specified in the “Allowed Address” on the far side. I played with multiple CIDR combinations and sumerization and it all worked as long as the “Allowed Address” list on the far side contained the IP address on that Interface.
 
404Network
Member
Member
Posts: 316
Joined: Wed Feb 16, 2022 2:04 pm

Re: PLAN Your WIREGUARD Connection!

Tue Feb 22, 2022 6:49 pm

.............................
Last edited by 404Network on Sun Mar 13, 2022 4:54 am, edited 3 times in total.
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 18168
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: PLAN Your WIREGUARD Connection!

Wed Feb 23, 2022 2:01 pm

.............................
Last edited by anav on Sun Mar 13, 2022 4:39 am, edited 1 time in total.
 
User avatar
mozerd
Forum Veteran
Forum Veteran
Posts: 867
Joined: Thu Oct 05, 2017 3:39 pm
Location: Canada
Contact:

Re: PLAN Your WIREGUARD Connection!

Wed Feb 23, 2022 2:14 pm

Brilliant take-down, of the fallacy's of using IP address for WG interface as the only viable method. :-)
I would like Mozerds take on point (2) and roaming endpoints and specifically how this works in MT.................... using an example.
Yes it does apply to MT ... Rick uses MT in all of his examples .... what you have forgotten is how Cryptokey Routing works
 
404Network
Member
Member
Posts: 316
Joined: Wed Feb 16, 2022 2:04 pm

Re: PLAN Your WIREGUARD Connection!

Wed Feb 23, 2022 2:23 pm

................................
Last edited by 404Network on Sun Mar 13, 2022 4:54 am, edited 1 time in total.
 
User avatar
mozerd
Forum Veteran
Forum Veteran
Posts: 867
Joined: Thu Oct 05, 2017 3:39 pm
Location: Canada
Contact:

Re: PLAN Your WIREGUARD Connection!

Wed Feb 23, 2022 2:53 pm

@anav ... When discussing RouterOS YOU must MUST Must remember that WireGuard is an integral part of the Linux KERNAL and as such Tik have to follow tightly in its footsteps ... I have ZERO knowledge how closely Tik follow the rules but regardless its ALL LINUX ... all Tik have done is prevented its users from making changes to how Tik want its version of LINUX to work through the SHELL it provided ... that shell is called RouterOS.

Last point on this rather senseless journey you are on .... RouterOS is not a PHD Tool .... its made for people who are network knowledgeable ... not for the PHD crowd ... For the network crowd the NUMBER ONE Tool is called Ping .... for the WireGuard world if one wants to calculate the effective MTU of the WG interface Ping is the Tool of Choice .... IF you do not assign a IP Address to the WG Interface then you cannot use Ping .... If you want to TEST out the WG Interface PING is the TOOL that the great majority of admins will GoTo .... etc etc etc.
 
404Network
Member
Member
Posts: 316
Joined: Wed Feb 16, 2022 2:04 pm

Re: PLAN Your WIREGUARD Connection!

Wed Feb 23, 2022 3:43 pm

.............................
Last edited by 404Network on Sun Mar 13, 2022 4:54 am, edited 1 time in total.
 
holvoetn
Forum Guru
Forum Guru
Posts: 4317
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: PLAN Your WIREGUARD Connection!

Wed Feb 23, 2022 4:21 pm

Process of elimination.
If you can not ping the other side, you don't know where in the chain it's broken -> multiple steps.
If you can not ping WG interface address on local side, you know where to look first.
Then WG address on remote side. If that works, you know the tunnel is ok.
Then router on remote side. Etc etc ...
 
User avatar
mozerd
Forum Veteran
Forum Veteran
Posts: 867
Joined: Thu Oct 05, 2017 3:39 pm
Location: Canada
Contact:

Re: PLAN Your WIREGUARD Connection!

Wed Feb 23, 2022 5:14 pm

I understand the ping crutch, only needed if you get it wrong the first time ;-P.
Actually you do not understand .... and that is the sad part for someone who I consider smart.
Let say the default MTU for WG is 1420 ... which it is BUT in some instances that MTU setting will cause throughput degradation because packet fragmentation or the throughput is not as fast as it should be ... so you will need to test and see what is the effective MTU setting for the WG Tunnel to get the optimal THROUGHPUT ....
Use Ping to Find a Path’s MTU

You are TESTING the WG Tunnel and that Tunnel is the WG Interface .... if that Interface does not have a IP address how are you going to TEST it.
 
404Network
Member
Member
Posts: 316
Joined: Wed Feb 16, 2022 2:04 pm

Re: PLAN Your WIREGUARD Connection!

Wed Feb 23, 2022 5:43 pm

.........................
Last edited by 404Network on Sun Mar 13, 2022 4:54 am, edited 1 time in total.
 
User avatar
mozerd
Forum Veteran
Forum Veteran
Posts: 867
Joined: Thu Oct 05, 2017 3:39 pm
Location: Canada
Contact:

Re: PLAN Your WIREGUARD Connection!

Wed Feb 23, 2022 6:25 pm

remember I have no formal training!
So you do not like the proper way and you want to rebel :)
IT Basics: The Ping Utility Explained
 
Sob
Forum Guru
Forum Guru
Posts: 9185
Joined: Mon Apr 20, 2009 9:11 pm

Re: WIREGUARD SUCCESS FOR THE BEGINNER

Fri Mar 18, 2022 11:44 pm

I read the main part (didn't dive much into examples, too many subnets, not enough images) and I find some parts confusing. Not counting funny bits like address 172.168.10.5.2 or port 80901.

In (3) you have (i) and (ii), and I had to read it several times, trying to find what's the difference, but there really isn't any. You're splitting incoming and outgoing traffic as two different things, but why? Whether there's communication initiated from local to remote subnet, or from remote to local subnet, it doesn't matter, because unless you're doing something special and unusual (e.g. some asymmetric routing), it will be bidirectional communication. And as far as routing is concerned, it doesn't matter which side started it. In both cases you need route to remote subnet, just one (if there's one remote subnet). But when I see it split in (i) and (ii), at first sight it seems there should be two routes.

In (4) it's hard to understand what belongs where. Those four addresses at the beginning, it looks like I should put all of them on main router, because the whole block starting with "/ip address" uses RouterOS syntax. But they are in fact addresses for individual devices. Also the choice of addresses, maybe it's just me, but wouldn't it be better if main router/server, as the most important component, had .1 and was mentioned first before others? There are also different mixed up subnets.

And when showing command to assign address, don't include network parameter (/ip address add address=172.10.5.5/24 interface=wg-local network=172.10.5.0). It suggests that it should be entered manually, but it's almost never the case. RouterOS will compute it automatically, and it won't make a mistake, unlike user entering something and not knowing why exactly.
 
User avatar
mozerd
Forum Veteran
Forum Veteran
Posts: 867
Joined: Thu Oct 05, 2017 3:39 pm
Location: Canada
Contact:

Re: WIREGUARD SUCCESS FOR THE BEGINNER

Sat Mar 19, 2022 10:33 am

@anav
very daunting presentation but well laid out. Perhaps it should be broken down into a series of posts :)

suggestions ... test each scenario out so that it will reflect reality under MikroTik ..

I've done some more testing in my Lab and confirmed that when Donenfeld's WG 'clients' are used under Windows, IOS and Android MikroTik;s WG implementation does properly sync both ways ... for example --- Allowed IPs will generate routes automatically on a peer to peer basis when the WG Interface has been assigned its IP Address ... however because those routes are auto generated there is more work to be done all depending on the end user objectives ... The additional work is Firewall related not routes.

A Windows machine may NOT be reachable in "any" subnet unless some prep work is done like having its Windows Firewall adjusted to have ICMP allowed for ipv4 and ipv6 plus network discovery enabled and shares properly defined for the user in question .. each platform has its quirks. ... If Windows Firewall is NOT adjusted for ICMP that machine will not be reachable .... after being reachable then one must confirm network discovery is enabled and shares properly defined otherwise the user objective may fail again. Also under Windows when traversing subnets the Windows Firewall needs attention ... it get complicated all depending on network type -- Domain, Private, Public ... not a big issue for the simple home but certainly an config issue for the SMB .... only meaningful when Routing from the Router in question.

I have not detailed all my findings here based on the tests I have conducted .. I do not have the time .... One very critical area is the IP Address and its subnet mask ... make a mistake there and those auto generated routes will not work. So actual testing will reveal what is possible ... very time consuming but the revelations make it worth while. :)
Last edited by mozerd on Mon Mar 21, 2022 3:17 pm, edited 1 time in total.
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 18168
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: WIREGUARD SUCCESS FOR THE BEGINNER

Sat Mar 19, 2022 2:02 pm

One very critical area is the IP Address and its subnet mask ... make a mistake there and those auto generated routes will not work. So actual testing will reveal what is possible ... very time consuming but the revelations make it worth while. :)
Concur, and is why it has its own section. Thanks for taking the time to look it over. The article was not meant to address general networking on a PC (windows firewall etc.) so its not really germane but will see if I can stick something in. I have not had time either to go over all the examples, or put the diagrams back in................. work in progress.
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 18168
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: WIREGUARD SUCCESS FOR THE BEGINNER

Mon Mar 21, 2022 2:37 pm

THanks Sob, will try to tidy up some of the bits you noted.
Also yes the diagrams and examples will get attention but not yet too busy.
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 18168
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: WIREGUARD SUCCESS FOR THE BEGINNER

Mon Mar 21, 2022 2:40 pm

In (3) you have (i) and (ii), and I had to read it several times, trying to find what's the difference, but there really isn't any. You're splitting incoming and outgoing traffic as two different things, but why? Whether there's communication initiated from local to remote subnet, or from remote to local subnet, it doesn't matter, because unless you're doing something special and unusual (e.g. some asymmetric routing), it will be bidirectional communication. And as far as routing is concerned, it doesn't matter which side started it. In both cases you need route to remote subnet, just one (if there's one remote subnet). But when I see it split in (i) and (ii), at first sight it seems there should be two routes.
THis para is more about explaining to new users where the allowed IPs come from. Your observations and comments are correct in terms of functionality or outcome, but was not the real intent.
I will attempt a rewording......... but yes, not all traffic is two way and thus a route could be made just for return traffic of remote users, or a route could be made just for destination addresses or local users.
 
User avatar
mozerd
Forum Veteran
Forum Veteran
Posts: 867
Joined: Thu Oct 05, 2017 3:39 pm
Location: Canada
Contact:

Re: WIREGUARD SUCCESS FOR THE BEGINNER

Fri Apr 08, 2022 6:48 pm

The following rules demonstrate the possibilities that exist at both ends of the tunnel:
add action=accept chain=input in-interface=wg-interface-name dst-port=winboxport src-address=Admin_IP { to allow admin to config the local router from a remote site }
@anav
The above example is missing protocol .... if protocol= is not included you cannot have dst-port=winboxport
Suggestion: each time you include rules I suggest that you follow the syntax otherwise people will have issues .... routeros does a good job of error spotting so its easy for you to trial the code before posting.
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 18168
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: WIREGUARD SUCCESS FOR THE BEGINNER

Fri Apr 08, 2022 6:56 pm

Thanks for that .........will hopefully get to it later today. Edit: Done!
 
nik96i
just joined
Posts: 2
Joined: Fri Apr 08, 2022 10:02 am

Re: WIREGUARD SUCCESS FOR THE BEGINNER

Sun Apr 10, 2022 2:57 pm

Hi, thanks for sharing.
I have an LHG antenna with a PPPOE connection to my ISP. I configured wireguard interface and peer and assign an IP to it. It's OK. But how can I send internet traffic through wireguard then pipe interface? Thanks. I use a WG client on windows, but i want to move it to routerOS for simplicity. Thanks.
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 18168
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: WIREGUARD SUCCESS FOR THE BEGINNER

Fri Apr 22, 2022 11:22 pm

Start a new thread at the beginner forum, with your question, this thread is for discussion on improving the user article..........
 
howdey57
Member Candidate
Member Candidate
Posts: 127
Joined: Wed Dec 31, 2014 2:36 pm

Re: Wireguard Success For The Beginner

Mon Jul 25, 2022 10:50 pm

anav,

I wonder if you could add to your helpful OP. Could you add a scenario describing how to direct the traffic from one IP address through a working WireGuard VPN out onto the internet? The use case is me trying to get to UK TV (via London) whilst to France. I have an existing successful WireGuard VPN that I can use to get to machines from either place, but the ability to direct a single French IP address out of the remote London WAN eludes me.

Thanks in advance,

Charles
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 18168
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Wireguard Success For The Beginner

Mon Jul 25, 2022 11:03 pm

Hi howdey, your explanation eludes me.

Please state where is client (and which device)
Please state where is sever (and which device).

Confirm the source IP is on one of the devices above and its part of a LAN subnet.
Confirm the destination IP is an internet address somewhere (but not either of the two devices noted above).

You are travelling, you have an IPAD that allows you through IOS to WIREGUARD to a home MT server...........
you go out the MT Server to a specific WANIP ??

OR are you using a third party vpn provider....... ????

Something along those lines would be helpful, hold my hand walk me through it so to speak.

+++++++++++++++++++
Whatever devices you have will need to see the config.
 
howdey57
Member Candidate
Member Candidate
Posts: 127
Joined: Wed Dec 31, 2014 2:36 pm

Re: Wireguard Success For The Beginner

Tue Jul 26, 2022 12:02 am

anav,

Hopefully this is what you are after.
  • France RouterBOARD 962UiGS-5HacT2HnT - 192.168.65.0/24
  • London RB4011 - 192.168.64.0/24
  • There is a Wireguard VPN with 0.0.0.0/0 Allowed Addresses on both ends - the VPN is up and allows me to see machines at either end from within the two networks.
  • TV in France IP = 192.168.65.194
I want the TV to get to the BBC via the London Router so the BBC see the TV as being in London.

Thanks

Charles
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 18168
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Wireguard Success For The Beginner

Tue Jul 26, 2022 4:49 am

Hopefully you will do a better job of answering some basic questions next time, its like being a dentist and pulling teeth :-0

So which Router France or London has either
a. a public IP OR
b. is behind a router with a public IP and you have access to the ISP modem router to at least forward a port?

IF you do then you basically want to establish a tunnel between the two devices/
Now one does not push tv signal over the tunnel, but one can certainly access the device from anywhere.

What I mean is that any remote user (ipad, iphone, laptop) can as a client access LONDON and then ipso facto gain access to the device in France.
What IPs are involved are inconsequential as they are behind a tunnel. What the TV provider in France will see is a another request from the same local french router etc...

Suggest that you start a thread in the beginner forum with as much detail as you can and provide a network diagram and the configs of both routerboard and router and a sample config of a remote user !

ALSo suggest before you do you read this.... LOL, as it will help you organize your thoughts so you have a coherent plan......... better than what you have presented thus far.
viewtopic.php?t=182340
 
howdey57
Member Candidate
Member Candidate
Posts: 127
Joined: Wed Dec 31, 2014 2:36 pm

Re: Wireguard Success For The Beginner

Sat Aug 06, 2022 3:23 pm

<In Prose>
I sit in my house in France. I turn on my IP TV. I start BBC iPlayer. Oh no, it says I'm in France, "you cannot view this content because you are not in the UK".

I think "hmm, is there a way I can direct all the IP traffic just for the TV through to London. (and not satellite signal, that would be silly)?".

Yes, I think, I can do that because I used to do it with an IPSec tunnel before I changed to the Wireguard tunnel tunnel last year. I think back to when I set up the Wireguard tunnel last year and how helpful the mikrotik forum was. It's been working really well for months.

Luckily, I think, that I've been using mikrotik routers between London and France for years. With London on the end of a Virgin Media cable router in modern mode and the French router behind an ADSL SFR router. However, I'm thinking that, because I have a working tunnel, this information is irrelevant.

I think, yes I'll have a go. So I try to add a route and various other things but can't make it work. I look at the mikrotik site. There is lots of info about directing all traffic through a Wireguard but the explanations about single IP address are complicated and I don't understand. Also the advice differs, so I don't know the best way.

Then I find a helpful post about Wireguard set up from the beginning and I think "ah, an expert" I'll ask them. So I put a post on the mikrotik site suggesting an addition to the original post that will help me and others. This, I assume, will be a generic suggestion that I can adjust for my particular circumstances but at least it will be a best practice answer.
<end prose>

To cut my story short, I read the OP and the whole thread again (after anav's helpful responses :wink: ) and find what I am after in:
(3) CONFIGURING THE IP ROUTES >>> b. ORIGINAL (LOCAL) TRAFFIC
and I add
/routing table add fib name=use-WG
/routing rule add action=lookup-only-in-table comment=TV disabled=no src-address=192.168.65.26/32 table=use-WG
/ip route add comment="So certain source IPs go through the WG VPN - look in Routing Rules" disabled=no distance=1 dst-address=0.0.0.0/0 gateway=WireGuard_ToUK pref-src=0.0.0.0 routing-table=use-WG scope=10 suppress-hw-offload=no target-scope=10
Much as I like the Mikrotik documentation, there is a lot of how, but not enough why. I was looking for a heading such as "How to direct your internet through a VPN to receive foreign TV stations" . This is not an unusual situation - there is a whole industry - nordvpn etc.

Picking through a long post looking for the right keywords is tough for someone who is still learning.
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 18168
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Wireguard Success For The Beginner

Sat Aug 06, 2022 4:28 pm

Yes, rereading the thread myself, I understand now, with prose, what you were trying to accomplish.
You have done it right it looks.

FW RULES:
Also ensure that the local user "192.168.65.26/32" has access to the wireguard interface.

At the local originating location FRANCE:
add chain=forward action=accept in-interface-list=LAN src-address=192.168.65.26/32 out-interface=WireGuard_ToUK

At the remote location LONDON
add chain=forward action=accept in-interface=WireGuard_FromFRANCE out-interface-list=WAN

You should also ensure that source natting occurs for this traffic at the LONDON when exiting to the internet, and can be done in two ways
add chain=srcnat action=masquerade in-interface=WireGuard_FromFRANCE out-interface-list=WAN
OR
you an simply do this.
add interface=WireGuard_FromFRANCE list=WAN

And then this existing rule would apply to wireguard traffic ...............
add chain=srcnat action=masquerade out-interface-list=WAN


There should be no concern about which country is the source of the request. The wireguard tunnel ONLY sends over the private IP addresses which have nothing to do with location.
However the Router in London needs to be told to masquerade the wireguard traffic for internet purposes, otherwise it will send request out with private IP of user and return traffic will never be seen.
 
howdey57
Member Candidate
Member Candidate
Posts: 127
Joined: Wed Dec 31, 2014 2:36 pm

Re: Wireguard Success For The Beginner

Sun Aug 07, 2022 1:32 pm

anav, thanks for confirming my approach - perhaps you add the heading I was looking for into your OP so others can search for it? ("Usecase: Directing your TV's internet traffic through a VPN to receive foreign TV stations")

On your firewall suggestions - I haven't got those in my config (as written by you), yet the routing works through the VPN.

I attach my rules here so you can see what I do. Are they equivalent to your suggestion?
# aug/07/2022 12:11:27 by RouterOS 7.4
# software id = UTIL-NR1C
#
# model = RouterBOARD 962UiGS-5HacT2HnT
# serial number = 8A7C08229882

/ip pool add name=default-dhcp ranges=192.168.65.63-192.168.65.254
/ip pool add name=guest_dhcp ranges=192.168.67.10-192.168.67.254
/ip dhcp-server add address-pool=default-dhcp interface=bridge name=defconf
/ip dhcp-server add address-pool=guest_dhcp interface=guest_bridge name=guest_dhcp_67
/ip address add address=192.168.65.1/24 comment=defconf interface=bridge network=192.168.65.0
/ip address add address=192.168.67.1/24 interface=guest_bridge network=192.168.67.0
/ip address add address=10.255.255.2/30 interface=WireGuard_ToUK network=10.255.255.0
/ip address add address=192.168.1.2/24 interface=ether1_SFR network=192.168.1.0
/ip dhcp-client add add-default-route=no comment=defconf disabled=yes interface=ether1_SFR use-peer-dns=no

/ip dhcp-server lease add address=192.168.65.26 client-id=1:e8:f2:e2:70:49:f2 comment=TV mac-address=E8:F2:E2:70:49:F2 server=defconf

/ip dhcp-server network add address=192.168.65.0/24 comment=defconf dns-server=8.8.8.8,9.9.9.9 gateway=192.168.65.1 netmask=24 ntp-server=192.168.1.1
/ip dhcp-server network add address=192.168.67.0/24 dns-server=9.9.9.9,8.8.8.8 gateway=192.168.67.1 ntp-server=192.168.1.1
/ip dns set servers=8.8.8.8,4.4.4.4

/ip firewall address-list add address=0.0.0.0/8 comment=RFC6890 list=not_in_internet
/ip firewall address-list add address=172.16.0.0/12 comment=RFC6890 list=not_in_internet
/ip firewall address-list add address=192.168.0.0/16 comment=RFC6890 list=not_in_internet
/ip firewall address-list add address=10.0.0.0/8 comment=RFC6890 list=not_in_internet
/ip firewall address-list add address=169.254.0.0/16 comment=RFC6890 list=not_in_internet
/ip firewall address-list add address=127.0.0.0/8 comment=RFC6890 list=not_in_internet
/ip firewall address-list add address=224.0.0.0/4 comment=Multicast list=not_in_internet
/ip firewall address-list add address=198.18.0.0/15 comment=RFC6890 list=not_in_internet
/ip firewall address-list add address=192.0.0.0/24 comment=RFC6890 list=not_in_internet
/ip firewall address-list add address=192.0.2.0/24 comment=RFC6890 list=not_in_internet
/ip firewall address-list add address=198.51.100.0/24 comment=RFC6890 list=not_in_internet
/ip firewall address-list add address=203.0.113.0/24 comment=RFC6890 list=not_in_internet
/ip firewall address-list add address=100.64.0.0/10 comment=RFC6890 list=not_in_internet
/ip firewall address-list add address=240.0.0.0/4 comment=RFC6890 list=not_in_internet
/ip firewall address-list add address=192.88.99.0/24 comment="6to4 relay Anycast [RFC 3068]" list=not_in_internet
/ip firewall address-list add address=8.8.8.8 list=CameraAllowed

/ip firewall address-list add address=8.8.4.4 list=CameraAllowed
/ip firewall address-list add address=9.9.9.9 list=CameraAllowed

/ip firewall address-list add address=10.200.0.0/24 list=AllowedToRouter
/ip firewall address-list add address=192.168.64.0/24 list=AllowedToRouter
/ip firewall address-list add address=192.168.65.0/26 list=AllowedToRouter

/ip firewall address-list add address=0.0.0.0/8 comment="defconf: RFC6890" list=no_forward_ipv4
/ip firewall address-list add address=169.254.0.0/16 comment="defconf: RFC6890" list=no_forward_ipv4
/ip firewall address-list add address=224.0.0.0/4 comment="defconf: multicast" list=no_forward_ipv4
/ip firewall address-list add address=255.255.255.255 comment="defconf: RFC6890" list=no_forward_ipv4

/ip firewall address-list add address=192.168.1.254 list=whitelist
/ip firewall address-list add address=192.168.1.1 list=whitelist
/ip firewall address-list add address=192.168.65.0/26 comment="IP Range 2-62" list=whitelist
/ip firewall address-list add address=192.168.64.0/24 list=whitelist
/ip firewall address-list add disabled=yes list=whitelist

/ip firewall address-list add address=192.168.65.0/26 list=TrustedIPaddresss
/ip firewall address-list add address=192.168.64.0/24 list=TrustedIPaddresss
/ip firewall address-list add address=10.200.0.0/24 list=TrustedIPaddresss
/ip firewall address-list add address=192.168.1.1 list=TrustedIPaddresss

/ip firewall address-list add address=192.168.65.192/26 list=GuestIP
/ip firewall address-list add address=192.168.65.64/26 list=GuestIP
/ip firewall address-list add address=192.168.65.128/26 list=GuestIP
/ip firewall address-list add address=192.168.67.0/24 list=GuestIP

/ip neighbor discovery-settings set discover-interface-list=LAN
/ip settings set max-neighbor-entries=8192

/ip firewall filter add action=accept chain=input comment="defconf: accept established,related,untracked" connection-state=established,related,untracked
/ip firewall filter add action=accept chain=input comment="Accept to Router" src-address-list=TrustedIPaddresss
/ip firewall filter add action=accept chain=input comment="Accept Ping" log-prefix=Ping protocol=icmp
/ip firewall filter add action=accept chain=input comment="Wireguard to London" dst-port=xxx log-prefix="CH_Track Wireguard " protocol=udp
/ip firewall filter add action=log chain=input comment="Track Dodgy SSH" dst-port=22 log-prefix="CH_Track Dodgy SSH" protocol=tcp src-address=!192.168.64.6
/ip firewall filter add action=accept chain=input comment="Accept SSH" dst-port=22 log=yes log-prefix="CH_Track: Allow in SSH" protocol=tcp src-address-list=TrustedIPaddresss
/ip firewall filter add action=accept chain=input comment="Accept Winbox" dst-port=8291 log=yes log-prefix="CH_Track: Allow in Winbox" protocol=tcp src-address-list=TrustedIPaddresss
/ip firewall filter add action=add-src-to-address-list address-list=maybeBlacklist address-list-timeout=none-dynamic chain=input comment="defconf: note all not coming from whitelist" src-address-list=!whitelist
/ip firewall filter add action=drop chain=input comment="Last Rule: Drop Everything" log-prefix=Last

/ip firewall filter add action=fasttrack-connection chain=forward comment="defconf: fasttrack" connection-state=established,related hw-offload=yes
/ip firewall filter add action=accept chain=forward comment="defconf: accept established,related, untracked" connection-state=established,related,untracked
/ip firewall filter add action=drop chain=forward comment="defconf: drop invalid" connection-state=invalid
/ip firewall filter add action=drop chain=forward comment="defconf: drop all from WAN not DSTNATed" connection-nat-state=!dstnat connection-state=new in-interface-list=WAN
/ip firewall filter add action=jump chain=forward comment="jump to ICMP filters" jump-target=icmp protocol=icmp
/ip firewall filter add action=drop chain=forward comment="defconf: drop bad forward IPs" src-address-list=no_forward_ipv4
/ip firewall filter add action=drop chain=forward comment="defconf: drop bad forward IPs" dst-address-list=no_forward_ipv4
/ip firewall filter add action=drop chain=forward comment="Stop Guests getting to our stuff" out-interface-list=!WAN src-address-list=GuestIP
/ip firewall filter add action=add-dst-to-address-list address-list=CameraGoingTo address-list-timeout=none-static chain=forward comment="Log Cameras going out" dst-address-list=!CameraAllowed log-prefix=Camera: out-interface-list=WAN src-address-list=Camera
/ip firewall filter add action=drop chain=forward comment="Stop Cameras going out" dst-address-list=!CameraAllowed log-prefix=Camera: out-interface-list=WAN src-address-list=Camera
/ip firewall filter add action=drop chain=forward comment="Drop incoming from internet which is not public IP" in-interface-list=WAN src-address-list=not_in_internet

/ip firewall filter add action=accept chain=icmp comment="echo reply" icmp-options=0:0 protocol=icmp
/ip firewall filter add action=accept chain=icmp comment="net unreachable" icmp-options=3:0 protocol=icmp
/ip firewall filter add action=accept chain=icmp comment="host unreachable" icmp-options=3:1 protocol=icmp
/ip firewall filter add action=accept chain=icmp comment="host unreachable fragmentation required" icmp-options=3:4 protocol=icmp
/ip firewall filter add action=accept chain=icmp comment="allow echo request" icmp-options=8:0 protocol=icmp
/ip firewall filter add action=accept chain=icmp comment="allow time exceed" icmp-options=11:0 protocol=icmp
/ip firewall filter add action=accept chain=icmp comment="allow parameter bad" icmp-options=12:0 protocol=icmp
/ip firewall filter add action=drop chain=icmp comment="deny all other types"


/ip firewall nat add action=masquerade chain=srcnat comment="defconf: masquerade" out-interface-list=WAN
/ip firewall raw add action=drop chain=prerouting comment="For Packets coming from Blacklist" src-address-list=Blacklist
/ip firewall raw add action=drop chain=prerouting comment="For Packets passing through the Router" dst-address-list=Blacklist log-prefix="Raw Pre Drop"
/ip firewall raw add action=drop chain=output comment="For Packets originating from the Router" dst-address-list=Blacklist log=yes log-prefix="Raw Output Drop:"
/ip ipsec policy set 0 disabled=yes
/ip route add disabled=no distance=1 dst-address=192.168.64.0/24 gateway=WireGuard_ToUK pref-src=0.0.0.0 routing-table=main scope=30 suppress-hw-offload=no target-scope=10
/ip route add comment="This is here to force Netwatch to direct the ping through the SFR Router" disabled=yes distance=1 dst-address=8.8.4.4/32 gateway=192.168.1.1 pref-src=0.0.0.0 routing-table=main scope=10 suppress-hw-offload=no target-scope=10
/ip route add disabled=no dst-address=10.200.0.0/24 gateway=WireGuard_ToUK routing-table=main suppress-hw-offload=no
/ip route add comment="So certain source IPs go through the WG VPN - look in Routing Rules" disabled=no distance=1 dst-address=0.0.0.0/0 gateway=WireGuard_ToUK pref-src=0.0.0.0 routing-table=use-WG scope=10 suppress-hw-offload=no target-scope=10
/ip route add disabled=no distance=1 dst-address=0.0.0.0/0 gateway=192.168.1.1 pref-src="" routing-table=main scope=30 suppress-hw-offload=no target-scope=10 vrf-interface=ether1_SFR
 
DarkNate
Forum Veteran
Forum Veteran
Posts: 890
Joined: Fri Jun 26, 2020 4:37 pm

Re: Wireguard Success For The Beginner

Sun Aug 07, 2022 1:52 pm

WireGuard doesn't rely on PMTUD inside the tunnel.

Set it to 1420 on the router where WAN interface is 1500, set it to 1420 on the client side app as well. PMTUD at OS level on each side will ensure packet size don't exceed 1420 and of course don't block ICMP like an idiot would.
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 18168
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Wireguard Success For The Beginner

Sun Aug 07, 2022 3:20 pm

Im no mtu expert so DarkNates advice is very helpful here. I just ensure that the MTU settings on both sides of the tunnel are the same.
No it hurts my head to look at your rules, I am a minimalist and simple appeals to me LOL. IF it works it works, be happy! Glad you got it working!!

Not sure if it needs its own paragraph, its a variation of simply accessing the internet at the other end of a VPN tunnel in this case wireguard.
The use of firewall rules to allow traffic to reach the tunnel locally and to reach the wan remotely are valid in many cases, especially as I do and many others do, have block all else rules at the end of input and forward chain. So any new traffic required has to be explicitly stated. The allowed addresses are critical and a thorough understanding of them is key. Firewall addresses are great to further refine access.

Routes are also common to many scenarios, the use of wireguard address takes care of much traffic via <dac> routes. However locally, when one has the possibility of going out locally or through the tunnel more work needs to be done. Ensuring a single IP, a block of IPs or a whole subnet to go out the internet at the far side is common to many scenarios.
The difference being that a single IP or an entire subnet are easy, no mangling, but when one has a large group of IPs, then one has to get creative and think of mangling vice route rules or perhaps use destination address vice source address in the route rule.
 
pwac092
just joined
Posts: 21
Joined: Tue Oct 04, 2022 9:44 pm

Re: Wireguard Success For The Beginner

Fri Nov 04, 2022 4:59 pm

Hiya anav,

this is a fantastic post.

Would you by any chance have the diagram for Scenario 4?

I am getting lost in the ip ranges.

Cheers.
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 18168
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Wireguard Success For The Beginner

Fri Nov 04, 2022 5:23 pm

Hi pwac092 caveat, the scenarios were done up BEFORE I understand wireguard correctly or more widely.
Thus you are reminding me to fix them LOL.
 
pwac092
just joined
Posts: 21
Joined: Tue Oct 04, 2022 9:44 pm

Re: Wireguard Success For The Beginner

Fri Nov 04, 2022 5:26 pm

hahaha cool..I am really into the fourth scenario.

I want to add an additional backup endpoint at my brother's house, and I think the Site A, public IP, Site B no public address behind an ISP router is exactly what I need.

I'll try the one you have and keep an eye on the new one.

Cheers.
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 18168
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Wireguard Success For The Beginner

Sat Nov 05, 2022 3:00 pm

kk, did my first cut at making scenario four more coherent and accurate. Have a look, and if your situation is more complicated let me know what it is!!
 
pwac092
just joined
Posts: 21
Joined: Tue Oct 04, 2022 9:44 pm

Re: Wireguard Success For The Beginner

Sat Nov 05, 2022 4:00 pm

Hiya anav,
cheers mate. This is brilliant! I think i'm really close!

I have one question when you create the new routes
routing table add fib name=useWG
dst-address=0.0.0.0/0 gwy=wg-client table=useWG
/routing rule add action=lookup-only-in-table src-address=10.0.1.0/24 table=useWG
I assume that gwy=wg-client refers to the ip address of the wireguard interface you created, am I right?
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 18168
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Wireguard Success For The Beginner

Sat Nov 05, 2022 5:34 pm

Nope the interface name !! wg-client
 
ckyrias
just joined
Posts: 4
Joined: Wed May 27, 2020 10:33 pm

Re: Wireguard Success For The Beginner

Fri Nov 11, 2022 6:47 pm

Hi anav. Awesome post!
i managed to setup the scripts for reresolving the DNS. Couldn't use the code in terminal in ROS7.6 for some reason so i set it up manualy. Because is nice since i understand it better reading the code and doing it manualy! :D

anyway i used the last script with netwatch and scheduler. but the schedule disable itself upon success!! any idea waht causes this and how can i stop it?
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 18168
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Wireguard Success For The Beginner

Fri Nov 11, 2022 10:27 pm

Suggest you start a thread for that very subject in beginner or general forums will tackle it there as its not my work but borrowed and thus needs exposure there.
 
ckyrias
just joined
Posts: 4
Joined: Wed May 27, 2020 10:33 pm

Re: Wireguard Success For The Beginner

Sat Nov 12, 2022 10:42 pm

thanks so much for the reply!! will do so mate.
 
efiniste
just joined
Posts: 11
Joined: Fri Mar 14, 2014 6:35 pm

Re: Wireguard Success For The Beginner

Wed Mar 15, 2023 10:39 pm

Just wanted to post a thank you for this thread. Fixed my 3rd party VPN provider config in about 5 minutes while reading the relevant section.
 
daveq
just joined
Posts: 21
Joined: Sun Mar 05, 2023 11:15 pm

Re: Wireguard Success For The Beginner

Thu Mar 30, 2023 4:28 pm

Hi, I went finally through the guide, but probably i have still something wrong.

EDITed and moved to other location
Last edited by daveq on Fri Mar 31, 2023 3:04 pm, edited 1 time in total.
 
404Network
Member
Member
Posts: 316
Joined: Wed Feb 16, 2022 2:04 pm

Re: Wireguard Success For The Beginner

Thu Mar 30, 2023 5:05 pm

This is not the place to get issues solved if you have input to improve the article OR you want something explicitly explained in the article that is hard to understand FILL yer boots.
Otherwise suggest posting in the regular forums such as beginner or general.
When you do ensure you note you are using ipv6 and a network diagram also helps
 
daveq
just joined
Posts: 21
Joined: Sun Mar 05, 2023 11:15 pm

Re: Wireguard Success For The Beginner

Thu Mar 30, 2023 5:23 pm

ok, so added it also here.
viewtopic.php?p=993279#p993279
If you can , please advise, thx
 
papageno
just joined
Posts: 14
Joined: Wed Apr 19, 2023 4:04 pm
Location: Tallinn
Contact:

Re: Wireguard Success For The Beginner

Thu May 04, 2023 10:56 pm

Issue [6] > had it with ROS 7.8, using a Synology.me address to connect to server with public dynamic IP.
In ROS7.9 it seems to be solved, WG tunnel gets up after device (LHGG LTE6) restart & peer gets a handshake. This did not happen with 7.8. No abovementioned solutions / scripts are in use and still it seems to work.
Can anyone confirm this?
I am such a newb that I might overlook something. Just got to a remote location that has LHGG LTE6 dish and no public IP and was ready to implement the solution suggested by @anav (thanks!). Before that upgraded LHGG to 7.9 and after multiple device restarts WG connection seems come up fine without scripts. RB1100AHx4 with ROS7.9 listening as server.
 
ivicask
Member
Member
Posts: 406
Joined: Tue Jul 07, 2015 2:40 pm
Location: Croatia, Zagreb

Re: Wireguard Success For The Beginner

Fri May 19, 2023 10:16 am

Most definitely doesnt work for me, still need to script to fix it after sever side dynamic IP changes...
 
holvoetn
Forum Guru
Forum Guru
Posts: 4317
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: Wireguard Success For The Beginner

Fri May 19, 2023 10:22 am

1- your problem has nothing to do with the topic for this thread, that aside
2- the issue you are most likely referring to (inability to resolve IP address at startup of client peer and then wireguard is not working) is effectively not solved. But again, the issue only occurs during startup of peer (which in my view is a bug). If the dynamic IP changes after the peer already has been properly started, it does change and follow the new address.
 
Rox169
Member
Member
Posts: 412
Joined: Sat Sep 04, 2021 1:47 am

Re: Wireguard Success For The Beginner

Fri May 19, 2023 10:34 am

Hi,

Im sorry but this guide is crazy and one big mess and you call it for beginners. Why you do not make easy guide where you will explain all on examples?

Look here how looks guide for beginners :https://help.mikrotik.com/docs/display/ROS/WireGuard
 
ivicask
Member
Member
Posts: 406
Joined: Tue Jul 07, 2015 2:40 pm
Location: Croatia, Zagreb

Re: Wireguard Success For The Beginner

Fri May 19, 2023 10:37 am

1- your problem has nothing to do with the topic for this thread, that aside
2- the issue you are most likely referring to (inability to resolve IP address at startup of client peer and then wireguard is not working) is effectively not solved. But again, the issue only occurs during startup of peer (which in my view is a bug). If the dynamic IP changes after the peer already has been properly started, it does change and follow the new address.
I dont have issue with startup.I set and start tunnel, it works for 24 hours then server side IP changes.
Client never recovers from this until i re-toggle peer so it refreshes IP.

HOW is this not related to topic where there are 5 different scripts which fix the above mentioned issue?
 
holvoetn
Forum Guru
Forum Guru
Posts: 4317
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: Wireguard Success For The Beginner

Fri May 19, 2023 10:41 am

I dont have issue with startup.I set and start tunnel, it works for 24 hours then server side IP changes.
Client never recovers from this until i re-toggle peer so it refreshes IP.
It works for me.
Do you have keep-alive active on client side ?
Best to start separate topic with your specific config.
 
ivicask
Member
Member
Posts: 406
Joined: Tue Jul 07, 2015 2:40 pm
Location: Croatia, Zagreb

Re: Wireguard Success For The Beginner

Fri May 19, 2023 10:45 am

I dont have issue with startup.I set and start tunnel, it works for 24 hours then server side IP changes.
Client never recovers from this until i re-toggle peer so it refreshes IP.
It works for me.
Do you have keep-alive active on client side ?
Best to start separate topic with your specific config.
Yes i do and what does keepalive helps when it keeps sending keepalive packet to wrong IP, wireguard peer takes IP on startup and never checks it again, thats facts and how it works and why users made scripts to fix it, there is nothing in wireguard config to fix this.
 
holvoetn
Forum Guru
Forum Guru
Posts: 4317
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: Wireguard Success For The Beginner

Fri May 19, 2023 10:46 am

Hi,

Im sorry but this guide is crazy and one big mess and you call it for beginners. Why you do not make easy guide where you will explain all on examples?

Look here how looks guide for beginners :https://help.mikrotik.com/docs/display/ROS/WireGuard
That specific guide is the very first place to start, yes.
Heck, that's the one I used when I first started using Wireguard (there was nothing else :lol: ).
But it barely covers all possible pitfalls.

Hence anav made this topic, because he got a bit tired of responding the same questions over and over again, I guess.
And I know quite a few have had excellent results from following the pieces they were missing from this topic.
Look at it as a reference guide (that's how I see it).

If you don't like it, then don't look at it or make your own according to your standards. It's a free world, hey ?
Anyhow, I'm sure Anav will provide you the required answers.
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 18168
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Wireguard Success For The Beginner

Fri May 19, 2023 4:19 pm

Those with the motivation and capacity to learn will benefit from the article. If one is looking for spoon feeding I agree, its not ideal.
If there is something that one does not understand or feels can be stated better, I am always looking for input/feedback to make the article better.
Ranting complaints are ignored as they provide zero value. VPN is not a beginner concept and one should have a solid grasp of other basic parts of RoS to tackle Wireguard. That being said, its by far the easiest VPN to understand (accessible), I believe, and thus why I spent time on the subject.
 
howdey57
Member Candidate
Member Candidate
Posts: 127
Joined: Wed Dec 31, 2014 2:36 pm

Re: Wireguard Success For The Beginner

Fri May 19, 2023 4:29 pm

This is a useful guide. I used it successfully.

The problem I see is that this site is a long stringy list of good ideas and suggestions but there is no "stake in the ground". It's a bit like what Wikipedia would be if it was based on a forum. What would be good is if there was a wiki type site that we all could use and build a common set of pages. Has anyone asked Mikrotik if we could have a corner of their site. Then anav could keep his "bible" there.
 
ivicask
Member
Member
Posts: 406
Joined: Tue Jul 07, 2015 2:40 pm
Location: Croatia, Zagreb

Re: Wireguard Success For The Beginner

Mon May 22, 2023 1:46 pm

I just noticed that above script which checks for last handshake >1min keeps spaming it after implementing it and realized i can no longer achieve last handshake lower then 2min, i used to have it set persistent keepalive @ 10 sec on all routers and i know it kept resetting to 0 every 10 sec properly, now no matter what i enter both sides minimum last handshake seams to be 2mins, so i had to adjust script to >2min.

Was something changed in 7.7 + updates? Could anyone else confirm this?
 
holvoetn
Forum Guru
Forum Guru
Posts: 4317
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: Wireguard Success For The Beginner

Wed May 24, 2023 1:45 pm

It looks like latest 7.10b8 FINALLY solves that pesky DNS resolve bug.
Tested on mAP and it seems to work.
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 18168
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Wireguard Success For The Beginner

Wed May 24, 2023 3:46 pm

can you expand on what you mean? Does MT now have an automated way of maintaining connection without a script??
 
holvoetn
Forum Guru
Forum Guru
Posts: 4317
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: Wireguard Success For The Beginner

Wed May 24, 2023 3:58 pm

*) wireguard - retry "endpoint-address" DNS query on failed resolve;

The problem where the complete wireguard process stops to function if no initial DNS resolution is in place at boot time.
That seems to be solved now. It will retry until DNS can be resolved and packets start to flow without the usual peer-toggling-dance being required.

Testing if this also solves "in-between-DNS-issues" is a bit trickier to do but from the release notes I would think it does.
 
Whitehawk29FR
just joined
Posts: 19
Joined: Thu Oct 06, 2022 12:14 pm

Re: Wireguard Success For The Beginner

Thu May 25, 2023 5:26 pm

Hi all,

How much bandwith I should have through wireguard VPN between CCR1036 / CCR1072 over 1G link ?
CPU goes to 10% on CCR1036 during speed test with 2 cores ~50%
Speed test gives only ~200M .. would like some more .. Any idea ? :shock:

Thanks !
 
holvoetn
Forum Guru
Forum Guru
Posts: 4317
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: Wireguard Success For The Beginner

Thu May 25, 2023 5:28 pm

Watch one core. If it's close to 100%, you're at the max.
Wireguard is not multi-processor.

I think I remember a test from Zvevna (not sure which equipment) showing WG speed close to 1Gb.

Did some tests of my own between RB5009 and AX Lite (!!), arriving at around 400Mb over 1G links. Then the processor on AX Lite gave up :lol:
Last edited by holvoetn on Thu May 25, 2023 5:34 pm, edited 1 time in total.
 
Rox169
Member
Member
Posts: 412
Joined: Sat Sep 04, 2021 1:47 am

Re: Wireguard Success For The Beginner

Thu May 25, 2023 5:33 pm

Do you know if they can make wireguard multi-processor?
 
holvoetn
Forum Guru
Forum Guru
Posts: 4317
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: Wireguard Success For The Beginner

Thu May 25, 2023 5:35 pm

Ask Jason A. Donenfeld.
He invented it.

https://www.wireguard.com
 
Filament
newbie
Posts: 26
Joined: Fri Jan 24, 2020 1:32 pm

Re: Wireguard Success For The Beginner

Fri Jul 07, 2023 1:14 am

I've tried to read the guide several times but I still cannot understand it properly to apply it to my situation :(

I need to create a site-to-site VPN from site A to site B.

Mikrotik on site A is behind an ISP router. That router has a public dynamic IP address. Thankfully, it doesn't suffer any CGNAT. I have the admin password of the ISP router, so I can open any ports I want.

Mikrotik on site B is behind an ISP-owned router. That router has a public dynamic IP address, but unfortunately it's suffering a terrible CGNAT applied by the ISP. Cannot open any ports at all :(

I've tried following the "Site to Site WireGuard tunnel" explained here:
https://help.mikrotik.com/docs/display/ROS/WireGuard

But it doesn't work. Could anyone point me to an example that covers my situation?

EDIT: What I currently have is this solution, using SSTP. I would like to have the same benefits, but using Wireguard instead.

Current Mikrotik config on site A (port 42345 is open on ISP router)
/ip address add address=192.168.100.2/24 interface=bridge network=192.168.100.0
/ip route add disabled=no dst-address=0.0.0.0/0 gateway=192.168.100.1
/interface sstp-server server set enabled=yes port=42345
/ppp secret add local-address=172.26.1.1 name=vpnuser password=blablabla profile=default-encryption remote-address=172.26.1.2 routes="192.168.200.0/24 172.26.1.2 1" service=sstp
/ip cloud set ddns-enabled=yes ddns-update-interval=2m
Current Mikrotik config on site B (cannot open any ports)
/ip address add address=192.168.200.2/24 interface=bridge network=192.168.200.0
/ip route add disabled=no dst-address=0.0.0.0/0 gateway=192.168.200.1
/ip route add disabled=no dst-address=192.168.100.0/24 gateway=sstp-out1
/interface sstp-client add connect-to=blablabla.sn.mynetname.net disabled=no name=sstp-out1 port=42345 profile=default-encryption user=vpnuser password=blablabla verify-server-address-from-certificate=no
Thanks a lot in advance!
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 18168
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Wireguard Success For The Beginner

Fri Jul 07, 2023 4:12 am

Open a new thread, this one is for particular questions on the information provided in the article, not for issues etc..
When you post the new thread ensure your include complete config of both routers.
/export file=anynameyouwish ( minus router serial number, any public wanip information, keys etc.. _
 
ccky
just joined
Posts: 6
Joined: Fri Jan 27, 2023 2:58 am

Re: Wireguard Success For The Beginner

Sat Dec 02, 2023 10:30 pm

Hi @anav,
appreciate the effort you've made with all those guides - in fact I consider this thread the starting point of my curiosity towards MT config ;)
It might have been your hidden agenda to fool proof the topic against thoughtless "copy-paste" approach - in this case: well played and thank you!

If not however, for the sake of future visitors seeking help you might want to correct point 7.6 (reminded me of all the pain while using this topic as checklist for new config :D )
6. DNS - If one has identified a subnet (be it a vlan or not) that will be going through the wireguard tunnel, ensure you modify the IP DHCP NETWORK SERVER
/ip dhcp-server network
add address=10.10.0.0/24 comment=LAN-4-WG dns-server=3rdPartyDNS gateway=10.10.0.1
rationale:
MT RoS SETTINGS:
2. IP address - Add address=10.10.10.2/24 interface=wireguard1
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 18168
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Wireguard Success For The Beginner

Sat Dec 02, 2023 10:42 pm

First, thanks for reviewing and making suggestions!!

Not sure I follow?
The setting in red, is under the heading of
/ip dhcp-network server NOT /ip address ???
 
ccky
just joined
Posts: 6
Joined: Fri Jan 27, 2023 2:58 am

Re: Wireguard Success For The Beginner

Sun Dec 03, 2023 4:47 am

Then - why would you assign DNS provided by 3rd party to some other innocent subnet ;)

Should have painted it in both places for the sake of clarity.
6. DNS - If one has identified a subnet (be it a vlan or not) that will be going through the wireguard tunnel, ensure you modify the IP DHCP NETWORK SERVER
/ip dhcp-server network
add address=10.10.0.0/24 comment=LAN-4-WG dns-server=3rdPartyDNS gateway=10.10.0.1
 
User avatar
anav
Forum Guru
Forum Guru
Topic Author
Posts: 18168
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Wireguard Success For The Beginner

Sun Dec 03, 2023 6:26 pm

I see the issue. The paragraph stood on its own and if you tried to correlate with the previous para, it would seem non-congruent. I have adjusted it so that confusion is removed. Much thanks!

Who is online

Users browsing this forum: Tajson999 and 3 guests