$ -weight: 600;">sudo -weight: 500;">apt -weight: 500;">update && -weight: 600;">sudo -weight: 500;">apt -weight: 500;">upgrade -y
-weight: 600;">sudo -weight: 500;">apt -weight: 500;">install wireguard -y
-weight: 600;">sudo -weight: 500;">apt -weight: 500;">update && -weight: 600;">sudo -weight: 500;">apt -weight: 500;">upgrade -y
-weight: 600;">sudo -weight: 500;">apt -weight: 500;">install wireguard -y
-weight: 600;">sudo -weight: 500;">apt -weight: 500;">update && -weight: 600;">sudo -weight: 500;">apt -weight: 500;">upgrade -y
-weight: 600;">sudo -weight: 500;">apt -weight: 500;">install wireguard -y
wg --version
wg --version
wg --version
wireguard-tools v1.0.20210914 - https://-weight: 500;">git.zx2c4.com/wireguard-tools/
wireguard-tools v1.0.20210914 - https://-weight: 500;">git.zx2c4.com/wireguard-tools/
wireguard-tools v1.0.20210914 - https://-weight: 500;">git.zx2c4.com/wireguard-tools/
-weight: 600;">sudo modprobe wireguard
wg --version
-weight: 600;">sudo modprobe wireguard
wg --version
-weight: 600;">sudo modprobe wireguard
wg --version
wg genkey | -weight: 600;">sudo tee /etc/wireguard/server_private.key | wg pubkey | -weight: 600;">sudo tee /etc/wireguard/server_public.key
wg genkey | -weight: 600;">sudo tee /etc/wireguard/server_private.key | wg pubkey | -weight: 600;">sudo tee /etc/wireguard/server_public.key
wg genkey | -weight: 600;">sudo tee /etc/wireguard/server_private.key | wg pubkey | -weight: 600;">sudo tee /etc/wireguard/server_public.key
-weight: 600;">sudo chmod 600 /etc/wireguard/server_private.key
-weight: 600;">sudo chmod 600 /etc/wireguard/server_private.key
-weight: 600;">sudo chmod 600 /etc/wireguard/server_private.key
wg genkey | -weight: 600;">sudo tee /etc/wireguard/client_private.key | wg pubkey | -weight: 600;">sudo tee /etc/wireguard/client_public.key
-weight: 600;">sudo chmod 600 /etc/wireguard/client_private.key
wg genkey | -weight: 600;">sudo tee /etc/wireguard/client_private.key | wg pubkey | -weight: 600;">sudo tee /etc/wireguard/client_public.key
-weight: 600;">sudo chmod 600 /etc/wireguard/client_private.key
wg genkey | -weight: 600;">sudo tee /etc/wireguard/client_private.key | wg pubkey | -weight: 600;">sudo tee /etc/wireguard/client_public.key
-weight: 600;">sudo chmod 600 /etc/wireguard/client_private.key
-weight: 600;">sudo cat /etc/wireguard/server_private.key
-weight: 600;">sudo cat /etc/wireguard/server_public.key
-weight: 600;">sudo cat /etc/wireguard/client_private.key
-weight: 600;">sudo cat /etc/wireguard/client_public.key
-weight: 600;">sudo cat /etc/wireguard/server_private.key
-weight: 600;">sudo cat /etc/wireguard/server_public.key
-weight: 600;">sudo cat /etc/wireguard/client_private.key
-weight: 600;">sudo cat /etc/wireguard/client_public.key
-weight: 600;">sudo cat /etc/wireguard/server_private.key
-weight: 600;">sudo cat /etc/wireguard/server_public.key
-weight: 600;">sudo cat /etc/wireguard/client_private.key
-weight: 600;">sudo cat /etc/wireguard/client_public.key
/etc/wireguard/wg0.conf
/etc/wireguard/wg0.conf
/etc/wireguard/wg0.conf
ip route | grep default
ip route | grep default
ip route | grep default
default via 203.0.113.1 dev eth0 proto dhcp
default via 203.0.113.1 dev eth0 proto dhcp
default via 203.0.113.1 dev eth0 proto dhcp
-weight: 600;">sudo nano /etc/wireguard/wg0.conf
-weight: 600;">sudo nano /etc/wireguard/wg0.conf
-weight: 600;">sudo nano /etc/wireguard/wg0.conf
[Interface]
# Server private key
PrivateKey = <paste-server-private-key-here> # VPN IP address assigned to the server
Address = 10.0.0.1/24 # WireGuard listens on this UDP port
ListenPort = 51820 # Enable IP masquerading so VPN clients can reach the internet
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -A FORWARD -o wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -D FORWARD -o wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE [Peer]
# Client public key
PublicKey = <paste-client-public-key-here> # IP address assigned to this client inside the VPN
AllowedIPs = 10.0.0.2/32
[Interface]
# Server private key
PrivateKey = <paste-server-private-key-here> # VPN IP address assigned to the server
Address = 10.0.0.1/24 # WireGuard listens on this UDP port
ListenPort = 51820 # Enable IP masquerading so VPN clients can reach the internet
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -A FORWARD -o wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -D FORWARD -o wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE [Peer]
# Client public key
PublicKey = <paste-client-public-key-here> # IP address assigned to this client inside the VPN
AllowedIPs = 10.0.0.2/32
[Interface]
# Server private key
PrivateKey = <paste-server-private-key-here> # VPN IP address assigned to the server
Address = 10.0.0.1/24 # WireGuard listens on this UDP port
ListenPort = 51820 # Enable IP masquerading so VPN clients can reach the internet
PostUp = iptables -A FORWARD -i wg0 -j ACCEPT; iptables -A FORWARD -o wg0 -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i wg0 -j ACCEPT; iptables -D FORWARD -o wg0 -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE [Peer]
# Client public key
PublicKey = <paste-client-public-key-here> # IP address assigned to this client inside the VPN
AllowedIPs = 10.0.0.2/32
10.0.0.3/32
10.0.0.4/32
10.0.0.5/32
10.0.0.3/32
10.0.0.4/32
10.0.0.5/32
10.0.0.3/32
10.0.0.4/32
10.0.0.5/32
-weight: 600;">sudo nano /etc/sysctl.conf
-weight: 600;">sudo nano /etc/sysctl.conf
-weight: 600;">sudo nano /etc/sysctl.conf
#net.ipv4.ip_forward=1
#net.ipv4.ip_forward=1
#net.ipv4.ip_forward=1
net.ipv4.ip_forward=1
net.ipv4.ip_forward=1
net.ipv4.ip_forward=1
-weight: 600;">sudo sysctl -p
-weight: 600;">sudo sysctl -p
-weight: 600;">sudo sysctl -p
net.ipv4.ip_forward = 1
net.ipv4.ip_forward = 1
net.ipv4.ip_forward = 1
-weight: 600;">sudo ufw allow 51820/udp
-weight: 600;">sudo ufw -weight: 500;">status
-weight: 600;">sudo ufw allow 51820/udp
-weight: 600;">sudo ufw -weight: 500;">status
-weight: 600;">sudo ufw allow 51820/udp
-weight: 600;">sudo ufw -weight: 500;">status
51820/udp ALLOW Anywhere
51820/udp (v6) ALLOW Anywhere (v6)
51820/udp ALLOW Anywhere
51820/udp (v6) ALLOW Anywhere (v6)
51820/udp ALLOW Anywhere
51820/udp (v6) ALLOW Anywhere (v6)
-weight: 600;">sudo ufw allow from 203.0.113.25 to any port 51820 proto udp
-weight: 600;">sudo ufw allow from 203.0.113.25 to any port 51820 proto udp
-weight: 600;">sudo ufw allow from 203.0.113.25 to any port 51820 proto udp
-weight: 600;">sudo wg-quick up wg0
-weight: 600;">sudo wg-quick up wg0
-weight: 600;">sudo wg-quick up wg0
[#] ip link add wg0 type wireguard
[#] wg setconf wg0 /dev/fd/63
[#] ip -4 address add 10.0.0.1/24 dev wg0
[#] ip link set mtu 1420 up dev wg0
[#] iptables -A FORWARD -i wg0 -j ACCEPT; ...
[#] ip link add wg0 type wireguard
[#] wg setconf wg0 /dev/fd/63
[#] ip -4 address add 10.0.0.1/24 dev wg0
[#] ip link set mtu 1420 up dev wg0
[#] iptables -A FORWARD -i wg0 -j ACCEPT; ...
[#] ip link add wg0 type wireguard
[#] wg setconf wg0 /dev/fd/63
[#] ip -4 address add 10.0.0.1/24 dev wg0
[#] ip link set mtu 1420 up dev wg0
[#] iptables -A FORWARD -i wg0 -j ACCEPT; ...
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">enable wg-quick@wg0
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">enable wg-quick@wg0
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">enable wg-quick@wg0
-weight: 600;">sudo wg show
-weight: 600;">sudo wg show
-weight: 600;">sudo wg show
interface: wg0 public key: <your-server-public-key> private key: (hidden) listening port: 51820
interface: wg0 public key: <your-server-public-key> private key: (hidden) listening port: 51820
interface: wg0 public key: <your-server-public-key> private key: (hidden) listening port: 51820
/etc/wireguard/wg0.conf
/etc/wireguard/wg0.conf
/etc/wireguard/wg0.conf
[Interface]
# Client private key
PrivateKey = <paste-client-private-key-here> # IP address assigned to this client inside the VPN
Address = 10.0.0.2/24 # Optional DNS resolver
DNS = 1.1.1.1 [Peer]
# Server public key
PublicKey = <paste-server-public-key-here> # Server public IP address and WireGuard port
Endpoint = <your-server-public-ip>:51820 # Route all traffic through the VPN
AllowedIPs = 0.0.0.0/0 # Keep the tunnel alive through NAT
PersistentKeepalive = 25
[Interface]
# Client private key
PrivateKey = <paste-client-private-key-here> # IP address assigned to this client inside the VPN
Address = 10.0.0.2/24 # Optional DNS resolver
DNS = 1.1.1.1 [Peer]
# Server public key
PublicKey = <paste-server-public-key-here> # Server public IP address and WireGuard port
Endpoint = <your-server-public-ip>:51820 # Route all traffic through the VPN
AllowedIPs = 0.0.0.0/0 # Keep the tunnel alive through NAT
PersistentKeepalive = 25
[Interface]
# Client private key
PrivateKey = <paste-client-private-key-here> # IP address assigned to this client inside the VPN
Address = 10.0.0.2/24 # Optional DNS resolver
DNS = 1.1.1.1 [Peer]
# Server public key
PublicKey = <paste-server-public-key-here> # Server public IP address and WireGuard port
Endpoint = <your-server-public-ip>:51820 # Route all traffic through the VPN
AllowedIPs = 0.0.0.0/0 # Keep the tunnel alive through NAT
PersistentKeepalive = 25
-weight: 600;">sudo wg-quick up wg0
-weight: 600;">sudo wg-quick up wg0
-weight: 600;">sudo wg-quick up wg0
AllowedIPs = 0.0.0.0/0
AllowedIPs = 0.0.0.0/0
AllowedIPs = 0.0.0.0/0
AllowedIPs = 10.0.0.0/24
AllowedIPs = 10.0.0.0/24
AllowedIPs = 10.0.0.0/24
-weight: 600;">sudo wg show
-weight: 600;">sudo wg show
-weight: 600;">sudo wg show
interface: wg0 public key: <server-public-key> private key: (hidden) listening port: 51820 peer: <client-public-key> endpoint: <client-ip>:<ephemeral-port> allowed ips: 10.0.0.2/32 latest handshake: X seconds ago transfer: 1.23 KiB received, 4.56 KiB sent
interface: wg0 public key: <server-public-key> private key: (hidden) listening port: 51820 peer: <client-public-key> endpoint: <client-ip>:<ephemeral-port> allowed ips: 10.0.0.2/32 latest handshake: X seconds ago transfer: 1.23 KiB received, 4.56 KiB sent
interface: wg0 public key: <server-public-key> private key: (hidden) listening port: 51820 peer: <client-public-key> endpoint: <client-ip>:<ephemeral-port> allowed ips: 10.0.0.2/32 latest handshake: X seconds ago transfer: 1.23 KiB received, 4.56 KiB sent
ping 10.0.0.1
ping 10.0.0.1
ping 10.0.0.1
PING 10.0.0.1 (10.0.0.1) 56(84) bytes of data.
64 bytes from 10.0.0.1: icmp_seq=1 ttl=64 time=12.4 ms
64 bytes from 10.0.0.1: icmp_seq=2 ttl=64 time=11.9 ms
PING 10.0.0.1 (10.0.0.1) 56(84) bytes of data.
64 bytes from 10.0.0.1: icmp_seq=1 ttl=64 time=12.4 ms
64 bytes from 10.0.0.1: icmp_seq=2 ttl=64 time=11.9 ms
PING 10.0.0.1 (10.0.0.1) 56(84) bytes of data.
64 bytes from 10.0.0.1: icmp_seq=1 ttl=64 time=12.4 ms
64 bytes from 10.0.0.1: icmp_seq=2 ttl=64 time=11.9 ms
ssh [email protected]
ssh [email protected]
ssh [email protected]
ListenAddress 10.0.0.1
ListenAddress 10.0.0.1
ListenAddress 10.0.0.1
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">restart ssh
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">restart ssh
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">restart ssh
-weight: 600;">sudo wg show
-weight: 600;">sudo wg show
-weight: 600;">sudo wg show
-weight: 600;">sudo wg-quick up wg0
-weight: 600;">sudo wg-quick up wg0
-weight: 600;">sudo wg-quick up wg0
-weight: 600;">sudo wg-quick down wg0
-weight: 600;">sudo wg-quick down wg0
-weight: 600;">sudo wg-quick down wg0
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">restart wg-quick@wg0
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">restart wg-quick@wg0
-weight: 600;">sudo -weight: 500;">systemctl -weight: 500;">restart wg-quick@wg0
-weight: 600;">sudo -weight: 500;">systemctl is-enabled wg-quick@wg0
-weight: 600;">sudo -weight: 500;">systemctl is-enabled wg-quick@wg0
-weight: 600;">sudo -weight: 500;">systemctl is-enabled wg-quick@wg0
-weight: 600;">sudo journalctl -u wg-quick@wg0
-weight: 600;">sudo journalctl -u wg-quick@wg0
-weight: 600;">sudo journalctl -u wg-quick@wg0
-weight: 600;">sudo journalctl -u wg-quick@wg0 -e
-weight: 600;">sudo journalctl -u wg-quick@wg0 -e
-weight: 600;">sudo journalctl -u wg-quick@wg0 -e
-weight: 600;">sudo wg show
-weight: 600;">sudo wg show
-weight: 600;">sudo wg show
-weight: 600;">sudo ufw -weight: 500;">status
-weight: 600;">sudo ufw -weight: 500;">status
-weight: 600;">sudo ufw -weight: 500;">status
sysctl net.ipv4.ip_forward
sysctl net.ipv4.ip_forward
sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 1
net.ipv4.ip_forward = 1
net.ipv4.ip_forward = 1
Endpoint = <your-server-public-ip>:51820
Endpoint = <your-server-public-ip>:51820
Endpoint = <your-server-public-ip>:51820
AllowedIPs = 10.0.0.2/32
AllowedIPs = 10.0.0.2/32
AllowedIPs = 10.0.0.2/32
AllowedIPs = 0.0.0.0/0
AllowedIPs = 0.0.0.0/0
AllowedIPs = 0.0.0.0/0
AllowedIPs = 10.0.0.0/24
AllowedIPs = 10.0.0.0/24
AllowedIPs = 10.0.0.0/24 - An Ubuntu 24.04 VPS or cloud server
- SSH access to the server
- A non-root user with -weight: 600;">sudo privileges
- A second device, such as a laptop or another server, to act as the VPN client
- UFW or another firewall configured on the server - The server config uses the server private key
- The server peer block uses the client public key
- The client config uses the client private key
- The client peer block uses the server public key - Adding more clients with separate [Peer] blocks
- Assigning each client a unique VPN IP address
- Restricting SSH access to the WireGuard interface
- Using split tunnel mode for admin-only access
- Monitoring the tunnel with -weight: 600;">sudo wg show
- Backing up /etc/wireguard/wg0.conf securely