I want to find out how much overhead wireguard creates on my machine in terms of latency. However, my server is remote, so I would like to test it solely on the machine to avoid measuring the whole network latency.
So for measuring the latency, I thought about the following setup.
I add two wireguard devices to the machine, wg0 and wg1. I then send a packet to wg0, which encrypts the packet and sends it to wg1. Wg1 then decrypts it and sends it to a local port to measure the time it takes between sending and receiving the packet.
My wg0 conf:
[Interface]
Address = 10.0.0.1/24
ListenPort = 51871
[Peer]
AllowedIPs = 10.0.0.1/24, 10.0.1.1/24
Endpoint = localhost:51872
My wg1 conf:
[Interface]
Address = 10.0.1.1/24
ListenPort = 51872
[Peer]
AllowedIPs = 10.0.0.1/24, 10.0.1.1/24
Endpoint = localhost:51871
I have tried using the following configuration but then I am unable to setup wg1 as the setup fails at
ip -4 route add 10.0.0.0/24 dev wg1
due to
RTNETLINK answers: File exists
Which makes sense as because this is the IP range of the wg0 device
My wg0 conf:
[Interface]
Address = 10.0.0.1/24
ListenPort = 51871
PostUp = route add -net 10.0.1.0/24 gw 10.0.0.1
PostDown = route delete -net 10.0.1.0/24 gw 10.0.0.1
[Peer]
AllowedIPs = 10.0.0.1/24, 10.0.1.1/24
Endpoint = localhost:51872
My wg1 conf:
[Interface]
Address = 10.0.1.1/24
ListenPort = 51872
PostUp = route add -net 10.0.0.1/24 gw 10.0.1.1
PostDown = route delete -net 10.0.0.1/24 gw 10.0.1.1
[Peer]
AllowedIPs = 10.0.0.1/24, 10.0.1.1/24
Endpoint = localhost:51871
However, I can not get the routing set up so that my packet actually traverses the wg devices. The devices also do not perform a handshake atm. Is it even possible? Or can you recommend another setup?.
My OS is ubuntu 20.04 server. As a sidenote, I want to compare this to another measurement I took where one of the wireguard devices runs in a virtual machine. In this setup, I just ran wg0 on the host and wg1 in the VM. Basically, now I want to find out the overhead of running a wireguard gateway in a VM compared to running it natively on the machine.
Solution:
As suggested, I am now running the second wg device in a different namespace. The setup was straightforward because even if the wg device is moved to a different namespace, the listen-port stays in the original namespace. The RTT is about 2/3 compared to running wg1 in a Linux VM for anyone interested.
Thanks for the suggestions!