Community discussions

MikroTik App
 
User avatar
urbinek
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 87
Joined: Mon Oct 25, 2010 4:11 pm

Loosing internet access via WireGuard

Mon Feb 07, 2022 11:42 pm

I am not sure if i did someting wrong.

I did simple RoadWarrior style configuration where mobile client is connecting to Internet via mikrotik and wireguard

Initiallty this configuration worked but after a while it started to trow errors:
22:33:32 wireguard,debug wireguard1: bQe944f7N4kCSXROQcDf1kheES0gTHzSsvGiUtZWUWQ=: Handshake for peer did not complete after 5 seconds, retrying (try 10)
mikrotik conf
mt-export.rsc
android/ios client conf
mt-export.rsc
You do not have the required permissions to view the files attached to this post.
 
holvoetn
Forum Guru
Forum Guru
Posts: 6763
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: Loosing internet access via WireGuard

Mon Feb 07, 2022 11:46 pm

I understood handshake should be at 25 sec.
At least that is the general recommendation for devices behind firewall.
Already tried that on both sides ?
 
User avatar
urbinek
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 87
Joined: Mon Oct 25, 2010 4:11 pm

Re: Loosing internet access via WireGuard

Mon Feb 07, 2022 11:52 pm

Could you explain a little bit more?
 
Sob
Forum Guru
Forum Guru
Posts: 9188
Joined: Mon Apr 20, 2009 9:11 pm

Re: Loosing internet access via WireGuard  [SOLVED]

Tue Feb 08, 2022 1:38 am

You can't have same allowed-address=192.168.99.0/24 for multiple peers on same interface, it should be allowed-address=192.168.99.X/32 (where X is what that peer has).
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 21910
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Loosing internet access via WireGuard

Tue Feb 08, 2022 2:34 am

Concur, My iphone setting is ONE address.
thus your peer settting for allowed addressess
on MT PEER SETTINGS
Android
/interface wireguard peers
add allowed-address=192.168.99.X/32 comment="OnePlus 7" interface=wireguard1 \
persistent-keepalive=1m
public-key=\
add allowed-address=192.168.99.Y/32 comment="iPhone 11" interface=wireguard1 \
persistent-keepalive=1m
public-key=\

For example on my iphone I use 10.2.0.2/32

Nothing wrong with having the endpoint address on iphone or android peer settings to be 0.0.0.0/0 as one is wanting internet through the MT WG server location.

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

The other issue could be routes.......
WHERE ARE THEY??
At a minimum you need
dst-address=192.168.99.0/24 gwy=wireguard1 table=main

This also looks suspect:
add action=masquerade chain=srcnat comment="WireGuard -> Internet" \
out-interface=ether1-wan src-address=192.168.99.0/24

There is no need to masquerade traffic coming from your iphone out to the internet??
I suppose it cannot hurt but not sure what you accomplish with it???
UNLESS your MT is behind another Router like an ISP router where you cannot create a static route??
Assuming if true, then at least you can forward ports otherwise the MT couldnt be an MT wg server.


note1; This is not best security practices, not recommended to use plain text services
/ip service
set telnet address=192.168.88.0/24
set ftp address=192.168.88.0/24
set www port=81

note2: this does not look like a legitimate rule as if it was for the establishment of an encrypted connection (VPN) it would be input chain
if it was for port forwarding to a server it would be in the dst nat chain.
add action=accept chain=forward dst-port=443 in-interface=ether1-wan \
log-prefix="fw-log -> " protocol=tcp
 
Sob
Forum Guru
Forum Guru
Posts: 9188
Joined: Mon Apr 20, 2009 9:11 pm

Re: Loosing internet access via WireGuard

Tue Feb 08, 2022 4:46 am

At a minimum you need
dst-address=192.168.99.0/24 gwy=wireguard1 table=main
Please tell me you're joking. What do you think this does?
/ip address
add address=192.168.99.1/24 interface=wireguard1 network=192.168.99.0
 
holvoetn
Forum Guru
Forum Guru
Posts: 6763
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: Loosing internet access via WireGuard

Tue Feb 08, 2022 7:53 am

