Server
A central server gives remote devices a reachable target, allowing them to traverse firewalls and NAT and connect. Let’s create a server and generate and configure a remote device.
Preparation
You’ll need:
- Public Domain Name or Static IP
- Linux Server and the ability to port-forward UDP 51820 to it
- To choose a routing network IP block
A dynamic domain name will work and it’s reasonably priced (usually free). You just need something for the peers to connect to, though a static IP is best. You can possibly break connectivity if your IP changes while your peers are connected or have the old IP cached.
We use Debian in this example and derivatives should be similar. UDP 51820 is the standard port but you can choose another if desired.
You must also choose a VPN network that doesn’t overlap with your existing networks. We use 192.168.100.0/24 in this example. This is the internal network used inside the VPN to route traffic.
Installation
sudo apt install wireguard-tools
Configuration
The server needs just a single config file, and it will look something like this:
[Interface]
Address = 192.168.100.1/24
ListenPort = 51820
PrivateKey = sGp9lWqfBx+uOZO8V5NPUlHQ4pwbvebg8xnfOgR00Gw=
We choose 192.168.100.0/24
as our VPN internal network and picked .1
as our server address (pretty standard), created a private key with the wg
tool, and put that in the file /etc/wireguard/wg0.conf
. Here’s the commands to do that.
# As root
cd /etc/wireguard/
umask 077
wg genkey > server_privatekey
wg pubkey < server_privatekey > server_publickey
read PRIV < server_privatekey
# We create the file wg0.conf here
cat << EOF > wg0.conf
[Interface]
Address = 192.168.100.1/24
ListenPort = 51820
PrivateKey = $PRIV
EOF
Operation
The VPN operates by creating network interface and loading a kernel module. You can use the linux ip
command to add a network interface of type wireguard (that automatically loads the kernel module) or use the wg-quick
command do do it for you.
Test the Interface
# The tool looks for the wg0.conf file you created earlier
wg-quick up wg0
ping 192.168.100.1
wg-quick down wg0
Enable The Service
For normal use, employ systemctl to create a service using the installed service file.
systemctl enable --now wg-quick@wg0
That’s it - add remote clients/peers and they will be able to connect.
Troubleshooting
When something is wrong, you don’t get an error message, you just get nothing. You bring up the client interface but you can’t ping the server. So turn on log messages on the server with this command.
echo module wireguard +p > /sys/kernel/debug/dynamic_debug/control
dmesg
# When done, send a '-p'
Key Errors
wg0: Invalid handshake initiation from 205.133.134.15:18595
In this case, you should check your keys and possibly take the server interface down and up.
Typeos
ifconfig: ioctl 0x8913 failed: No such device
Check your conf is named /etc/wireguard/wg0.conf
and look for any mistakes. Replace from scratch if nothing else.
Firewall Issues
If you see no wireguard error messages, suspect your firewall. Since it’s UDP you can’t test the port directly, but you can use netcat.
# On the server
systemctl stop wg-quick@wg0
nc -ulp 51820
# On the client.
nc -u some.server 51820
# Type some text and it should be echoed on the server
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.