How to Connect to Wireguard VPN on Ubuntu?

Discover the simplest way to secure your internet with WireGuard VPN on Ubuntu. Follow our easy guide now!

Updated: 12 May, 24 by Lisa P 4 Min

List of content you will read in this article:

In today's interconnected world, ensuring the security and privacy of your online activities is paramount. Virtual Private Networks (VPNs) play a crucial role in safeguarding your data and identity from prying eyes on the internet. WireGuard, a relatively new VPN protocol, has gained popularity for its simplicity, speed, and modern cryptography. In this guide, we'll walk you through the process of installing and setting up WireGuard on Ubuntu, one of the most widely used Linux distributions.

Setting up WireGuard on Ubuntu is a streamlined process that involves installation, configuration, and connection. This modern VPN protocol offers robust security, high performance, and ease of use. With its minimalist design and efficient codebase, WireGuard simplifies the setup and management of VPN connections on Ubuntu systems. By following a few simple steps, users can establish secure and reliable VPN tunnels to protect their online activities. Additionally, WireGuard's cross-platform compatibility ensures seamless integration across various devices and operating systems. With WireGuard, Ubuntu users can enjoy enhanced privacy and security without sacrificing performance or usability.

  • Open a terminal window by pressing Ctrl + Alt + T.
  • Update your package list to ensure you have the latest version of available packages:

sudo apt update

  • Install the WireGuard package by running the following command:

sudo apt install wireguard

  • Once the installation is complete, verify that WireGuard is installed by checking its version:

wg --version

Congratulations! You've successfully installed WireGuard on your Ubuntu system.

Now that WireGuard is installed, let's proceed with setting it up.

  • Generate a pair of public and private keys for the server:

wg genkey | sudo tee /etc/wireguard/privatekey | wg pubkey | sudo tee /etc/wireguard/publickey

  • Create a configuration file for the WireGuard interface. You can use any text editor of your choice. For example, to create a new configuration file named wg0.conf:

sudo nano /etc/wireguard/wg0.conf

  • Add the following configuration to the file, replacing <Private_Key> with the private key generated earlier:

[Interface]
PrivateKey = <Private_Key>
Address = 10.0.0.1/24
ListenPort = 51820

[Peer]
PublicKey = <Public_Key_of_Client>
AllowedIPs = 10.0.0.2/32

Replace <Public_Key_of_Client> with the public key of the client you'll be connecting to WireGuard.

  • Save and close the file.
  • Enable IP forwarding by uncommenting the following line in /etc/sysctl.conf:

#net.ipv4.ip_forward=1

  • Apply the changes:

sudo sysctl -p

  • Start the WireGuard service:

sudo systemctl start wg-quick@wg0
sudo systemctl enable wg-quick@wg0

With WireGuard set up on your Ubuntu server, you can now connect to it from your client machine.

  • Install WireGuard on your client machine following the same steps as above.
  • Generate a pair of public and private keys for the client:

wg genkey | sudo tee /etc/wireguard/privatekey | wg pubkey | sudo tee /etc/wireguard/publickey

  • Create a configuration file for the client:

sudo nano /etc/wireguard/wg0.conf

  • Add the following configuration to the file, replacing <Private_Key> with the private key generated earlier and <Public_Key_of_Server> with the public key of your Ubuntu server:

[Interface]
PrivateKey = <Private_Key>
Address = 10.0.0.2/24

[Peer]
PublicKey = <Public_Key_of_Server>
Endpoint = <Server_IP>:51820
AllowedIPs = 0.0.0.0/0

Replace <Server_IP> with the public IP address of your Ubuntu server.

  • Save and close the file.
  • Start the WireGuard service on the client:

sudo systemctl start wg-quick@wg0
sudo systemctl enable wg-quick@wg0

You are now connected to the WireGuard VPN on your Ubuntu client.

In this guide, we've covered the installation, setup, and connection to WireGuard VPN on Ubuntu. By following these steps, you can ensure a secure and private connection to the internet, protecting your data from potential threats. Whether you're accessing sensitive information or simply browsing the web, WireGuard provides a reliable solution for safeguarding your online activities.

Lisa P

Lisa P

Hello, everyone, my name is Lisa. I'm a passionate electrical engineering student with a keen interest in technology. I'm fascinated by the intersection of engineering principles and technological advancements, and I'm eager to contribute to the field by applying my knowledge and skills to solve real-world problems.