Community discussions

MikroTik App
 
User avatar
mozerd
Forum Veteran
Forum Veteran
Topic Author
Posts: 891
Joined: Thu Oct 05, 2017 3:39 pm
Location: Canada
Contact:

WireGuard useful learning [Linux]

Sun Mar 03, 2024 3:08 pm

YET ANOTHER SYSADMIN WEBSITE
The basics to know about wireguard routing

Introduction
Now that we learned how to configure wireguard on multiple operating systems, let’s take a break and review what running wireguard does to your routing table.

Wireguard routing basics
The most important thing to understand is that you do not configure routes with wireguard: the AllowedIPs you configure for a peer become your routes!

This has several consequences:

These routes are always in your routing table, even when the peer is unreachable.
If you accept traffic from a range of IPs through wireguard, all traffic towards this range will go through wireguard too.
This is what you want most of the time, but it is cumbersome if you ever:

want to redirect all your internet traffic through wireguard.
would like to have redundancy to reach a distant host through more than one wireguard peer.
want to route all traffic destined to the internet.
The simplest setup
Let’s consider the two hosts and two networks in the following schematic:
https://www.adyxax.org/static/wireguard ... drawio.svg

Simplest setup

The first network is physical and connects the eth0 interfaces of the two hosts on 192.168.1.0/24. The second network is virtual and virtually connects the wg0 wireguard interfaces of the two hosts on 10.1.2.0/24.

The first host is named Dalinar and has a single physical network interface eth0 with ip address 192.168.1.10/24. We will configure wireguard with ip address 10.1.2.1/24, wireguard private key kIrQqJA1kEX56J9IbF8crSZOEZQLIAywjyoOqmjzjHU= and public key zfxxxWIMFYbEoX55mXO0gMuHk26iybehNR9tv3ZwJSg=.

The second host is named Kaladin and has a single physical network interface eth0 with ip address 192.168.1.20/24. We will configure wireguard with ip address 10.1.2.2/24, wireguard private key SIg6cOoTyJRGIYSZ9ACRryL182yufKAtTLHK/Chb+lo= and public key BN89Ckhy4TEHjy37zz/Mvi6cOksnKzHHrnHXx5YkMlg=.

Wireguard configurations
Dalinar’s wireguard configuration looks like:

[Interface]
PrivateKey = kIrQqJA1kEX56J9IbF8crSZOEZQLIAywjyoOqmjzjHU=
ListenPort = 342
Address = 10.1.2.1/32

[Peer]
PublicKey = BN89Ckhy4TEHjy37zz/Mvi6cOksnKzHHrnHXx5YkMlg=
Endpoint = 192.168.1.20:342
AllowedIPs = 10.1.2.2/32
Kaladin’s wireguard configuration looks like:

[Interface]
PrivateKey = SIg6cOoTyJRGIYSZ9ACRryL182yufKAtTLHK/Chb+lo=
ListenPort = 342
Address = 10.1.2.2/32

[Peer]
PublicKey = zfxxxWIMFYbEoX55mXO0gMuHk26iybehNR9tv3ZwJSg=
Endpoint = 192.168.1.10:342
AllowedIPs = 10.1.2.1/32
Important things to note
Look carefully at the netmask in the Address and AllowedIPs: I did not use /24 anywhere! I did this because:

wireguard does not need it.
it would become confusing with many peers.
we should try and keep the cleanest routing tables possible.
I could have used a /24 netmask for the Address field, this would work and look natural as this is how all networking devices usually work. I do not because I do not want the OS to have a /24 route to the wg0 interface without a next hop, I will need it when we introduce a distant host to our configuration in the next article.

I could have put one for the AllowedIPs though, but this would only work in this particular case. As soon as you add more than one peer the configuration would break.

A key takeaway is this: Even though with other vpn solutions (or traditional networking) we are used to have hosts logically sharing a network like 10.1.2.0/24 in our case, this is absolutely not a wireguard requirement. We could have used 10.1.2.1 for Dalinar’s wg0 and 172.16.0.1 for Kaladin’s wg0 and besides changing these IPs the configuration would be exactly the same and work directly. Let that sink in!

