How to Configure WireGuard VPN on Debian 11 (2024)

Choose a different version or distribution

Introduction

Before we start talking on how to configure WireGuard VPN on Debian 11, let's briefly understand - What is WireGuard?

WireGuard is a free and open-source VPN that employs innovative cryptography. VPN represents Virtual Private Network. It is a modern and highly efficient VPN (Virtual Private Network) protocol known for its simplicity and security.

It provides a secure connection between two or more devices over the internet, offering privacy and data protection.

This tutorial will guide you through setting up a WireGuard VPN on Debian 11, enabling you to create your own private network.

Step1: Installing WireGuard on Debian 11

First, let's install the WireGuard VPN. Repositories for back ports can be used to install it. The command that follows will allow us to add it to our system:

echo 'deb http://ftp.debian.org/debian buster-backports main' | sudo tee /etc/apt/sources.list.d/buster-backports.list

Update our apt-cache now that the repository has been activated. To accomplish this, execute the following command:

sudo apt update

We must install the WireGuard module and tools after updating. To accomplish this, enter or copy the following command:

sudo apt install wireguard

It should be noted that WireGuard functions as a kernel module.

Step2: WireGuard Configuration

Let's configure WireGuard now that it has been installed on Debian 11. WireGuard may be managed and configured with the help of the wg and wg-quick commands.

As we stated in the beginning, every device in the WireGuard VPN network has a public and private key. The following command must be run in order to produce a key pair for this purpose:

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

Once you have executed the above command, you will be able to see the key as seen in the screenshot. The /etc/wireguard directory is where the key pair files were created. In Debian 11, we can use the cat or less commands to see file content.

Note that the private key is confidential and must never be disclosed to anybody.

The pre-shared key is another key that WireGuard supports. This key's purpose is to provide an additional layer of symmetric key cryptography. It should be noted that this key is absolutely optional. Additionally, each peer pair's unique key should be used.

Configuring the tunnel device is the next stage in the WireGuard configuration process. Our VPN traffic will be able to be routed through the tunnel device. Let's configure our device using the command line interface for this purpose.

We'll launch the editor and make an entirely new file called wg0.conf. We must use a text editor to create the configuration. To launch the editor and start a new file, enter the following command:

sudo nano /etc/wireguard/wg0.conf
How to Configure WireGuard VPN on Debian 11 (1)

Add the following to your open editor:

[Interface]Address = 10.0.0.1/24SaveConfig = trueListenPort = 51820PrivateKey = SERVER_PRIVATE_KEYPostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o enp0s3 -j MASQUERADEPostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -o enp0s3 -j MASQUERADE
How to Configure WireGuard VPN on Debian 11 (2)

Replace SERVER_PRIVATE_KEY with your server private key.

Press CTRL+S to save the file and CTRL+X to close it after that.

Before proceeding, it is critical that you replace the SERVER_PRIVATE_KEY in the above code with your private key. The following command will generate a private key for you:

umask 077 /etc/wireguardwg genkey | tee privatekey | wg pubkey > publickey

You can use the command below to view the private key:

sudo cat /etc/wireguard/privatekey

Remember that the public network interface needs to be substituted for enp0s3, which is found after the Postrouting, in the above commands. You can use the following command to locate your public interface:

ip -o -4 route show to default | awk '{print $5}'

Using the properties in the config file, we must activate the wg0 interface after you have finished editing the file in the editor. To accomplish this, execute the following command:

sudo wg-quick up wg0

The output will appear as follows:

With the following command, we can view the settings and the interface state:

sudo wg show wg0

WireGuard must be brought up at boot time as the final configuration step. This is due to the fact that WireGuard can be controlled by systemd. Enter the command as follows:

sudo systemctl enable wg-quick@wg0

Step3: Server Networking and Configuration of Firewall

Networking and firewall configuration are done in this step. You must first turn on IP forwarding for NAT to function. To accomplish this, execute the following command:

sudo nano /etc/sysctl.conf

The sysctl.conf file will be opened as a result. The following line has to be added to that file:

net.ipv4.ip_forward=1

After inserting the aforementioned line, save the document by clicking CTRL+S, and then press CTRL+X to exit the document.

In the terminal after that, enter the following command:

sudo sysctl -p

The last step is to manage our firewall. Port 51820 must be made available for UDP traffic. Only if one is utilizing the UFW, though. To accomplish this, execute the following command:

sudo ufw allow 51820/udp

Congratulations! The Debian peer has been set up effectively. Now it will function as a server.

