WireGuard adalah protokol VPN open-source yang dirancang untuk memberikan koneksi yang lebih aman, lebih cepat, dan lebih sederhana dibandingkan protokol VPN tradisional seperti OpenVPN atau IPSec. Dikembangkan oleh Jason A. Donenfeld dan dirilis pertama kali pada tahun 2016, WireGuard kini telah menjadi bagian dari kernel Linux, sehingga semakin populer berkat efisiensi dan keandalannya.
Panduan ini akan membahas proses instalasi dan konfigurasi WireGuard menggunakan dua workstation dengan detail berikut:
Topologi Workstation #
Workstation A
eth0:192.168.160.131/24wg0:10.0.0.1/24
Workstation B
eth0:192.168.160.129/24wg0:10.0.0.2/24
Instalasi WireGuard #
Lakukan instalasi sesuai dengan jenis distribusi Linux yang Anda gunakan.
Linux (RPM-based) #
Misalnya: AlmaLinux, Rocky Linux, CentOS Stream, RHEL.
dnf -y install epel-release elrepo-release
dnf -y install wireguard-tools kmod-wireguardLinux (DEB-based) #
Misalnya: Debian, Ubuntu.
apt -y install wireguardUsing WireGuard #
Aktifkan modul kernel WireGuard:
modprobe wireguardGenerate Private Key #
Lakukan pada kedua Workstation:
wg genkey > privatekeyKonfigurasi Interface wg0
#
Workstation A
ip link add wg0 type wireguard
ip addr add 10.0.0.1/24 dev wg0
wg set wg0 private-key ./privatekey
ip link set wg0 upWorkstation B
ip link add wg0 type wireguard
ip addr add 10.0.0.2/24 dev wg0
wg set wg0 private-key ./privatekey
ip link set wg0 upCek Public Key #
Gunakan perintah berikut untuk melihat public key yang nanti akan digunakan sebagai peer.
Workstation A
# wg show
interface: wg0
public key: /FDHZRntW7H3WNOmzLWWo0d5UGicyt+BOvl0Khynsik=
private key: (hidden)
listening port: 45960Workstation B
# wg show
interface: wg0
public key: JSi9B7Vic3nfPuPVLyerYEqR13yFIY5sUk2FNaaL42Y=
private key: (hidden)
listening port: 33497Menghubungkan Workstation A ↔ Workstation B #
Konfigurasi peer dilakukan dengan menambahkan public key, endpoint, dan allowed-ips.
Workstation A
wg set wg0 peer JSi9B7Vic3nfPuPVLyerYEqR13yFIY5sUk2FNaaL42Y= \
endpoint 192.168.160.129:33497 \
persistent-keepalive 25 \
allowed-ips 10.0.0.2/32Workstation B
wg set wg0 peer /FDHZRntW7H3WNOmzLWWo0d5UGicyt+BOvl0Khynsik= \
endpoint 192.168.160.131:45960 \
persistent-keepalive 25 \
allowed-ips 10.0.0.1/32Testing Koneksi #
Test dari Workstation A
# ping -c4 10.0.0.2
PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
64 bytes from 10.0.0.2: icmp_seq=1 ttl=64 time=1.12 ms
64 bytes from 10.0.0.2: icmp_seq=2 ttl=64 time=0.754 ms
64 bytes from 10.0.0.2: icmp_seq=3 ttl=64 time=0.959 ms
64 bytes from 10.0.0.2: icmp_seq=4 ttl=64 time=0.702 msStatus pada Workstation B
# wg show
interface: wg0
public key: JSi9B7Vic3nfPuPVLyerYEqR13yFIY5sUk2FNaaL42Y=
private key: (hidden)
listening port: 33497
peer: /FDHZRntW7H3WNOmzLWWo0d5UGicyt+BOvl0Khynsik=
endpoint: 192.168.160.131:45960
allowed ips: 10.0.0.1/32
latest handshake: 30 seconds ago
transfer: 4.48 KiB received, 3.05 KiB sent
persistent keepalive: every 25 secondsUsing wg-quick
#
Selain konfigurasi manual, Anda juga dapat menggunakan wg-quick untuk mempermudah proses setup interface WireGuard. Tool ini memungkinkan Anda membuat konfigurasi yang persisten serta memulai koneksi hanya dengan satu perintah.
Generate Private Key & Public Key #
Lakukan pada kedua Workstation:
wg genkey | tee privatekey | wg pubkey > publickeyPerintah di atas akan menghasilkan dua file:
privatekeypublickey
Konfigurasi wg-quick
#
Buat file konfigurasi untuk masing-masing workstation.
Workstation A
Buat file:
nano /etc/wireguard/server.confIsi konfigurasi:
[Interface]
Address = 10.0.0.1
ListenPort = 45960
PrivateKey = YKAPzFfqrUBkiw18kGCOuJTkuCV8ldXB03gLJkCNH1w=
# PresharedKey = $(wg genpsk)
[Peer]
PublicKey = JSi9B7Vic3nfPuPVLyerYEqR13yFIY5sUk2FNaaL42Y=
PresharedKey = LDbol67eaLt351b21xUwnQLdkB/bUzgCepzWx7Ekkxc=
AllowedIPs = 10.0.0.2/32
Endpoint = 192.168.160.129:33497Workstation B
Buat file:
nano /etc/wireguard/client.confIsi konfigurasi:
[Interface]
Address = 10.0.0.2
ListenPort = 33497
PrivateKey = 6LQjtoSje8BjYXISKzE+/YwhTw8VRO0bEHYOMKCnHEo=
[Peer]
PublicKey = /FDHZRntW7H3WNOmzLWWo0d5UGicyt+BOvl0Khynsik=
PresharedKey = LDbol67eaLt351b21xUwnQLdkB/bUzgCepzWx7Ekkxc=
AllowedIPs = 10.0.0.1/32
Endpoint = 192.168.160.131:45960
PersistentKeepalive = 25Mengaktifkan WireGuard #
Setelah file konfigurasi siap, aktifkan interface WireGuard dengan wg-quick.
Workstation A
wg-quick up serverWorkstation B
wg-quick up clientEnable WireGuard Saat Boot #
Agar interface WireGuard otomatis aktif saat sistem booting, gunakan perintah berikut:
Workstation A
systemctl enable wg-quick@serverWorkstation B
systemctl enable wg-quick@clientUntuk memastikan status service:
systemctl status wg-quick@server
# atau
systemctl status wg-quick@clientVPN #
Terdapat dua pendekatan:
- Setup otomatis menggunakan script Nyr
- Setup manual untuk memahami alurnya secara penuh
Setup Otomatis (Script Nyr) #
Script ini akan:
- Menginstal paket WireGuard
- Membuat konfigurasi server
- Membuat konfigurasi klien (client.conf)
- Mengaktifkan firewall + NAT secara otomatis
Jalankan perintah berikut pada Workstation A (Server VPN):
wget https://git.io/wireguard -O wireguard-install.sh && bash wireguard-install.shScript akan memunculkan prompt seperti:
- IP publik server
- Port WireGuard (default 51820)
- DNS untuk klien
- Nama konfigurasi klien
Anda dapat menggunakan nilai default atau menyesuaikannya.
Setelah instalasi selesai, file client.conf akan berada di direktori yang sama:
# ls -l
total 32
-rw-r--r-- 1 root root 324 Nov 25 09:19 client.conf
-rw-r--r-- 1 root root 26724 Nov 25 09:18 wireguard-install.shDownload file ke Workstation B:
scp root@YOUR_SERVER_IP:/root/client.conf /etc/wireguard/Aktifkan WireGuard pada Workstation B:
wg-quick up clientKlien kini terhubung ke VPN.
Setup Manual #
Aktifkan IP Forwarding
echo "net.ipv4.ip_forward=1" | tee -a /etc/sysctl.conf
sysctl -pKonfigurasi WireGuard Server. File: /etc/wireguard/server.conf
[Interface]
Address = 10.0.0.1/24
ListenPort = 51820
PrivateKey = AEi/B7B0ulkppXRN4WWnyrZIg3x8o+fOQquiL9Gt43o=
# NAT + firewall
PostUp = iptables -A FORWARD -i %i -j ACCEPT; iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
PostDown = iptables -D FORWARD -i %i -j ACCEPT; iptables -t nat -D POSTROUTING -o eth0 -j MASQUERADE
# PresharedKey = $(wg genpsk)
[Peer]
PublicKey = xtLLY1oDdDdVBGxnKafexOO2mx63WySv1qUf9+oVUjw=
PresharedKey = LDbol67eaLt351b21xUwnQLdkB/bUzgCepzWx7Ekkxc=
AllowedIPs = 10.0.0.2/32Konfigurasi Klien (Workstation B). File: /etc/wireguard/client.conf
[Interface]
Address = 10.0.0.2/32
PrivateKey = SFFCKS3L4iIrvYLaQOU1RQo+P0uw0VojYILKxFurdVg=
DNS = 1.1.1.1
[Peer]
PublicKey = 48XNnKVRJjXk892Ku7DO7CzU6B2OehgRnd/0ln8FryM=
PresharedKey = LDbol67eaLt351b21xUwnQLdkB/bUzgCepzWx7Ekkxc=
AllowedIPs = 0.0.0.0/0
Endpoint = 192.168.160.129:51820
PersistentKeepalive = 250.0.0.0/0= seluruh trafik melewati VPN (full-tunnel).
Setelah file konfigurasi siap, aktifkan interface WireGuard dengan wg-quick.
Workstation A
wg-quick up serverWorkstation B
wg-quick up clientTroubleshooting #
Jika muncul error saat menjalankan wg-quick seperti contoh berikut:
# wg-quick up client
[#] ip link add client type wireguard
[#] wg setconf client /dev/fd/63
[#] ip -4 address add 10.7.0.2/24 dev client
[#] ip -6 address add fddd:2c4:2c4:2c4::2/64 dev client
[#] ip link set mtu 8920 up dev client
[#] resolvconf -a client -m 0 -x
Failed to set DNS configuration: Could not activate remote peer.
[#] ip link delete dev clientMasalah ini biasanya terjadi karena layanan systemd-resolved belum aktif.
Aktifkan systemd-resolved dengan menjalankan perintah berikut:
systemctl unmask systemd-resolved
systemctl enable --now systemd-resolvedSetelah itu, jalankan kembali perintah:
wg-quick up client