Neglecting the ip address everyone is using, even himself on iPhone, I guess ?
 
User avatar
urbinek
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 87
Joined: Mon Oct 25, 2010 4:11 pm

Re: Loosing internet access via WireGuard

Tue Feb 08, 2022 10:52 am

You can't have same allowed-address=192.168.99.0/24 for multiple peers on same interface, it should be allowed-address=192.168.99.X/32 (where X is what that peer has).
It seems that changing from network to host alone worked, but i am confused why.

Documentation is not very descriptive on WireGuard and using networks seems to be more flexible configuration for many clients when i do not care about specific IP
Last edited by urbinek on Tue Feb 08, 2022 11:43 am, edited 1 time in total.
 
User avatar
urbinek
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 87
Joined: Mon Oct 25, 2010 4:11 pm

Re: Loosing internet access via WireGuard

Tue Feb 08, 2022 11:04 am

The other issue could be routes.......
WHERE ARE THEY??
At a minimum you need
dst-address=192.168.99.0/24 gwy=wireguard1 table=main
You mean like the one created dynamically by MT whe i've added IP to WireGuard interface?
[admin@home_CRS305] > /ip/route/print 
Flags: D - DYNAMIC; A - ACTIVE; c, d, y - COPY
Columns: DST-ADDRESS, GATEWAY, DISTANCE
    DST-ADDRESS      GATEWAY       DISTANCE
DAd 0.0.0.0/0        1.2.3.4         1
DAc 10.10.10.0/24    bridge-infra         0
DAc 79.175.228.0/22  ether1-wan           0
DAc 172.16.10.0/24   bridge-guest         0
DAc 172.31.100.0/24  bridge-iot           0
DAc 192.168.88.0/24  bridge-home          0
DAc 192.168.99.0/24  wireguard1           0
This also looks suspect:
add action=masquerade chain=srcnat comment="WireGuard -> Internet" \
out-interface=ether1-wan src-address=192.168.99.0/24

There is no need to masquerade traffic coming from your iphone out to the internet??
I suppose it cannot hurt but not sure what you accomplish with it???
UNLESS your MT is behind another Router like an ISP router where you cannot create a static route??
Assuming if true, then at least you can forward ports otherwise the MT couldnt be an MT wg server.
I might fail to mention, but this is my home network. I have no option to route this traffic and i need to nat it locally
note1; This is not best security practices, not recommended to use plain text services
/ip service
set telnet address=192.168.88.0/24
set ftp address=192.168.88.0/24
set www port=81
Agree, I used this for local fuckery, should remove that :)
note2: this does not look like a legitimate rule as if it was for the establishment of an encrypted connection (VPN) it would be input chain
if it was for port forwarding to a server it would be in the dst nat chain.
add action=accept chain=forward dst-port=443 in-interface=ether1-wan \
log-prefix="fw-log -> " protocol=tcp
This is not related with VPN
Last edited by urbinek on Tue Feb 08, 2022 11:25 am, edited 1 time in total.
 
User avatar
urbinek
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 87
Joined: Mon Oct 25, 2010 4:11 pm

Re: Loosing internet access via WireGuard

Tue Feb 08, 2022 11:12 am

Neglecting the ip address everyone is using, even himself on iPhone, I guess ?
How come?
 
holvoetn
Forum Guru
Forum Guru
Posts: 6763
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: Loosing internet access via WireGuard

Tue Feb 08, 2022 11:21 am

Neglecting the ip address everyone is using, even himself on iPhone, I guess ?
How come?
Running joke/discussion around here between anav and Sob.
anav seems to be amongst the very few (if not the only one) insisting on NOT using internal IP addresses on WG-endpoints (which BTW DOES work without on Mikrotik to Mikrotik connections, no discussion there. But it's mighty confusing for most people).
But for the connection from his iPhone he has to or it will not work.
 
User avatar
urbinek
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 87
Joined: Mon Oct 25, 2010 4:11 pm

Re: Loosing internet access via WireGuard

Tue Feb 08, 2022 11:51 am

Now it makes sense :)

