How to configure Wireguard client
On a client computer, create a new configuration file in the /etc/wireguard directory.
sudo nano /etc/wireguard/wg0.conf
Then add the following to that file. Remember to set the client private key and server public key to their corresponding places and also include your WireGuard server’s public IP address.
[Interface]
Address = 10.0.0.2/32
PrivateKey = <contents-of-client-privatekey>
DNS = 1.1.1.1
[Peer]
PublicKey = <contents-of-server-publickey>
Endpoint = <server-public-ip>:51820
AllowedIPs = 0.0.0.0/0, ::/0
Note that setting AllowedIPs to 0.0.0.0/0, ::/0 will forward all traffic over the WireGuard VPN connection. If you want to only use WireGuard for specific destinations, set their IP address ranges in the list separated by a comma.
Once you’ve set the keys and the server address, save the file and exit the editor.
Start the connection with the command below.
sudo wg-quick up wg0
You can also use the system command to start WireGuard as a service.
sudo systemctl start wg-quick@wg0
Then when you want to disconnect, use either of the following commands depending on which method you used to start it.
sudo wg-quick down wg0
sudo systemctl stop wg-quick@wg0
WireGuard will then disconnect from the server and remove the related network setting