Routing tables
With this setup if Dalinar was a Linux, its routing table would look like this with ip -4 r:

10.1.2.2 dev wg0 scope link
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.10 metric 600
Kaladin’s would look very similar:

10.1.2.1 dev wg0 scope link
192.168.1.0/24 dev eth0 proto kernel scope link src 192.168.1.20 metric 600
Wireguard routing part two
 
DarkNate
Forum Guru
Forum Guru
Posts: 1017
Joined: Fri Jun 26, 2020 4:37 pm

Re: WireGuard useful learning [Linux]

Sun Mar 03, 2024 6:00 pm

WireGuard is a peer-to-peer protocol, it doesn't support server/client functionality. Your blog should accurately explain this relationship of peer-to-peer from a network standpoint.

The Wikipedia article seems fairly clear to me:
https://en.wikipedia.org/wiki/WireGuard
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 19395
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: WireGuard useful learning [Linux]

Sun Mar 03, 2024 6:16 pm

Interesting write up. I like some of it and would word things differently for MT users but overall its reasonable for overall understanding.
Concur with DarkNate's input as well.
 
User avatar
Larsa
Forum Guru
Forum Guru
Posts: 1068
Joined: Sat Aug 29, 2015 7:40 pm
Location: The North Pole, Santa's Workshop

Re: WireGuard useful learning [Linux]

Tue Mar 05, 2024 12:20 am

Let me rephrase that for both of you! ;-)
WireGuard is an encrypted tunnel protocol that can be used in all types of topologies, including client/server, spoke/hub, mesh, and much more. @mozerd, great articles btw!
 
DarkNate
Forum Guru
Forum Guru
Posts: 1017
Joined: Fri Jun 26, 2020 4:37 pm

Re: WireGuard useful learning [Linux]

Mon Mar 18, 2024 8:50 pm

including client/server
Nope. The protocol literally is peer to peer, it is not a server/client protocol like OpenVPN. This is about as stupid as saying OSPF has a sever and a client. People are really stuck up on NATted server/client model to the point they forgot what peer to peer really means.
 
User avatar
anav
Forum Guru
Forum Guru
Posts: 19395
Joined: Sun Feb 18, 2018 11:28 pm
Location: Nova Scotia, Canada
Contact:

Re: WireGuard useful learning [Linux]

Mon Mar 18, 2024 8:51 pm

Larsa you need to stay off the magic shrooms. :-)
Next your going to claim you wear a cross, eat garlic and spend hours in front of mirrors.
 
User avatar
Larsa
Forum Guru
Forum Guru
Posts: 1068
Joined: Sat Aug 29, 2015 7:40 pm
Location: The North Pole, Santa's Workshop

Re: WireGuard useful learning [Linux]

Mon Mar 18, 2024 9:08 pm

I'm sorry, but I have terrible allergies to such things so I've never dared to try! ;-) Btw, @DarkNate, can you please explain what a "client/server" tunnel is to a dummy like me?
 
DarkNate
Forum Guru
Forum Guru
Posts: 1017
Joined: Fri Jun 26, 2020 4:37 pm

Re: WireGuard useful learning [Linux]

Tue Mar 19, 2024 11:37 am

I just explained with a famous example, OpenVPN! OpenVPN is a server/client model.

WireGuard is a peer to peer overlay network protocol. It's fully layer 3, peer to peer. By default every peer can talk to any other peer using unicast routing, there is no "server" and there is no "client". Read the papers published by Jason, the creator of WireGuard. He knows better than you, me, and even MikroTik employees about the WireGuard protocol.
 
User avatar
Larsa
Forum Guru
Forum Guru
Posts: 1068
Joined: Sat Aug 29, 2015 7:40 pm
Location: The North Pole, Santa's Workshop

Re: WireGuard useful learning [Linux]

Tue Mar 19, 2024 6:02 pm

It's true that OpenVPN is often configured in a "client/server" style especially for remote access use cases.

However, the same applies to WireGuard. Both of these tunnel protocols, along with IPsec and SSTP, have the flexibility to act as "initiators" or passive "responders". It's simply a matter of configuration, not a fundamental limitation of the tunnel protocols themselves.

Who is online

Users browsing this forum: jurajhampel and 31 guests