For me it's natural to use IPs for vpn endpoints, but routing by interface might be more elastic in bigger environments i think
 
User avatar
Znevna
Forum Guru
Forum Guru
Posts: 1352
Joined: Mon Sep 23, 2019 1:04 pm

Re: Loosing internet access via WireGuard

Tue Feb 08, 2022 11:57 am

So many topics/issues tagged with WireGuard that have nothing to do with WireGuard.
 
User avatar
urbinek
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 87
Joined: Mon Oct 25, 2010 4:11 pm

Re: Loosing internet access via WireGuard

Tue Feb 08, 2022 12:07 pm

So many topics/issues tagged with WireGuard that have nothing to do with WireGuard.
Good that mine was actually related with bad WireGuard configuration fixed by propper WireGuard configuration :)
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 21910
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Loosing internet access via WireGuard

Tue Feb 08, 2022 1:59 pm



How come?
Running joke/discussion around here between anav and Sob.
anav seems to be amongst the very few (if not the only one) insisting on NOT using internal IP addresses on WG-endpoints (which BTW DOES work without on Mikrotik to Mikrotik connections, no discussion there. But it's mighty confusing for most people).
But for the connection from his iPhone he has to or it will not work.
Yes, I forget about the IP address wrt not needed the IP Route.
I prefer to use Routes then IP address. IP address confuses me LOL

For the record Holvoeten I dont espouse anything on non-MT devices. My iphone has an Ip address assigned to it, so that on my MT I can know which IP is coming through the tunnel.
Not necessarily the case for MT devices where I care about the IP address of individual devices coming through, not one, and not necessarily just one subnet, I could care less what the IP address of the wg interface is ;-)

In this case the issue was PEER overlap. Probably caused by over reliance on IP addresses and wg interfaces ;-P
 
Sob
Forum Guru
Forum Guru
Posts: 9188
Joined: Mon Apr 20, 2009 9:11 pm

Re: Loosing internet access via WireGuard

Tue Feb 08, 2022 2:09 pm

... using networks seems to be more flexible configuration for many clients when i do not care about specific IP
The catch is that when you have multiple peers connected to same interface, router must use something to determine what should it send to which client. If you have allowed-address=192.168.99.0/24 for both and there's packet to 192.168.99.x, should it go to first one or second one? It's impossible to choose. If there's only one peer (e.g. on client side), then whole subnet is fine, as all will be sent to server and it can do routing between clients.
 
Sob
Forum Guru
Forum Guru
Posts: 9188
Joined: Mon Apr 20, 2009 9:11 pm

Re: Loosing internet access via WireGuard

Tue Feb 08, 2022 2:23 pm

... which BTW DOES work without on Mikrotik to Mikrotik connections ...
You can do the same with Linux, but why would anyone do it?
 
holvoetn
Forum Guru
Forum Guru
Posts: 6763
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: Loosing internet access via WireGuard

Tue Feb 08, 2022 2:42 pm

... which BTW DOES work without on Mikrotik to Mikrotik connections ...
You can do the same with Linux, but why would anyone do it?
I know and you should also know in which camp I am :lol:
 
User avatar
urbinek
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 87
Joined: Mon Oct 25, 2010 4:11 pm

Re: Loosing internet access via WireGuard

Tue Feb 08, 2022 4:50 pm

The catch is that when you have multiple peers connected to same interface, router must use something to determine what should it send to which client.
Well, each peer have unique set of keys which are not shared across other peers so why it can't be used?
They are used in logs for identifying peers

But i guess that's MT implementation, so I'll roll with it.
 
Sob
Forum Guru
Forum Guru
Posts: 9188
Joined: Mon Apr 20, 2009 9:11 pm

Re: Loosing internet access via WireGuard

Tue Feb 08, 2022 5:06 pm

Yes, keys are unique, but how does that help? How can you tell that e.g. 192.168.99.3 should go to peer A and not peer B?
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 21910
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Loosing internet access via WireGuard

Tue Feb 08, 2022 6:25 pm

Encryption does not equate to routing or filtering, two separate functions.
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 21910
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Loosing internet access via WireGuard

Tue Feb 08, 2022 9:00 pm