Step 4: Setup of Windows Client

We now need to set up a client after configuring the server. We'll select windows for this purpose. Install the MSI package for the window in your browser by clicking the following link:

https://www.wireguard.com/install/
How to Configure WireGuard VPN on Debian 11 (3)

Click "Add Tunnel" in the bottom left corner after installing the downloaded file.

How to Configure WireGuard VPN on Debian 11 (4)

Then a drop-down menu will appear. Select "Add empty tunnel" from the menu. When finished, the following screen will appear:

How to Configure WireGuard VPN on Debian 11 (5)

Here, add the following lines to the file:

[Interface]
PrivateKey = CLIENT_PRIVATE_KEY
Address = 10.0.0.2/24

[Peer]
PublicKey = SERVER_PUBLIC_KEY
Endpoint = SERVER_IP_ADDRESS:51820
AllowedIPs = 0.0.0.0/0

How to Configure WireGuard VPN on Debian 11 (6)

It's important to keep in mind that you must enter both your private key and the server you built, which is a public key, in the respective fields. Additionally, you need to include the server IP address in place of the "Server_IP_ADDRESS" keyword. Set the name after that, then click "Save."

Step 5: Client Peer and Server Connection

The client and server are added in Step 5. The second-to-last step is when we connect the client's public key and IP address to the server. Run the following command on your Debian 11 server once more:

sudo wg set wg0 peer CLIENT_PUBLIC_KEY allowed-ips 10.0.0.2

Change the public key with your client's public key. The client public key is located in the Window WireGuard application.

Once you have completed the previous steps, open the Windows WireGuard App on your client machine.

Step 6: Windows Client

You only need to click the "Activate" in the WireGuard App tunnel button in the final step to complete it.

How to Configure WireGuard VPN on Debian 11 (7)

The status of the tunnel will automatically change to Active after you click the activate button. And with that, we're done. Congratulations!

How to Configure WireGuard VPN on Debian 11 (8)

FAQs on Configuring WireGuard VPN on Debian 11

What are the requirements for setting up WireGuard on Debian 11?

To set up WireGuard on Debian 11, you need a Debian 11 system with root access, a public IP address, and basic knowledge of networking concepts.

Is WireGuard compatible with Debian 11?

Yes, WireGuard is fully compatible with Debian 11, providing a straightforward setup process.

How can I install WireGuard on Debian 11?

To install WireGuard on Debian 11, you need to add the WireGuard PPA (Personal Package Archive) repository, update the package list, and then install the necessary packages using the apt package manager.

Do I need a static IP address for setting up WireGuard on Debian 11?

Having a static IP address for the WireGuard server is recommended for easier access and configuration.

Can I set up WireGuard on a VPS (Virtual Private Server) or cloud provider like AWS or DigitalOcean?

Yes, WireGuard can be set up on a VPS or cloud provider like AWS or DigitalOcean. The process is similar to setting up WireGuard on a local Debian 11 system.

Do I need to forward ports on my router for WireGuard to work?

Yes, to establish a connection from outside your network, you need to forward the WireGuard listening port (usually UDP) on your router to the WireGuard server.

Can I set up a site-to-site VPN using WireGuard?

Yes, WireGuard supports site-to-site VPN setups, allowing you to connect multiple networks together securely.

Conclusion

Setting up a WireGuard VPN on Debian 11 offers numerous advantages for secure and private networking. With its simplicity, efficiency, and strong security features, WireGuard stands as a modern and robust VPN protocol.

By following the installation and configuration steps mentioned in the tutorial, you can create your own private network and enjoy the benefits of a secure connection.

If you have any queries, please leave a comment below, and we’ll be happy to respond to them.

How to Configure WireGuard VPN on Debian 11 (2024)

FAQs

How to setup WireGuard VPN server Debian? ›

Configuring a VPN with WireGuard on Debian 12
  1. Step 1: Install WireGuard. First, you'll need to install WireGuard. ...
  2. Step 2: Generate Keys. Next, generate the private and public keys for the server: ...
  3. Step 3: Configure WireGuard Interface. ...
  4. Step 4: Configure Firewall. ...
  5. Step 5: Set up a Peer.
Jan 24, 2024

How to setup VPN on Debian 11? ›

How to Install OpenVPN Server on Debian 11/12
  1. Installation Using a Script. ...
  2. Step 1: Update and Upgrade Debian. ...
  3. Step 2: Install OpenVPN. ...
  4. Step 3: Generate Certificates and Keys. ...
  5. Step 4: Configure OpenVPN. ...
  6. Step 5: Enable IP Forwarding. ...
  7. Step 6: Start and Enable OpenVPN. ...
  8. Step 7: Configure Firewall.

