WireGuard adalah protokol VPN (Virtual Private Network) yang sederhana namun cepat, dapat menjadi pengganti protokol VPN lain seperti OpenVPN dan IPsec. WireGuard telah dimasukkan ke dalam kernel Linux 5.6 dan mulai tersedia di Ubuntu 20.04.
Install WireGuard Server
Sistem operasi yang digunakan sebagai WireGuard server adalah 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
Membuat file konfigurasi untuk WireGuard interface di server.
nano /etc/wireguard/wg0.conf
Masukkan konfigurasi interface.
[Interface]
PrivateKey = cFtmVKUPUBhK8qpzi4KbTbOHG1frrPQbnxYxkyWhAGU=
Address = 192.168.10.1/24
ListenPort = 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)
Sistem operasi yang digunakan sebagai WireGuard peer (client) adalah Ubuntu Server 22.04 LTS dengan user root. Langkahnya mirip dengan WireGuard server.
Membuat konfigurasi interface WireGuard di client.
nano /etc/wireguard/wg0.conf
Masukkan konfigurasi interface.
PrivateKey = gFyRMQtq83pMuf3RD1EiCL09mQtFhdqMjjlPJ1J3yFY=
Address = 192.168.10.2/24 [Peer]
PublicKey = 8q8jmSa5RwWK56NPCU4wHNFYczzcKYg0okM15FUJEz4=
Endpoint = 159.89.194.36:51820
AllowedIPs = 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.
Menjalankan WireGuardsystemctl start wg-quick@wg0.service
systemctl enable wg-quick@wg0.service
systemctl status wg-quick@wg0.service