在 Ubuntu 設置 WireGuard ClientSetting Up a WireGuard Client on Debian/Ubuntu
想讓你的網路變得更安全、更隱私,WireGuard 就是你的好夥伴!這是一款超高效、超簡單的 VPN 協議,不但安全性強,而且性能優異。這篇文章將會示範如何在 Debian/Ubuntu 系統上安裝並配置 WireGuard Client。
第一步:安裝 WireGuard
首先,更新軟體包列表並安裝 WireGuard,執行以下命令:
sudo apt update
sudo apt install wireguard
第二步:生成 WireGuard 密鑰
WireGuard 需要一對加密密鑰來確保安全通信。執行以下命令來生成密鑰:
cd /etc/wireguard/
wg genkey | tee privatekey | wg pubkey > publickey
第三步:配置 WireGuard 客戶端
在 /etc/wireguard/
目錄下建立 my-client.conf
配置檔,並填入以下內容:
範例配置:
[Interface]
PrivateKey = <您的私鑰>
Address = <WireGuard 伺服器分配的 IP,例如 10.13.0.105/32>
DNS = <可選,指定 DNS 伺服器,例如 8.8.8.8>
[Peer]
PublicKey = <WireGuard 伺服器的公鑰,例如 utrkMw+tobMpNfQgxa3ZnFzTjhja1XPXz4QQLllcVis=>
AllowedIPs = <VPN 網段,例如 10.13.0.0/24>, <內部網段,例如 10.101.0.0/16>
Endpoint = <WireGuard 伺服器的 URL 或 IP,例如 wireguard01-server.aws.test.tw:51820>
PersistentKeepalive = 25
⚠️ 注意:如果 Client 與伺服器位於不同網路,請確保 Endpoint
使用的是伺服器的 public IP。
範例配置:
[Interface]
PrivateKey = WGMM7Q3mh2y2K+jXoMwyUBkJQm/Z/7zxfOOPb1bDw1s=
Address = 10.13.0.105/32
DNS = 168.63.129.16 # Azure 預設的 DNS 伺服器
[Peer]
PublicKey = utrkMw+tobMpNfQgxa3ZnFzTjhja1XPXz4QQLllcVis=
AllowedIPs = 10.13.0.0/24, 168.63.129.16/32
Endpoint = wireguard01-server.aws.test.tw:51820
PersistentKeepalive = 25
第四步:啟動 WireGuard 客戶端
當配置檔建立完成後,啟動 WireGuard 介面:
wg-quick up my-client
若希望開機自動啟動 WireGuard,執行:
sudo systemctl enable wg-quick@my-client
第五步:驗證連線狀態
執行以下命令檢查 WireGuard 連線狀態:
wg
預期的輸出範例:
interface: my-client
public key: aPs8od/ItG6Y4jqOzTnR1SHTJPs8od/ItG6Y4jXWc1EM=
private key: (hidden)
listening port: 57670
peer: utrkMw+tobMpNfQgxa3ZnFzTjhja1XPXz4QQLllcVis=
endpoint: 132.116.162.174:51820
allowed ips: 10.13.0.0/24
latest handshake: 1 minute, 27 seconds ago
transfer: 10.50 KiB received, 11.59 KiB sent
persistent keepalive: every 25 seconds
留言
張貼留言