Configuring and Starting WireGuard
Installing WireGuard on the Server
- Install the WireGuard tools
sudo dnf install wireguard-tools
- Generate a private key for the server
wg genkey | sudo tee /etc/wireguard/server.key
- Generate a public key for the server
sudo cat /etc/wireguard/server.key | wg pubkey | sudo tee /etc/wireguard/server.pub
- Create the WireGuard configuration file
/etc/wireguard/wg0.conf
with the following content:[Interface] PrivateKey = <Insert Server Private Key Here> Address = 10.20.10.1 ListenPort = 51820
- Generate a private key for the client
wg genkey | sudo tee /etc/wireguard/client.key
- Generate a public key for the client
sudo cat /etc/wireguard/client.key | wg pubkey | sudo tee /etc/wireguard/client.pub
- Add the client public key to the server configuration file
/etc/wireguard/wg0.conf
:[Peer] PublicKey = <Insert Client Public Key Here> AllowedIPs = 10.20.10.2
- Allow udp traffic on port 51820 in the firewall
sudo ufw allow 51820/udp
- Enable IP forwarding by editing
/etc/sysctl.conf
and adding the line:net.ipv4.ip_forward = 1
- Apply the changes:
sudo sysctl -p
- Start the WireGuard interface:
sudo wg-quick up wg0
- Enable the WireGuard service to start on boot:
sudo systemctl enable wg-quick@wg0