Install WireGuard VPN Rocky Linux 9
Install WireGuard VPN Rocky Linux 9

Install WireGuard VPN Server di Rocky Linux 9 + (NAT)

WireGuard solusi VPN modern yang terkenal dengan performa tinggi, konfigurasi sederhana, dan keamanan yang kuat.

Dibandingkan protokol tradisional seperti OpenVPN atau IPSec, WireGuard menawarkan kemudahan instalasi dan koneksi yang lebih cepat, berikut Install WireGuard VPN Rocky Linux 9.

Install WireGuard Server

Instal repositori EPEL

sudo dnf install epel-release -y

Install package tool WireGuard.

sudo dnf install wireguard-tools -y

Lihat versi WireGuard yang terpasang di server rocky linux 9.

sudo wg --version

Output

wireguard-tools v1.0.20210914 - https://git.zx2c4.com/wireguard-tools/

Konfigurasi WireGuard Server

Buat pasangan kunci privat dan publik server WireGuard baru di direktori /etc/wireguard.

wg genkey | sudo tee /etc/wireguard/server_private.key | wg pubkey | sudo tee /etc/wireguard/server_public.key

Ubah izin file untuk hanya memberikan akses baca kepada pengguna yang memiliki hak istimewa pada kunci yang dihasilkan.

sudo chmod 600 /etc/wireguard/server_private.key /etc/wireguard/server_public.key

Lihat value server_private.key dan server_public.key

sudo cat /etc/wireguard/server_private.key /etc/wireguard/server_public.key

Output

(Server Privaye Key)
wAVfTr+0unS6rhwt8DUzzsB5JhXwZZTVew4hiO2lOkw=

(Server Public Key)
+9eHqpI9wgCYhrbMCdKbsqYKUEdQa7FvSVgL1CNgp0g=

Lihat network interfaces server yang tersedia dan verifikasi detail antarmuka utama.

ip a

Output

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 52:54:00:a9:65:09 brd ff:ff:ff:ff:ff:ff
    altname enp0s5
    altname ens5
    inet 10.3.10.247/22 brd 10.3.11.255 scope global noprefixroute eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::5054:ff:fea9:6509/64 scope link
       valid_lft forever preferred_lft forever

Buat file konfigurasi interface server WireGuard baru. Misalnya, wg0.conf .

sudo nano /etc/wireguard/wg0.conf

Tambahkan konfigurasi dibawah ke dalam file. Ganti dengan server_private_key sebenarnya yang telah kamu buat sebelumnya.

[Interface]
Address = 172.16.0.1/24
PrivateKey = server_private_key
ListenPort = 51820

Keterangan:

  • Address = Private IP address untuk IP VPN server
  • PrivateKey = Private key yang sudah dibuat
  • ListenPort = Nomor port default WireGuard 51820 UDP, bisa menggunakan nomor lain

Konfigurasi WireGuard Client

Buat private key dan publik key baru, di direktori WireGuard /etc/wireguard/. Ganti ‘client‘ dengan skema penamaan client yang kamu inginkan.

wg genkey | sudo tee /etc/wireguard/client_private.key | wg pubkey | sudo tee /etc/wireguard/client_public.key

Lihat nilai private dan public key client WireGuard yang dihasilkan.

sudo cat /etc/wireguard/client_private.key /etc/wireguard/client_public.key

Output

Salin value client private key dan client publik key ke text editor.

(Client Private Key)
2Ip88ypQcDkfudZi0mCG8CY59YQQW90Rd5K8SARDpEE=

(Client Public Key)
Es+p1bt06LU9/vqGk67nc44oLf/Tahw2G5mS1wr8Kj4=

Buat file configuration client WireGuard baru.

sudo nano /etc/wireguard/client.conf

Tambahkan konfigurasi berikut ke dalam file. Ganti Client_Private_Key, Server_Public_Key yang kamu buat, dan IP_Public_Server dengan alamat IP server WireGuard.

[Interface]
PrivateKey = Client_Private_Key
Address = 172.16.0.2/24

[Peer]
PublicKey = Server_Public_Key
AllowedIPs = 172.16.0.1
Endpoint = IP_Public_Server:51820
PersistentKeepalive = 25

Keterangan:

  • 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 (172.16.0.1) atau satu subnet (172.16.0.0/24).
  • PersistentKeepalive = Mengirimkan paket kosong (Data Kosong) ke server setiap 25 detik secara otomatis.

Setelah selesain membuat file konfigurasi WireGuard interface di sisi client, update konfigurasi interface di WireGuard server dengan menambahkan [Peer] dan memasukkan Public Key milik Peer (VPN client).

sudo nano /etc/wireguard/wg0.conf

Tambahkan konfigurasi berikut di akhir file. Ganti Client_Public_Key WireGuard telah kamu buat sebelumnya.

[Peer]
PublicKey = Client_Public_Key
AllowedIPs = 172.16.0.2/24

Simpan dan keluar.

Management WireGuard VPS Server

Enable dan Start interface wg0 server WireGuard.

sudo systemctl enable [email protected]
sudo systemctl start [email protected]

Lihat status interface WireGuard dan verifikasi bahwa interface tersebut aktif di server.

sudo systemctl status [email protected]

Output