How to setup WireGuard for VPN? ›

WireGuard Road Warrior Setup
  1. Step 1 - Configure the Wireguard Instance. Go to VPN ‣ WireGuard ‣ Instances. ...
  2. Step 2 - Configure the client peer. ...
  3. Step 3 - Turn on/restart WireGuard. ...
  4. Step 4 - Assignments and routing. ...
  5. Step 5 - Create firewall rules. ...
  6. Step 5a - Create normalization rules. ...
  7. Step 6 - Configure the WireGuard client.

Do I need a static IP address for WireGuard? ›

If you have a static IP address from your ISP then you don't need to do anything, we can just use the IP name you have been given or the IP itself. If you have a dynamic IP address then you will need to setup dynamic DNS. For my setup I used NoIP.com.

How to configure WireGuard VPN Linux? ›

Configuring the WireGuard VPN Server
  1. Create a new file named wg0. conf with your favorite text editor, and populate the wg0. ...
  2. Populate the wg0. conf file with the following contents. ...
  3. Run the command below to turn on the wg0 interface. sudo wg-quick up wg0. ...
  4. Lastly, run the below command to check your wg0 interface status.
Jan 14, 2022

What is the configuration file for the WireGuard server? ›

The config files are generally stored in the /etc/wireguard folder. Create a new configuration file called wg0. conf in that folder. The configuration below will make your WireGuard server accept connections to 51820 and allow a client with the public key corresponding to the private key we made above.

Which is more secure, WireGuard or OpenVPN? ›

There are no known security flaws in either protocol. If security is your topmost priority, the conservative option is OpenVPN. It has simply been around much longer than WireGuard, gone through more third-party security audits, and has a far longer track record than WireGuard.

How to setup VPN on Linux terminal? ›

To use a VPN on Linux, the following steps should be executed with proper concentration.
  1. Open Linux Terminal.
  2. Execute the command sudo add-apt-repository universe.
  3. Run the command sudo add-get install network-manager-openvpn.
  4. At last, the command sudo service network-manager restart will be executed.
Jul 11, 2024

How to configure OpenVPN client in Debian? ›

To start, update the package lists to ensure you get the latest version of the software:
  1. sudo apt update sudo apt install openvpn. ...
  2. sudo cp ~/myvpn.ovpn /etc/openvpn/ ...
  3. sudo chmod 600 /etc/openvpn/myvpn.ovpn. ...
  4. sudo systemctl start openvpn@myvpn. ...
  5. sudo systemctl enable openvpn@myvpn.
Feb 10, 2024

How do I manually set a WireGuard? ›

Connect to the VPN
  1. In the WireGuard application, click on Import tunnel(s) from file.
  2. Now select the Surfshark configuration file you downloaded earlier, and hit Open.
  3. You can rename this uploaded connection to your liking. ...
  4. Lastly, to connect to the VPN, click Activate, and to disconnect from the VPN, click Deactivate.
Jun 19, 2024

What VPN protocol does WireGuard use? ›

The default implementation of WireGuard uses UDP port 51820, something that most competent network administrators will close on public networks for security reasons.

What is the port number for WireGuard VPN? ›

The 51820 is the default Wireguard (listening) port. You should have a port forward of 51820 from your main router to the IP address allocated by your main router to your gl.

Does WireGuard need TCP or UDP? ›

Networking. WireGuard uses only UDP, due to the potential disadvantages of TCP-over-TCP. Tunneling TCP over a TCP-based connection is known as "TCP-over-TCP", and doing so can induce a dramatic loss in transmission performance (a problem known as "TCP meltdown").

Does WireGuard hide my IP address? ›

When you connect to our VPN server via WireGuard, your device can only see the IP address 10.2. 0.2, and the website you visit can only see the public IP address of our VPN server. Your true IP address remains secure and private, just as it would with OpenVPN.

How do I add an IP address to WireGuard? ›

Command-line Interface
  1. # ip link add dev wg0 type wireguard. ...
  2. # ip address add dev wg0 192.168.2.1/24. ...
  3. # ip address add dev wg0 192.168.2.1 peer 192.168.2.2. ...
  4. # wg setconf wg0 myconfig.conf. ...
  5. # wg set wg0 listen-port 51820 private-key /path/to/private-key peer ABCDEF... ...
  6. # ip link set up dev wg0.

How to create VPN server in Linux? ›

