Question Help me to set up Wireguard server on Ubuntu 22.04 LTS

GorgKhan

Reputable
Jul 21, 2020
18
0
4,510
I get a virtual Cloud Server which is Ubuntu 22.04 LTS. I followed this tutorial.
I don't know why my IP is 192.168.0.22 rather than showing my public IP address in terminal.

Untitled.png


Also this is the Code I used:
Code:
sudo apt update

nano /etc/sysctl.d/99-sysctl.conf
#    to Enable ip4 forward = 1

sudo ufw allow 51820/udp
sudo ufw allow 53/udp
sudo ufw allow 80/udp
sudo ufw allow 443/udp
sudo ufw allow 53/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw allow OpenSSH

sudo ufw disable
sudo ufw enable

systemctl reboot

sudo apt install wireguard

wg genkey | sudo tee /etc/wireguard/srvrpri.key
sudo chmod go= /etc/wireguard/srvrpri.key

sudo cat /etc/wireguard/srvrpri.key | wg pubkey | sudo tee /etc/wireguard/srvrpub.key

sudo nano /etc/wireguard/wg0.conf


[Interface]
PrivateKey = srvrpri.key
Address = 172.16.0.1/24
ListenPort = 51820
SaveConfig = true
PostUp = ufw route allow in on wg0 out on enp3s0
PostUp = iptables -t nat -I POSTROUTING -o enp3s0 -j MASQUERADE
PreDown = ufw route delete allow in on wg0 out on enp3s0
PreDown = iptables -t nat -D POSTROUTING -o enp3s0 -j MASQUERADE

[Peer]
PublicKey = cleint0pubkey.key
AllowedIPs = 172.16.0.2/32



sudo systemctl enable wg-quick@wg0.service

sudo systemctl start wg-quick@wg0.service

sudo systemctl status wg-quick@wg0.service
 

lantis3

Distinguished
Nov 5, 2015
639
103
19,070
why my IP is 192.168.0.22 rather than showing my public IP address

Because you are behind ISP's NAT, just like your home LAN. Public IP costs money. You will never get it for free.
And if you have a public IP for your machine, if you didn't configure or setup firewall correctly, the minute you power on the machine, you will be under immediate and constant attacks from the internet.

Use Tailscale instead if for personal use. Free for 3 users/100 devices.
Tailscale is based on Wireguard but use UDP instead TCP.
https://tailscale.com/compare/wireguard
  • No port forwarding required.
  • No key generation required.
  • No key private / public paring.
  • No public IP required.
  • No firewall configuration required, at least on Windows.
Tailscale will give you a complex long public domain name. But if you turn on its free MagicDNS feature, you can use machine name directly without appending that domain name.

You also don't have to set config files. At least for my Windows experience.

Many tutorials on Youtube.

Not familiar with Linux, just playing with desktop in the VM.

https://tailscale.com/pricing

simple instruction for Ubuntu
https://tailscale.com/kb/1187/install-ubuntu-2204

Alternatives
 
Last edited: