最近公司換了新的路由器有支援VPN功能,同事說只要裝個軟體就可以輕鬆連到公司,但是我是用ubuntu所以還是會比較搞工一點,以下是我的 安裝與設定OpenVPN 過程。
apt install apt-transport-https
curl -fsSL https://swupdate.openvpn.net/repos/openvpn-repo-pkg-key.pub | gpg –dearmor > /etc/apt/trusted.gpg.d/openvpn-repo-pkg-keyring.gpg
18.04
curl -fsSL https://swupdate.openvpn.net/community/openvpn3/repos/openvpn3-bionic.list >/etc/apt/sources.list.d/openvpn3.list
apt install openvpn3
載入設定檔
openvpn3 session-start –config xxx.ovpn
列出session 清單
openvpn3 sessions-list
Path: /net/openvpn/v3/sessions/f23ae3cas2dcas44b4s9046s904ea7e103d9
Created: Fri Feb 24 16:46:28 2023 PID: 21134
Owner: root Device: tun0
Config name: xxx.ovpn
Session name: xxx.asuscomm.com
Status: Connection, Client connected
停用vpn
openvpn3 session-manage –config xxx.ovpn –disconnect
Initiated session shutdown.
Connection statistics:
BYTES_IN……………..3438089
BYTES_OUT…………….2914174
PACKETS_IN………………7341
PACKETS_OUT……………..7683
TUN_BYTES_IN………….2718398
TUN_BYTES_OUT…………3309703
TUN_PACKETS_IN…………..7670
TUN_PACKETS_OUT………….7328
N_RECONNECT………………..1
openvpn3 sessions-list
No sessions available
如果沒正常的停用 session 可以先
openvpn3 session-manage –cleanup Session name
常用指令
openvpn3 session-start –config client.ovpn
openvpn3 config-import –config client.ovpn -name jeff_vpn
openvpn3 config-manage –config jeff_vpn -allow-compression yes
openvpn3 configs-list
openvpn3 config-remove –path /net/openvpn/v3/sessions/135f1f1as49ads44cas9da7s6dd2a2525b88
實際範例
root@jeff-Inspiron-3471:/home/jeff# openvpn3 session-start –config client.ovpn
Using configuration profile from file: client.ovpn
Session path: /net/openvpn/v3/sessions/e1956517s0e25s4bfas8c03saa16bxxxxx
Auth User name: jeff
Auth Password:
session-start: ** ERROR ** Failed to connect: Connection, Client disconnected
root@jeff-Inspiron-3471:/home/jeff# openvpn3-admin journal –path /net/openvpn/v3/sessions/e1956517s0e25s4bfas8c03saa16bxxxxx
Tue Jan 16 12:12:46 2024 {tag:5488674904447} Client INFO: Starting connection
Tue Jan 16 12:12:46 2024 {tag:5488674904447} Client INFO: Connecting
Tue Jan 16 12:12:46 2024 {tag:5488674904447} Client INFO: Connected: jeff@222.111.333.193:1224 (211.23.61.193) via /UDP on tun/10.8.0.10/ gw=[10.8.0.9/] mtu=(default)
Tue Jan 16 12:12:46 2024 {tag:5488674904447} Client !! FATAL !!: [COMPRESS_ERROR] server pushed compression settings that are not allowed and will result in a non-working connection.
Tue Jan 16 12:12:46 2024 {tag:5488674904447} Client INFO: Disconnected
root@jeff-Inspiron-3471:/home/jeff# openvpn3 config-import –config client.ovpn –name jeff_vpn
Configuration imported. Configuration path: /net/openvpn/v3/configuration/48f419eax6a24x45bdxa167xfff
root@jeff-Inspiron-3471:/home/jeff# openvpn3 config-manage –config jeff_vpn –allow-compression yes
Set override ‘allow-compression’ to ‘yes’
root@jeff-Inspiron-3471:/home/jeff# openvpn3 session-start –config jeff_vpn
Using pre-loaded configuration profile ‘jeff_vpn’
Session path: /net/openvpn/v3/sessions/ef9d3a83s8b49s4870s8d9bs4927a7c3f3a3
Auth User name: jeff
Auth Password:
Connected