Install WireGuard Free VPN Server on Ubuntu Server.Always Free Oracle Cloud Tier
Table of Contents
Introduction
In this tutorial, you will learn how to install and configure a WireGuard VPN server on an Ubuntu server using the Oracle Cloud Free Tier. WireGuard is a modern, high-performance VPN that is easy to set up and offers strong security features. By the end of this guide, you'll have a fully functional VPN server that can secure your internet connection.
Step 1: Install WireGuard
-
Update your system to ensure all packages are up to date:
sudo apt update && sudo apt upgrade -y
-
Install WireGuard using the following command:
sudo apt install wireguard -y
-
Verify installation by checking the WireGuard module:
sudo modprobe wireguard
Step 2: Configure the Server
-
Create server keys for WireGuard:
umask 077 wg genkey | tee server_private.key | wg pubkey > server_public.key
-
Create the configuration file for the WireGuard server:
sudo nano /etc/wireguard/wg0.conf
-
Add the following configuration to the file, replacing
YOUR_SERVER_IP
with your server's public IP address:[Interface] Address = 10.0.0.1/24 ListenPort = 51820 PrivateKey = <server_private_key> [Peer] PublicKey = <client_public_key> AllowedIPs = 10.0.0.2/32
-
Save and exit the file.
Step 3: Configure the Client
-
Generate client keys on the client machine:
umask 077 wg genkey | tee client_private.key | wg pubkey > client_public.key
-
Add the client to the server configuration by editing the
wg0.conf
file on the server again:sudo nano /etc/wireguard/wg0.conf
Add a new
[Peer]
section for the client:[Peer] PublicKey = <client_public_key> AllowedIPs = 10.0.0.2/32
-
Start the WireGuard server:
sudo wg-quick up wg0
-
Enable WireGuard to start on boot:
sudo systemctl enable wg-quick@wg0
Step 4: Set iptables Rules
-
Allow traffic through the VPN by setting up iptables rules:
sudo iptables -A INPUT -p udp --dport 51820 -j ACCEPT sudo iptables -A FORWARD -i wg0 -j ACCEPT sudo iptables -A FORWARD -o wg0 -j ACCEPT
-
Ensure that traffic is correctly routed:
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
Step 5: Configure Additional Client
-
Generate configuration settings for additional clients using the same method as before.
-
Repeat the steps for adding peers in the server configuration file for each new client.
Step 6: Generate QR Code for Mobile Clients
-
Install the QR code generator if not already installed:
sudo apt install qrencode
-
Generate the QR code by running:
qrencode -t ANSIUTF8 < /etc/wireguard/wg0.conf
Step 7: Make iptables Rules Permanent
-
Install iptables-persistent to save the rules:
sudo apt install iptables-persistent
-
Save the current rules:
sudo netfilter-persistent save
Conclusion
You have successfully installed and configured a WireGuard VPN server on Ubuntu. You can now connect clients securely to your server and enjoy enhanced privacy while browsing. Always remember to keep your server updated and monitor its security settings. For further customization, consider exploring advanced WireGuard features and configurations tailored to your specific needs.