This article is going to take you through on how to Install WireGuard VPN client on Ubuntu 22.04. WireGuard is a free and open-source communication technology and software for constructing encrypted virtual private networks (VPNs). It was designed with the goals of simplicity, speed, and a small attack surface in mind. UDP is used to carry data in the WireGuard protocol.
A virtual private network (VPN) allows you to connect to public networks as if they were private. When connecting to an untrusted network, such as the WiFi at a hotel or coffee shop, it allows you to access the internet safely and securely on your smartphone or laptop. To connect WireGuard VPN client, you need to have WireGuard VPN server installed. Check out our article on how to Install WireGuard VPN on Ubuntu 22.04.
How to Install WireGuard VPN client on Ubuntu 22.04
- To Install WireGuard VPN Client on Ubuntu 22.04, start by updating and upgrading your system using the following command.
sudo apt-get update && sudo apt-get upgrade
- Next install WireGuard VPN client on Ubuntu 22.04.
sudo apt install wireguard resolvconf -y
Reading package lists... Done Building dependency tree Reading state information... Done wireguard is already the newest version (1.0.20200513-1~20.04.2). The following NEW packages will be installed: resolvconf 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 54.7 kB of archives. After this operation, 200 kB of additional disk space will be used. Get:1 http://us.archive.ubuntu.com/ubuntu focal/universe amd64 resolvconf all 1.82 [54.7 kB] Fetched 54.7 kB in 1s (49.4 kB/s) Preconfiguring packages ... Selecting previously unselected package resolvconf. (Reading database ... 219751 files and directories cur rently installed.) Preparing to unpack .../resolvconf_1.82_all.deb ... Unpacking resolvconf (1.82) ... Setting up resolvconf (1.82) ... Created symlink /etc/systemd/system/sysinit.target.wan ts/resolvconf.service → /lib/systemd/system/resolvconf .service. Created symlink /etc/systemd/system/systemd-resolved.s ervice.wants/resolvconf-pull-resolved.path → /lib/syst emd/system/resolvconf-pull-resolved.path. resolvconf-pull-resolved.service is a disabled or a st atic unit, not starting it. Processing triggers for systemd (245.4-4ubuntu3.15) .. . Processing triggers for man-db (2.9.1-1) ... Processing triggers for resolvconf (1.82) ...
- After that, copy client keys to the appropriate clients. Note when you install WireGuard VPN server the keys will be generated.
[[ -d /etc/wireguard/ ]] || mkdir /etc/wireguard/
- Confirm you have both publickey and privatekey created using the command below.
sudo ls /etc/wireguard
- Use the following command to see the contents of the private key.
sudo cat /etc/wireguard/privatekey
- Use the following command to see the contents of the public key.
sudo cat /etc/wireguard/publickey
- Add Peer config in
/etc/wireguard/wg0.conffile. Run the following command to open the file.
sudo nano /etc/wireguard/wg0.conf
Then paste the following content.
[Peer] PublicKey = Your-Public-Key AllowedIPs = 10.8.0.0/24 Endpoint = Your-server-IP:51820 PersistentKeepalive = 20
- Your config file should look like the example file below.
[Interface] Address = 10.0.0.1/24 SaveConfig = true ListenPort = 51820 PrivateKey = UE5b3W+Ci/DTC5PH8qDbJhrjrbCrHCor30r5bx+0> PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptable> PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptab> [Peer] PublicKey = pfQem31SxkjF2NbzmELy5pgj7w7NVwLkEB82Z> AllowedIPs = 10.8.0.0/24 Endpoint = 192.168.171.128:51820 PersistentKeepalive = 20
- After editing your config file, run the following command to start WireGuard VPN client.
sudo systemctl start [email protected]
- WireGuard VPN client should be running, verify using the command below.
systemctl status [email protected]
● [email protected] - WireGuard via wg-quick(8) fo> Loaded: loaded (/lib/systemd/system/[email protected]> Active: active (exited) since Mon 2022-03-14 14:> Docs: man:wg-quick(8) man:wg(8) https://www.wireguard.com/ https://www.wireguard.com/quickstart/ https://git.zx2c4.com/wireguard-tools/ab> https://git.zx2c4.com/wireguard-tools/ab> Main PID: 941 (code=exited, status=0/SUCCESS) Tasks: 0 (limit: 4588) Memory: 0B CGroup: /system.slice/system-wg\x2dquick.slice/w> Mar 14 14:22:11 chat.itnixpro.com wg-quick: [#] > Mar 14 14:22:10 chat.itnixpro.com systemd: Startin> Mar 14 14:22:13 chat.itnixpro.com wg-quick: [#] > Mar 14 14:22:13 chat.itnixpro.com wg-quick: [#] > Mar 14 14:22:13 chat.itnixpro.com wg-quick: [#] > Mar 14 14:22:13 chat.itnixpro.com wg-quick: [#] > Mar 14 14:22:14 chat.itnixpro.com systemd: Finished>
- Check IP address assignment.
ip add show wg0
- Pinging the VPN server with the following command will confirm interconnection between the VPN server and the client.
ping 10.0.0.1 -c 5
PING 10.0.0.1 (10.0.0.1) 56(84) bytes of data. 64 bytes from 10.0.0.1: icmp_seq=1 ttl=64 time=0.120 ms 64 bytes from 10.0.0.1: icmp_seq=2 ttl=64 time=0.091 ms 64 bytes from 10.0.0.1: icmp_seq=3 ttl=64 time=0.178 ms 64 bytes from 10.0.0.1: icmp_seq=4 ttl=64 time=0.150 ms 64 bytes from 10.0.0.1: icmp_seq=5 ttl=64 time=0.133 ms --- 10.0.0.1 ping statistics --- 5 packets transmitted, 5 received, 0% packet loss, time 4102ms rtt min/avg/max/mdev = 0.091/0.134/0.178/0.029 ms
- You have reached the end of the article, Congratulations. You have learned how to Install WireGuard VPN client on Ubuntu 22.04.
Read more about WireGuard VPN
Synchronize Files between multiple devices using Syncthing
Monitor Linux host metrics using Prometheus node exporter
Monitor Windows system metrics using Prometheus node exporter