The catch is that when you have multiple peers connected to same interface, router must use something to determine what should it send to which client.
Well, each peer have unique set of keys which are not shared across other peers so why it can't be used?
They are used in logs for identifying peers

But i guess that's MT implementation, so I'll roll with it.
Sob is 99.9999% correct, no one is perfect ;-P

Discussion:

The most common error occurs when you have multiple endpoints for users INTERNET TRAFFIC!.
Lets say you have subnet A going out WG1 Peer1 to NordVPN WG implementation
Lets say you have subnet B going out WG1 Peer2 to PureVPN WG implementation
Lets say you have subnet C going out WG2 to another MT device for internet

NETWORK SETUP

WG1 peers
Peer B allowed addresses=0.0.0.0/0
Peer A allowed addresses=0.0.0.0/0

WG2 peers
Peer C allowed addresses=0.0.0.0/0

/ip route
dst-address=0.0.0.0/0 gwy=WG1 routing-table=useWG1
dst-address=0.0.0.0/0 gwy=WG2 routing-table=useWG2

/routing table add name=useWG1 fib
/routing table add name=useWG2 fib

/routing rule src-address=subnetA action=lookup-only-in-table table=useWG1
/routing rule src-address=subnetB action=lookup-only-in-table table=useWG1
/routing rule src-address=subnetC action=lookup-only-in-table table=useWG2

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

Results/Observations:

(1) Regardless of PEER settings, the Router will attempt to find the correct Route FIRST, and then check, for the applicable interface, if there is a peer matching entry.

(2) The order of the peers, within each WG interface, in the wireguard settings, determines the order in which the router will attempt that matching.
(note: In the case of WG1, it will thus always be the Peer B.)

(2) User A Session: Router finds route for subnet A, out WG1. Router matches destination address to that assigned on Peer B. Traffic is sent out the wrong tunnel.
(note: the other end of the tunnel will probably filter out the traffic and thus the end result is FAILED BROWSING SESSION - nil return traffic)

(3) User B Session : Router finds route for subnet B, out WG1. Router matches destination address to that on Peer B. Traffic is sent out the correct tunnel.

(4) User C Session: Router finds route for Subnet C, out WG2. Router checks WG2 peers and finds match. Traffic is sent out the correct tunnel.

Conclusion: One cannot guarantee success of traffic when one has overlapping Allowed Addresses in the Peers of a single wireguard interface. A separate wireguard interface with proper routing will ensure success.
 
User avatar
urbinek
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 87
Joined: Mon Oct 25, 2010 4:11 pm

Re: Loosing internet access via WireGuard

Wed Feb 09, 2022 11:06 am

Yes and no, my end goal is simpler. I want to provide Internet access via my Mikrotik

I do not want to have 0.0.0.0/0 as allowed-addresses but some specified network e.g. /24 that i can manage later. I do not care about client IPs in particular as long as they are from defined /24 network


MT should easily make associations between individual /24 host, unique peer and unique key pair to create dynamic route.
 
User avatar
urbinek
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 87
Joined: Mon Oct 25, 2010 4:11 pm

Re: Loosing internet access via WireGuard

Wed Feb 09, 2022 11:22 am

I've just found this:
https://www.procustodibus.com/blog/2021/01/same-key-multiple-peers
WireGuard, in fact, uses a peer’s public key as the lookup key in its internal table of connected peers; when sending encrypted traffic to a peer, WireGuard consults this table to determine the public IP address and port (aka endpoint) to which it should send the encrypted traffic.
If i understand it correctly WireGuard already uses unique keys for distinguish individual clients instead of IPs itself
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 21910
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Loosing internet access via WireGuard

Wed Feb 09, 2022 1:35 pm

I wonder if thats talking about the initial handshake. That sounds like wAy to much overhead for every traffic packet.
 
holvoetn
Forum Guru
Forum Guru
Posts: 6763
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: Loosing internet access via WireGuard

Wed Feb 09, 2022 1:42 pm