[email protected] - WireGuard via wg-quick(8) for wg0
    Loaded: loaded (/usr/lib/systemd/system/[email protected]; enabled; preset: disabled)
    Active: active (exited) since Wed 2026-05-20 14:35:23 CST; 1min 26s ago
      Docs: man:wg-quick(8)
            man:wg(8)
            https://www.wireguard.com/
            https://www.wireguard.com/quickstart/
            https://git.zx2c4.com/wireguard-tools/about/src/man/wg-quick.8
            https://git.zx2c4.com/wireguard-tools/about/src/man/wg.8
   Process: 19002 ExecStart=/usr/bin/wg-quick up wg0 (code=exited, status=0/SUCCESS)
  Main PID: 19002 (code=exited, status=0/SUCCESS)
       CPU: 40ms

Lihat log interface WireGuard untuk memverifikasi proses tunnel.

sudo journalctl -u [email protected]

Output

systemd[1]: Starting WireGuard via wg-quick(8) for wg0.
wg-quick[52638]: [#] ip link add wg0 type wireguard
wg-quick[52638]: [#] wg setconf wg0 /dev/fd/63
wg-quick[52638]: [#] ip link set mtu 1420 up dev wg0
wg-quick[52638]: [#] ip -4 route add 172.16.0.2/32 dev wg0
systemd[1]: Finished WireGuard via wg-quick(8) for wg0.
systemd[1]: Stopping WireGuard via wg-quick(8) for wg0.

Konfigurasi Firewall Rule

Enable dan Start firewalld

sudo systemctl enable firewalld
sudo systemctl start firewalld

Izinkan port 22 tcp (SSH) dan port 51820 (WireGuard) udp, lalu reload firewalld.

sudo firewall-cmd --permanent --add-port=22/tcp && sudo firewall-cmd --reload
sudo firewall-cmd --permanent --add-port=51820/udp
sudo firewall-cmd --reload

Lihat status firewalld

sudo systemctl status firewalld

Pastikan firewalld status active.

firewalld.service - firewalld - dynamic firewall daemon
     Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; preset: enabled)
     Active: active (running) since Wed 2026-05-20 17:24:48 CST; 42min ago
       Docs: man:firewalld(1)
   Main PID: 579 (firewalld)
      Tasks: 2 (limit: 10668)
     Memory: 41.2M (peak: 42.9M)
        CPU: 663ms
     CGroup: /system.slice/firewalld.service
             └─579 /usr/bin/python3 -s /usr/sbin/firewalld --nofork --nopid

Reload firewalld untuk menerapkan perubahan konfigurasi.

sudo firewall-cmd --reload

Lihat semua rule port firewalld yang tersedia di server dan verifikasi bahwa port WireGuard tersedia.

sudo firewall-cmd --list-ports
Output

22/tcp 51820/udp

Aktifkan IPV4 Forwarding untuk meneruskan paket dari jaringan WireGuard ke interface publik server.

echo 'net.ipv4.ip_forward = 1' | sudo tee -a /etc/sysctl.conf

Reload konfigurasi sysctl untuk menerapkan perubahan konfigurasi.

sudo sysctl -p

Aktifkan NAT (Network Address Translation) untuk subnet WireGuard 172.16.0.0/24 agar client terhubung ke Internet.

sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="172.16.0.0/24" masquerade'

Reload firewalld untuk menerapkan perubahan konfigurasi baru.

sudo firewall-cmd --reload

Pengujian WireGuard Client

Windows

Download dan install WireGuard client desktop  dari website resminya.

Website Download WireGuard Client Windows
Website Download WireGuard Client Windows

Buat file baru dengan nama wg0.conf, lalu isikan script dibawah.

[Interface]
PrivateKey = 2Ip88ypQcDkfudZi0mCG8CY59YQQW90Rd5K8SARDpEE=
Address = 172.16.0.2/24

[Peer]
PublicKey = +9eHqpI9wgCYhrbMCdKbsqYKUEdQa7FvSVgL1CNgp0g=
AllowedIPs = 0.0.0.0/0, 172.16.0.1/24
Endpoint = IP_Public_WireGuard:51820
PersistentKeepalive = 25

Klik Add Tunnel untuk menambahkan file wg0.conf ke WireGuard client desktop.

Import File Configuration WireGuard Client
Import File Configuration WireGuard Client

File konfigurasi wg0 WireGuard client yang terbaca. Mengkatifkan VPN WireGuard  klik Activate, tunggu sampai proses menghubungkan ke server WireGuard berhasil.

File wg0 terbaca di WireGuard Client Desktop Windows
File wg0 terbaca di WireGuard Client Desktop Windows

Status WireGuard client berhasil terhubung ke server VPN.

Status WireGuard Client Terhubung
Status WireGuard Client Terhubung

Ping IP Private peer client dari WireGuard Server

Ping IP Private Client dari WireGuard Server VPN
Ping IP Private Client dari WireGuard Server VPN

Ping IP Private peer WireGuard Server dari Client

Ping IP Private Peer WireGuard Server VPN dari Client
Ping IP Private Peer WireGuard Server VPN dari Client

Lakukan ping ke 8.8.8.8 dan google.com .

Test Ping
Test Ping

 

Sebelum Menghubungkan ke WireGuard VPN Server
Sebelum Menghubungkan ke WireGuard VPN Server

 

Sesudah Menghubungkan ke WireGuard VPN Server
Sesudah Menghubungkan ke WireGuard VPN Server

Kesimpulan

Setelah menyelesaikan langkah-langkah Install WireGuard VPN Rocky Linux 9, kamu telah berhasil menginstal dan mengonfigurasi server WireGuard VPN di Rocky Linux 9.

Server kini siap menerima koneksi dari klien yang telah dikonfigurasi, menyediakan tunnel yang aman dan cepat untuk aktivitas online.