Linking WireGuard Tunnel (wg0 interface) IPs: 172.16.0.0/172.16.1.0 (Server, VM)
In this article, we will discuss how to link a WireGuard tunnel on a physical server with IP addresses 172.16.0.0/172.16.1.0. We will cover the key concepts, provide detailed context, and include subtitles, use H2, H3, etc., paragraphs, and code blocks.
Prerequisites
Before we begin, ensure you have the following prerequisites:
- A physical server with a WireGuard-compatible operating system (e.g., Linux)
- WireGuard installed on the server
- Access to the server via SSH
- IP addresses 172.16.0.0/172.16.1.0 for the server and the VM
Setting Up WireGuard on the Server
First, let's set up WireGuard on the server. To do this, follow these steps:
- Install WireGuard on the server:
sudo apt-get update
sudo apt-get install wireguard
- Create a new WireGuard configuration file:
sudo nano /etc/wireguard/wg0.conf
- Add the following content to the configuration file, replacing the placeholders with your actual IP addresses and other details:
[Interface]
Address = 172.16.0.1/24
PrivateKey = <Your Private Key>
ListenPort = 51820
[Peer]
PublicKey = <VM's Public Key>
Endpoint = <VM's IP Address>:51820
AllowedIPs = 172.16.1.0/24
-
Save and close the file.
-
Enable and start the WireGuard service:
sudo systemctl enable wg-quick@wg0
sudo systemctl start wg-quick@wg0
- Verify the WireGuard interface is up and running:
sudo ip link show wg0
Setting Up WireGuard on the VM
Now, let's set up WireGuard on the VM:
- Install WireGuard on the VM (if it's not already installed):
sudo apt-get update
sudo apt-get install wireguard
- Create a new WireGuard configuration file:
sudo nano /etc/wireguard/wg0.conf
- Add the following content to the configuration file, replacing the placeholders with your actual IP addresses and other details:
[Interface]
Address = 172.16.1.1/24
PrivateKey = <Your Private Key>
ListenPort = 51820
[Peer]
PublicKey = <Server's Public Key>
Endpoint = <Server's IP Address>:51820
AllowedIPs = 0.0.0.0/0
-
Save and close the file.
-
Enable and start the WireGuard service:
sudo systemctl enable wg-quick@wg0
sudo systemctl start wg-quick@wg0
- Verify the WireGuard interface is up and running:
sudo ip link show wg0
Troubleshooting
If you encounter any issues, ensure the following:
- The IP addresses and subnet masks are correctly specified.
- The server and VM public keys match.
- The server and VM listening ports are the same.
- The firewall on both the server and VM allows WireGuard traffic.
Summary
In this article, we discussed how to link a WireGuard tunnel on a physical server with IP addresses 172.16.0.0/172.16.1.0 to a VM. We covered the key concepts, provided detailed context, and included subtitles, use H2, H3, etc., paragraphs, and code blocks.
References
- WireGuard official website: https://www.wireguard.com/
- WireGuard documentation: https://www.wireguard.com/documents/
- Ubuntu WireGuard package: https://packages.ubuntu.com/bionic/wireguard
- WireGuard tutorial on DigitalOcean: https://www.digitalocean.com/community/tutorials/how-to-set-up-wireguard-vpn-on-ubuntu-20-04-1
- WireGuard troubleshooting guide: https://www.wireguard.com/docs/troubleshoot/