I wonder if thats talking about the initial handshake. That sounds like wAy to much overhead for every traffic packet.
The way I see it:
Every packet is being encrypted, send over the interface and decrypted on the other side.
Otherwise it's not a secured tunnel anymore.
So it's not that much overhead at all since those keys need to be used already, an intelligent lookup can be blazing fast.
Heck, that's a trick from the old computer days to store some tables simply in ROM to use as lookup (one cycle) instead of calculating the result (multitude of cycles).
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 21910
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: Loosing internet access via WireGuard

Wed Feb 09, 2022 1:50 pm

I wonder if thats talking about the initial handshake. That sounds like wAy to much overhead for every traffic packet.
The way I see it:
Every packet is being encrypted, send over the interface and decrypted on the other side.
Otherwise it's not a secured tunnel anymore.
So it's not that much overhead at all since those keys need to be used already, an intelligent lookup can be blazing fast.
Heck, that's a trick from the old computer days to store some tables simply in ROM to use as lookup (one cycle) instead of calculating the result (multitude of cycles).
Yeah in my head the concept of a tunnel is that you create safe passage, and the traffic just barrels through it without any additional noise. In other words you create an encrypted path and dont need to touch the data with encryption.......... probably fantasy land thinking ( I must be the only one that thinks a tunnel is like a worm hole LOL )
Last edited by anav on Wed Feb 09, 2022 4:06 pm, edited 1 time in total.
 
holvoetn
Forum Guru
Forum Guru
Posts: 6763
Joined: Tue Apr 13, 2021 2:14 am
Location: Belgium

Re: Loosing internet access via WireGuard

Wed Feb 09, 2022 2:42 pm

Actually that's a very good visualization of what a tunnel is.
A Worm Hole.
 
User avatar
mozerd
Forum Veteran
Forum Veteran
Posts: 926
Joined: Thu Oct 05, 2017 3:39 pm
Location: Canada
Contact:

Re: Loosing internet access via WireGuard

Wed Feb 09, 2022 2:52 pm

The way I see it:
Every packet is being encrypted, send over the interface and decrypted on the other side.
Otherwise it's not a secured tunnel anymore.
So it's not that much overhead at all since those keys need to be used already, an intelligent lookup can be blazing fast.
Heck, that's a trick from the old computer days to store some tables simply in ROM to use as lookup (one cycle) instead of calculating the result (multitude of cycles).
Good seeing :D
The virtual tunnel interface is based on a proposed fundamental principle of secure tunnels: an association between a peer public key and a tunnel source IP address. It uses a single round trip key exchange, based on NoiseIK, and handles all session creation transparently to the user using a novel timer state machine mechanism. Short pre-shared static keys—Curve25519 points—are used for mutual authentication in the style of OpenSSH.

The protocol provides strong perfect forward secrecy in addition to a high degree of identity hiding. Transport speed is accomplished using ChaCha20Poly1305 authenticated-encryption for encapsulation of packets in UDP.

The overall design allows for allocating no resources in response to received packets, and from a systems perspective, there are multiple interesting Linux implementation techniques for queues and parallelism.
So this is from the mind of Jason A. Donenfeld the creator of WireGuard. I know that you @holvoetn have taken the time and effort to read and inwardly digest Donenfeld's WhitePaper and I have encouraged everyone else to do the same especially our resident configuration GURU @anav. :)
Last edited by mozerd on Wed Feb 09, 2022 2:54 pm, edited 2 times in total.
 
Sob
Forum Guru
Forum Guru
Posts: 9188
Joined: Mon Apr 20, 2009 9:11 pm

Re: Loosing internet access via WireGuard

Wed Feb 09, 2022 2:52 pm

If i understand it correctly WireGuard already uses unique keys for distinguish individual clients instead of IPs itself
Yes, but that's for the transport part, encrypted packets between peers. WG doesn't care about ports and addresses as much as other VPNs. It remembers peer's current endpoint, but if peer suddenly sends packet from completely different enpoint, WG accepts it, recognizes that it's from that peer (thanks to unique keys) and switches peer's endpoint to new one. But it doesn't help with traffic inside the tunnel, there's no relation between those addresses and keys.

Who is online

Users browsing this forum: LukasL and 56 guests