Set Up a Linux VPN Server With Hostinger OpenVPN VPS Template
  1. Log in to hPanel and click VPS on the top menu.
  2. Select the VPS you want to install OpenVPN on.
  3. Navigate to the sidebar → OS & Templates → Operating System.
  4. Click Applications.
  5. Select Ubuntu 22.04 64bit with OpenVPN from the drop-down menu and click Change OS.
Jun 26, 2024

How to setup your own VPN server using WireGuard on Ubuntu? ›

  1. Step 1: Update Ubuntu Server packages.
  2. Step 2: Install Wireguard on ubuntu.
  3. Step 3: Generate WireGuard Server Key Pairs.
  4. Step 4: Configure IPv4 and IPv6 addresses.
  5. Step 5: Port Forwarding configuration and /etc/sysctl.conf file.
  6. Step 6: WireGuard server firewall configuration.
  7. Step 7: Start the WireGuard server in Ubuntu.
Jan 3, 2023

How do I connect to my WireGuard server? ›

Open up your web browser and paste in your server's IP address and port and hit 'Enter'. This will now take you to the login page. Simply input your username and password into the corresponding fields and click on the 'Sign In' button.

How to setup L2TP VPN on Debian? ›

L2TP/IPsec VPN with NetworkManager on Debian Stretch
  1. Install dependencies. # apt install strongswan xl2tpd.
  2. Install it. ...
  3. Open NetworkManager settings.
  4. Add “Layer 2 Tunneling Protocol” (the “IPsec” options are not the right ones for an ordinary L2TP/IPsec network)
  5. Enter details. ...
  6. Select VPN and hit Connect.
Jan 16, 2018

Top Articles
Netflix L7 Software Engineer Salary | $990K-$1.2M+ | Levels.fyi
God Of War: 10 Superpowers Only Super Fans Know Kratos Has (And 10 Weaknesses)
Odawa Hypixel
Craglist Oc
Khatrimaza Movies
What's New on Hulu in October 2023
Whiskeytown Camera
Braums Pay Per Hour
Dark Souls 2 Soft Cap
Jessica Renee Johnson Update 2023
Chastity Brainwash
Pwc Transparency Report
Discover Westchester's Top Towns — And What Makes Them So Unique
House Of Budz Michigan
Midlife Crisis F95Zone
Dutch Bros San Angelo Tx
Gino Jennings Live Stream Today
Dallas Cowboys On Sirius Xm Radio
Echat Fr Review Pc Retailer In Qatar Prestige Pc Providers – Alpha Marine Group
Outlet For The Thames Crossword
Yog-Sothoth
Bethel Eportal
Access a Shared Resource | Computing for Arts + Sciences
R/Airforcerecruits
Gma' Deals & Steals Today
Lawrence Ks Police Scanner
Used 2 Seater Go Karts
The Latest: Trump addresses apparent assassination attempt on X
The Pretty Kitty Tanglewood
Greencastle Railcam
Vitals, jeden Tag besser | Vitals Nahrungsergänzungsmittel
Car Crash On 5 Freeway Today
Black Adam Showtimes Near Amc Deptford 8
The 50 Best Albums of 2023
Ukg Dimensions Urmc
Finland’s Satanic Warmaster’s Werwolf Discusses His Projects
Heelyqutii
The Best Restaurants in Dublin - The MICHELIN Guide
Daly City Building Division
Newsweek Wordle
Luciane Buchanan Bio, Wiki, Age, Husband, Net Worth, Actress
Craigslist Rooms For Rent In San Fernando Valley
Borat: An Iconic Character Who Became More than Just a Film
Star Sessions Snapcamz
The 13 best home gym equipment and machines of 2023
Rovert Wrestling
Puss In Boots: The Last Wish Showtimes Near Valdosta Cinemas
Craigslist Psl
How To Win The Race In Sneaky Sasquatch
Fishing Hook Memorial Tattoo
Latest Posts
Article information

Author: Jamar Nader

Last Updated:

Views: 6499

Rating: 4.4 / 5 (55 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Jamar Nader

Birthday: 1995-02-28

Address: Apt. 536 6162 Reichel Greens, Port Zackaryside, CT 22682-9804

Phone: +9958384818317

Job: IT Representative

Hobby: Scrapbooking, Hiking, Hunting, Kite flying, Blacksmithing, Video gaming, Foraging

Introduction: My name is Jamar Nader, I am a fine, shiny, colorful, bright, nice, perfect, curious person who loves writing and wants to share my knowledge and understanding with you.