How to set up WireGuard on Debian 12 – D4D Blog (2024)

Introduction

WireGuard is a straightforward yet fast and modern VPN that utilizes state-of-the-art cryptography. It aims to be faster, simpler, leaner, and more practical than IPsec while avoiding the massive headache. It intends to be considerably more performant than OpenVPN. WireGuard is designed as a general-purpose VPN for running on embedded interfaces and supercomputers alike, and it is fit for many different circ*mstances.

Step 1. Installing WireGuard and generating a key pair

The first step is to install WireGuard on your server. Before starting, update your WireGuard server’s package index and install WireGuard using the following command.

apt-get update && apt-get install wireguard

Now that you have WireGuard installed, the next step is to generate private and public key pairs for the server using the following command.

Create the private key for WireGuard and change its permissions using the following command:

wg genkey | tee /etc/wireguard/private.key && chmod go= /etc/wireguard/private.key

The next step is to create the corresponding public key derived from the private key. Use the following command to create the public key file:

cat /etc/wireguard/private.key | wg pubkey | tee /etc/wireguard/public.key

Step 2. Choosing IPv4 addresses

If you are using your WireGuard server with IPv4 peers, the server needs a range of private IPv4 addresses for clients and its tunnel interface. You can choose any range of IP addresses from the following reserved blocks of addresses (if you would like to learn more about how these blocks are allocated, visit the RFC 1918 specification):

10.0.0.0 - 10.255.255.255 (10/8 prefix)172.16.0.0 - 172.31.255.255 (172.16/12 prefix)192.168.0.0 - 192.168.255.255 (192.168/16 prefix)

Step 3. Creating a WireGuard server configuration

Once you have the required private key and IP address, create a new configuration file using nano or your preferred editor by running the following command:

nano /etc/wireguard/wg0.conf

Add the following lines to the file. Don’t forget to add the private key generated in your WireGuard server and the IP address on the Address line. You can also change the ListenPort line if you would like WireGuard to be available on a different port:

[Interface]Address = 10.8.0.1/24SaveConfig = trueListenPort = 51820PrivateKey = private_key

Step 4. Starting the WireGuard server

WireGuard can be configured to run as a systemd service using its built-in wg-quick script. While you could manually use the wg command to create the tunnel every time you want to use the VPN, doing so is a manual process that becomes repetitive and error-prone. Instead, you can use systemctl to manage the tunnel with the help of the wg-quick script.

Using a systemd service means you can configure WireGuard to start up at boot so that you can connect to your VPN anytime as long as the server is running. To do this, enable the wg-quick service for the wg0 tunnel that you’ve defined by adding it to systemctl:

systemctl enable [emailprotected]

Now start the service:

systemctl start [emailprotected]

Double-check that the WireGuard service is active using the following command. You should see active (running) in the output:

systemctl status [emailprotected]

Command output:

[emailprotected] - WireGuard via wg-quick(8) for wg0 Loaded: loaded (/lib/systemd/system/[emailprotected]; enabled; preset: enabled) Active: active (exited) since Tue 2024-03-19 17:27:52 CET; 2min 39s ago Docs: man:wg-quick(8) man:wg(8) https://www.wireguard.com/ https://www.wireguard.com/quickstart/ https://git.zx2c4.com/wireguard-tools/about/src/man/wg-quick.8 https://git.zx2c4.com/wireguard-tools/about/src/man/wg.8 Process: 1190 ExecStart=/usr/bin/wg-quick up wg0 (code=exited, status=0/SUCCESS) Main PID: 1190 (code=exited, status=0/SUCCESS) CPU: 65ms

Step 5. Configuring a WireGuard peer

Configuring a WireGuard peer is similar to setting up the WireGuard Server. Before starting, firstly install client software.

How to set up WireGuard on Debian 12 – D4D Blog (1)

You can now set up your first connection by clicking the “+” button and selecting “Add Empty Tunnel.”

How to set up WireGuard on Debian 12 – D4D Blog (2)

In the opened window, we must fill in additional information like our name and save the public key for our WireGuard server. In the text area, we need some information that allows us to connect to our WireGuard server.

[Interface]PrivateKey = peer_private_keyAddress = 10.8.0.2/24[Peer]PublicKey = wire_guard_server_public_keyAllowedIPs = 10.8.0.0/24Endpoint = wire_guard_server_ip_address:51820

Interface section:

PrivateKey – the base 64 encoded private key generated on the peer.

Address – your IP address for your peer.

Peer section:

PublicKey – the base 64 encoded public key from the WireGuard server.

AllowedIPs – the IP address range that you defined on the WireGuard server.

Endpoint – the WireGuard server IP address and port.

After that, click the button save and save this configuration on your MacBook.

Step 6. Adding the peer’s public key to the WireGuard server

Before connecting the peer to the server, adding the peer’s public key to the WireGuard server is essential. This step ensures you can connect to and route traffic over the VPN. Without completing this step, the WireGuard server will not allow the peer to send or receive any traffic over the tunnel.

Now log into the WireGuard server and run the following command:

wg set wg0 peer peer_public_key allowed-ips 10.8.0.2

Once you have run the command to add the peer, check the status of the tunnel on the server using the wg command:

wg

Output of the command

interface: wg0 public key: 5eXbx9Z8YUjJmmj43xNpQROs+xVPmcxCOC7gMyrnTGk= private key: (hidden) listening port: 51820peer: FI0l1ZGaJw/RRksHE6ImMoOHNcs4DKfGZHb/P1266WE= allowed ips: 10.8.0.2/32

