![]() |
Install WireGuard VPN di Ubuntu 22.04 |
Install WireGuard Server
Sistem operasi yang digunakan sebagai WireGuard server yakni Ubuntu Server 22.04 LTS dengan user root.
Install WireGuard.
apt install wireguard
Membuat private key WireGuard server.
wg genkey | tee /etc/wireguard/private.key
Hasil perintah di atas meng-generate key dan menyimpannya ke dalam file private.key.
cFtmVKUPUBhK8qpzi4KbTbOHG1frrPQbnxYxkyWhAGU=
Mengubah permission private.key, menghilangkan semua permission untuk group dan other.
chmod 600 /etc/wireguard/private.key
Meng-generate public key WireGuard server berdasarkan private key yang telah dibuat sebelumnya dan menyimpannya ke dalam file public.key.
cat /etc/wireguard/private.key | wg pubkey | tee /etc/wireguard/public.key
Hasil perintah di atas.
8q8jmSa5RwWK56NPCU4wHNFYczzcKYg0okM15FUJEz4=
Konfigurasi WireGuard Interface di Server
nano /etc/wireguard/wg0.conf
[Interface]PrivateKey = cFtmVKUPUBhK8qpzi4KbTbOHG1frrPQbnxYxkyWhAGU=Address = 192.168.10.1/24ListenPort = 51820
- PrivateKey = Private key yang sudah dibuat
- Address = Private IP address untuk IP VPN server
- ListenPort = Nomor port default WireGuard 51820 UDP, bisa menggunakan nomor lain
Konfigurasi WireGuard Peer (Client)
apt install wireguard
wg genkey | tee /etc/wireguard/private.keychmod 600 /etc/wireguard/private.key
6Aqa8MWTrdAaqvAxe2vCuKFZqUgAcAltNkZj9UnvEEw=
cat /etc/wireguard/private.key | wg pubkey | tee /etc/wireguard/public.key
uic2Ph1uCFFXz2ZzbHyZrmuidU1+v0XD/vN1+ROkMTE=
nano /etc/wireguard/wg0.conf
[Interface]PrivateKey = gFyRMQtq83pMuf3RD1EiCL09mQtFhdqMjjlPJ1J3yFY=Address = 192.168.10.2/24[Peer]PublicKey = 8q8jmSa5RwWK56NPCU4wHNFYczzcKYg0okM15FUJEz4=Endpoint = 159.89.194.36:51820AllowedIPs = 192.168.10.0/24
- PrivateKey = Private key milik peer (client)
- Address = Private IP address untuk IP VPN client
- PublicKey = Public key milik VPN server
- Endpoint = Public IP address milik VPN server beserta nomor port yang digunakan
- AllowedIPs = IP address yang diijinkan terhubung ke peer. Bisa menggunakan host IP address (192.168.10.1) atau satu subnet (192.168.10.0/24). Jika ingin memasukkan IP address lebih dari satu, pisahkan dengan tanda koma.
[Interface]PrivateKey = cFtmVKUPUBhK8qpzi4KbTbOHG1frrPQbnxYxkyWhAGU=Address = 192.168.10.1/24ListenPort = 51820[Peer]PublicKey = uic2Ph1uCFFXz2ZzbHyZrmuidU1+v0XD/vN1+ROkMTE=AllowedIPs = 192.168.10.0/24
Menjalankan WireGuard
systemctl start wg-quick@wg0.servicesystemctl enable wg-quick@wg0.servicesystemctl status wg-quick@wg0.service
Menguji Koneksi VPN
wg
interface: wg0public key: 8q8jmSa5RwWK56NPCU4wHNFYczzcKYg0okM15FUJEz4=private key: (hidden)listening port: 51820peer: uic2Ph1uCFFXz2ZzbHyZrmuidU1+v0XD/vN1+ROkMTE=endpoint: 146.190.106.74:50714allowed ips: 192.168.10.2/32latest handshake: 3 minutes, 34 seconds agotransfer: 47.11 KiB received, 18.06 KiB sent
interface: wg0public key: uic2Ph1uCFFXz2ZzbHyZrmuidU1+v0XD/vN1+ROkMTE=private key: (hidden)listening port: 50714peer: 8q8jmSa5RwWK56NPCU4wHNFYczzcKYg0okM15FUJEz4=endpoint: 159.89.194.36:51820allowed ips: 192.168.10.0/24latest handshake: 4 minutes, 7 seconds agotransfer: 1.21 KiB received, 1.30 KiB sent
ping -c 3 192.168.10.2PING 192.168.10.2 (192.168.10.2) 56(84) bytes of data.64 bytes from 192.168.10.2: icmp_seq=1 ttl=64 time=0.807 ms64 bytes from 192.168.10.2: icmp_seq=2 ttl=64 time=0.761 ms64 bytes from 192.168.10.2: icmp_seq=3 ttl=64 time=0.933 ms
ping -c 3 192.168.10.1PING 192.168.10.1 (192.168.10.1) 56(84) bytes of data.64 bytes from 192.168.10.1: icmp_seq=1 ttl=64 time=0.761 ms64 bytes from 192.168.10.1: icmp_seq=2 ttl=64 time=1.46 ms64 bytes from 192.168.10.1: icmp_seq=3 ttl=64 time=0.779 ms
Menambah WireGuard Peer (VPN Client)
[Interface]PrivateKey = cFtmVKUPUBhK8qpzi4KbTbOHG1frrPQbnxYxkyWhAGU=Address = 192.168.10.1/24ListenPort = 51820[Peer]PublicKey = uic2Ph1uCFFXz2ZzbHyZrmuidU1+v0XD/vN1+ROkMTE=AllowedIPs = 192.168.10.2/32[Peer]PublicKey = ueotNN04cxkPGLxMC94M5CMiuobQsFXGphE962l10kg=AllowedIPs = 192.168.10.3/32
Menghubungkan antar WireGuard Peer
nano /etc/sysctl.conf
net.ipv4.ip_forward=1
sysctl -p
net.ipv4.ip_forward = 1