Notice how the peer The line shows the WireGuard Peer’s public key and the IP addresses or ranges of addresses it can use to assign itself an IP. Now that you have defined the peer’s connection parameters on the server, the next step is to start the tunnel on the peer.

Step 7. Connecting the WireGuard peer to the tunnel

Now you can connect the WireGuard peer to the tunnel by clicking “Activate.”

How to set up WireGuard on Debian 12 – D4D Blog (3)

Now you can ping your IP address, for example:

ping 10.8.0.1PING 10.8.0.1 (10.8.0.1): 56 data bytes64 bytes from 10.8.0.1: icmp_seq=0 ttl=64 time=68.325 ms64 bytes from 10.8.0.1: icmp_seq=1 ttl=64 time=90.643 ms64 bytes from 10.8.0.1: icmp_seq=2 ttl=64 time=99.050 ms^C--- 10.8.0.1 ping statistics ---3 packets transmitted, 3 packets received, 0.0% packet lossround-trip min/avg/max/stddev = 68.325/86.006/99.050/12.965 ms

Conclusion

Today we installed the WireGuard server and tried to connect our MacBook to the WireGuard VPN network.

Sources:

  1. Digital Ocean
How to set up WireGuard on Debian 12 – D4D Blog (2024)

FAQs

How to set up WireGuard on Debian 12 – D4D Blog? ›

Kernel Requirements

WireGuard requires Linux ≥3.10, with the following configuration options, which are likely already configured in your kernel, especially if you're installing via distribution packages.

What Linux kernel is required for WireGuard? ›

Kernel Requirements

WireGuard requires Linux ≥3.10, with the following configuration options, which are likely already configured in your kernel, especially if you're installing via distribution packages.

What is the default port for WireGuard easy? ›

However WireGuard always listens on port 51820 inside the container. You can 'translate' the port at the router (see below), but I recommend using port 51820 throughout to avoid confusion. Make the following changes under "Networking" setting in the app setup: Set "WireGuard UDP Node Port for WG-Easy" to 51820.

What ports are required for WireGuard? ›

What ports do you use for WireGuard? UDP ports 53, 80, 443, 1194, 2049, 2050, 30587, 41893, 48574, 58237.

What is the default password for WireGuard? ›

Run WireGuard-UI

⚠️ The default username and password are admin .

Does WireGuard require a server? ›

A WireGuard VPN usually involves a client (the app on your phone, for example) and a VPN server. Like other encryption protocols, WireGuard communicates with the server and establishes an encrypted tunnel between server and client.

What are the hardware requirements for WireGuard? ›

The OS recommends as a min a 1ghz cpu, 1gb of ram and 1.5gb of storage (Source).

Which is more secure, WireGuard or OpenVPN? ›

While WireGuard is generally faster, OpenVPN provides heavier security.

Top Articles
Move Sent Emails to a Specific Folder Automatically
How much does it cost to install granite countertops?
Craigslist San Francisco Bay
How To Start a Consignment Shop in 12 Steps (2024) - Shopify
Truist Bank Near Here
Somboun Asian Market
Promotional Code For Spades Royale
O'reilly's Auto Parts Closest To My Location
No Limit Telegram Channel
Pieology Nutrition Calculator Mobile
Cad Calls Meriden Ct
Craigslist Motorcycles Jacksonville Florida
Calamity Hallowed Ore
Morgan Wallen Pnc Park Seating Chart
Nexus Crossword Puzzle Solver
Hillside Funeral Home Washington Nc Obituaries
Hartford Healthcare Employee Tools
Colts seventh rotation of thin secondary raises concerns on roster evaluation
Theresa Alone Gofundme
50 Shades Darker Movie 123Movies
Osborn-Checkliste: Ideen finden mit System
623-250-6295
If you bought Canned or Pouched Tuna between June 1, 2011 and July 1, 2015, you may qualify to get cash from class action settlements totaling $152.2 million
Exl8000 Generator Battery
Sandals Travel Agent Login
Kirk Franklin Mother Debra Jones Age
Lovindabooty
Wolfwalkers 123Movies
Pokemon Inflamed Red Cheats
Rgb Bird Flop
Lilpeachbutt69 Stephanie Chavez
How Do Netspend Cards Work?
Street Fighter 6 Nexus
Los Amigos Taquería Kalona Menu
O'reilly Auto Parts Ozark Distribution Center Stockton Photos
Jay Gould co*ck
Craigs List Jonesboro Ar
Craigslist Boats Eugene Oregon
Hell's Kitchen Valley Center Photos Menu
Body Surface Area (BSA) Calculator
Ticket To Paradise Showtimes Near Marshall 6 Theatre
WorldAccount | Data Protection
Dispensaries Open On Christmas 2022
Callie Gullickson Eye Patches
Autum Catholic Store
Thothd Download
Dobratz Hantge Funeral Chapel Obituaries
Theatervoorstellingen in Nieuwegein, het complete aanbod.
Rheumatoid Arthritis Statpearls
Twizzlers Strawberry - 6 x 70 gram | bol
Unbiased Thrive Cat Food Review In 2024 - Cats.com
Latest Posts
Article information

Author: Melvina Ondricka

Last Updated:

Views: 6325

Rating: 4.8 / 5 (48 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Melvina Ondricka

Birthday: 2000-12-23

Address: Suite 382 139 Shaniqua Locks, Paulaborough, UT 90498

Phone: +636383657021

Job: Dynamic Government Specialist

Hobby: Kite flying, Watching movies, Knitting, Model building, Reading, Wood carving, Paintball

Introduction: My name is Melvina Ondricka, I am a helpful, fancy, friendly, innocent, outstanding, courageous, thoughtful person who loves writing and wants to share my knowledge and understanding with you.