🐧 Linux 用户翻墙:最硬核的平台,也最自由

Linux 是所有平台中 VPN 配置最灵活的——你可以完全用命令行控制每一个数据包的走向。但灵活性也意味着复杂性:没有统一的 GUI 客户端、发行版差异大、手动配置容易出错。

本文覆盖:

  1. 6 家主流 VPN 的 Linux 客户端支持情况实测
  2. WireGuard 命令行配置(从零到翻墙)
  3. OpenVPN 命令行和 NetworkManager 导入
  4. Clash / sing-box 替代方案
  5. Kill Switch + DNS 防泄漏安全加固

适合人群:Ubuntu/Debian/Fedora/Arch 用户,开发者/运维人员。


1. 为什么 Linux 需要专属 VPN 指南?

Linux 的独特性

维度Windows/MacLinux
GUI 客户端所有VPN都有部分VPN无GUI
配置方式一键安装命令行为主
发行版差异Ubuntu/Debian/Fedora/Arch 包管理不同
网络管理系统统一NetworkManager/netctl/systemd-networkd
DNS 系统统一systemd-resolved/dnsmasq/resolv.conf
Kill Switch客户端内置需手动配 iptables/nftables

核心挑战

  1. 不是所有VPN都有Linux GUI客户端:ExpressVPN/NordVPN/Surfshark 有,Mullvad/VyprVPN 有但功能有限
  2. WireGuard 需要手动配置:多数VPN不提供一键 WireGuard 配置
  3. DNS 防泄漏最容易被忽略:Linux DNS 系统复杂,配置不当会泄漏
  4. Kill Switch 需手动配置:不像 Windows 那样一键开启

2. 6 家主流 VPN 的 Linux 客户端对比

客户端支持总览

VPNGUI客户端CLI工具WireGuard支持OpenVPN配置发行版支持
ExpressVPN✅ expressvpn✅ (内置Lightway)Ubuntu/Debian/Fedora/Arch
NordVPN✅ nordvpn✅ (NordLynx)Ubuntu/Debian/Fedora
SurfsharkUbuntu/Debian
Mullvad✅ mullvadUbuntu/Debian/Fedora/Arch
PIAUbuntu/Debian/Fedora
VyprVPN仅OpenVPN手动

详细评价

ExpressVPN — Linux 体验最佳

ExpressVPN 的 Linux 客户端是所有VPN中最完善的:

# 安装(Ubuntu/Debian)
sudo dpkg -i expressvpn_3.x.x_amd64.deb

# 激活
expressvpn activate

# 连接
expressvpn connect japan

# 断开
expressvpn disconnect

# 查看状态
expressvpn status
  • Lightway 协议:比 WireGuard 更轻量,Linux 上性能优秀
  • Split Tunneling:Linux 版支持应用级分流
  • Kill Switch:内置,无需手动配置
  • 自动更新:apt 仓库自动更新

详见 ExpressVPN 评测

NordVPN — 功能最全

NordVPN 的 Linux 客户端基于 NordLynx(WireGuard 改版),速度极快:

# 安装
sudo dpkg -i NordVPN_3.x.x_amd64.deb

# 登录
nordvpn login

# 连接(NordLynx/WireGuard)
nordvpn connect japan

# 开启 Kill Switch
nordvpn set killswitch on

# 开启分流
nordvpn set split_tunneling on

Mullvad — 极客最爱

Mullvad 的 Linux 客户端开源,支持 WireGuard 原生配置:

# 安装(添加仓库后)
sudo apt install mullvad-vpn

# 或者直接用 WireGuard 命令行(推荐)
sudo apt install wireguard
# 从 Mullvad 网站下载配置文件
sudo wg-quick up mullvad-jp1

详见 Mullvad 评测


3. WireGuard 命令行配置实战

WireGuard 是 Linux 上最推荐的 VPN 协议——速度快、内核级集成、配置简单。

3.1 安装 WireGuard

# Ubuntu / Debian
sudo apt update && sudo apt install wireguard wireguard-tools

# Fedora
sudo dnf install wireguard-tools

# Arch Linux
sudo pacman -S wireguard-tools

3.2 获取配置文件

大多数VPN提供 WireGuard 配置文件(.conf),登录VPN官网的"手动配置"页面下载。

以 Mullvad 为例:

# 下载配置文件
wget https://api.mullvad.net/www/addresses/jp-tyo-wg-001/
# 获得配置文件 mullvad-jp1.conf

3.3 配置 WireGuard

# 将配置文件放到 /etc/wireguard/
sudo cp mullvad-jp1.conf /etc/wireguard/wg0.conf

# 启动 WireGuard
sudo wg-quick up wg0

# 验证连接
sudo wg show
# 输出示例:
# interface: wg0
#   public key: xxxxxxxxxxxxxxxxxxxxxx
#   private key: (hidden)
#   listening port: 51820
#
# peer: xxxxxxxxxxxxxxxxxxxxxx
#   endpoint: 185.x.x.x:51820
#   allowed ips: 0.0.0.0/0
#   latest handshake: 2 seconds ago
#   transfer: 1.23 KiB received, 2.45 KiB sent

# 设置开机自启
sudo systemctl enable wg-quick@wg0

3.4 多节点切换

# 下载多个节点配置
sudo cp mullvad-jp1.conf /etc/wireguard/wg-jp.conf
sudo cp mullvad-us1.conf /etc/wireguard/wg-us.conf
sudo cp mullvad-hk1.conf /etc/wireguard/wg-hk.conf

# 切换节点
sudo wg-quick down wg-jp   # 断开日本
sudo wg-quick up wg-us     # 连接美国

💡 国内注意:WireGuard 在国内几乎秒封。如果你在中国,WireGuard 只能在非审查环境下使用。国内翻墙建议用 VyprVPN Chameleon 或自建 Shadowsocks/Trojan。


4. OpenVPN 命令行配置

4.1 安装 OpenVPN

# Ubuntu / Debian
sudo apt install openvpn openvpn-systemd-resolved

# Fedora
sudo dnf install openvpn

# Arch Linux
sudo pacman -S openvpn

4.2 手动连接

# 从VPN官网下载 .ovpn 配置文件
# 以 ExpressVPN 为例
sudo openvpn --config expressvpn_japan_udp.ovpn \
  --auth-user-pass credentials.txt

# 后台运行
sudo openvpn --config expressvpn_japan_udp.ovpn \
  --auth-user-pass credentials.txt \
  --daemon

4.3 NetworkManager 导入(GUI 方式)

如果你使用 GNOME/KDE 桌面环境:

# 导入 .ovpn 文件到 NetworkManager
nmcli connection import type openvpn file expressvpn_japan_udp.ovpn

# 连接
nmcli connection up expressvpn_japan_udp

# 断开
nmcli connection down expressvpn_japan_udp

4.4 多配置管理

# 将所有 .ovpn 文件放到一个目录
mkdir -p ~/vpn-configs
cp *.ovpn ~/vpn-configs/

# 列出所有配置
ls ~/vpn-configs/

# 快速切换脚本
#!/bin/bash
# vpn-connect.sh
sudo openvpn --config ~/vpn-configs/$1.ovpn \
  --auth-user-pass ~/vpn-configs/credentials.txt \
  --daemon
echo "Connected to $1"

5. Clash / sing-box 替代方案

对于国内用户,Clash 和 sing-box 是比传统VPN更实用的方案。

5.1 Clash for Linux (mihomo)

# 下载 mihomo (Clash Meta 内核)
wget https://github.com/MetaCubeX/mihomo/releases/latest/download/mihomo-linux-amd64-v1.x.x.gz
gunzip mihomo-linux-amd64-v1.x.x.gz
chmod +x mihomo-linux-amd64-v1.x.x
sudo mv mihomo-linux-amd64-v1.x.x /usr/local/bin/mihomo

# 配置文件
mkdir -p ~/.config/mihomo
cp config.yaml ~/.config/mihomo/

# 启动
mihomo -d ~/.config/mihomo

# 设置系统代理
export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890
export all_proxy=socks5://127.0.0.1:7891

5.2 sing-box

# 安装
sudo bash -c 'curl -L https://github.com/SagerNet/sing-box/releases/latest/download/sing-box-linux-amd64.tar.gz | tar xz -C /usr/local/bin --strip-components=1'

# 配置
sudo mkdir -p /etc/sing-box
sudo cp config.json /etc/sing-box/

# 运行
sudo sing-box run -c /etc/sing-box/config.json

# systemd 服务
sudo tee /etc/systemd/system/sing-box.service << 'EOF'
[Unit]
Description=sing-box
After=network.target

[Service]
Type=simple
ExecStart=/usr/local/bin/sing-box run -c /etc/sing-box/config.json
Restart=on-failure

[Install]
WantedBy=multi-user.target
EOF

sudo systemctl enable --now sing-box

💡 推荐方案:国内用户首选 sing-box + 订阅链接,配合 软路由 iKuai + Passwall 方案 实现全屋翻墙。


6. Kill Switch 配置

Linux 上的 Kill Switch 需要手动配置防火墙规则,确保 VPN 断开时不泄漏真实 IP。

6.1 iptables 方案

#!/bin/bash
# killswitch.sh — VPN Kill Switch for iptables

# VPN 接口名称
VPN_IF="wg0"

# 清除现有规则
sudo iptables -F
sudo iptables -t nat -F
sudo iptables -X

# 默认策略:拒绝所有出站
sudo iptables -P OUTPUT DROP

# 允许本地回环
sudo iptables -A OUTPUT -o lo -j ACCEPT
sudo iptables -A INPUT -i lo -j ACCEPT

# 允许 VPN 接口的所有流量
sudo iptables -A OUTPUT -o $VPN_IF -j ACCEPT
sudo iptables -A INPUT -i $VPN_IF -j ACCEPT

# 允许 VPN 服务器连接(替换为实际VPN服务器IP)
sudo iptables -A OUTPUT -o eth0 -d <VPN_SERVER_IP> -j ACCEPT
sudo iptables -A INPUT -i eth0 -s <VPN_SERVER_IP> -j ACCEPT

# 允许已建立的连接
sudo iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

echo "Kill Switch enabled on $VPN_IF"

6.2 取消 Kill Switch

#!/bin/bash
# killswitch-off.sh
sudo iptables -F
sudo iptables -t nat -F
sudo iptables -X
sudo iptables -P OUTPUT ACCEPT
sudo iptables -P INPUT ACCEPT
sudo iptables -P FORWARD ACCEPT
echo "Kill Switch disabled"

6.3 nftables 方案(推荐)

#!/bin/bash
# killswitch-nft.sh — Kill Switch using nftables

sudo nft add table inet vpn_killswitch
sudo nft 'add chain inet vpn_killswitch output { type filter hook output priority 0; policy drop; }'
sudo nft 'add chain inet vpn_killswitch input { type filter hook input priority 0; policy drop; }'

# 允许回环
sudo nft add rule inet vpn_killswitch output oif "lo" accept
sudo nft add rule inet vpn_killswitch input iif "lo" accept

# 允许 VPN 接口
sudo nft add rule inet vpn_killswitch output oif "wg0" accept
sudo nft add rule inet vpn_killswitch input iif "wg0" accept

# 允许 VPN 服务器连接
sudo nft add rule inet vpn_killswitch output ip daddr <VPN_SERVER_IP> accept
sudo nft add rule inet vpn_killswitch input ip saddr <VPN_SERVER_IP> accept

# 允许已建立连接
sudo nft add rule inet vpn_killswitch input ct state established,related accept

详见 Kill Switch 科普


7. DNS 防泄漏配置

Linux 的 DNS 系统复杂,容易在 VPN 连接时泄漏真实 DNS 查询。

7.1 检查 DNS 泄漏

# 安装 DNS 泄漏测试工具
sudo apt install dnsutils

# 查看当前 DNS 服务器
resolvectl status
# 或
cat /etc/resolv.conf

# 在线测试
# 访问 https://dnsleaktest.com

7.2 systemd-resolved 配置

# 编辑 systemd-resolved 配置
sudo tee /etc/systemd/resolved.conf << 'EOF'
[Resolve]
DNS=10.64.0.1  # VPN 的 DNS 服务器
FallbackDNS=
DNSSEC=yes
DNSOverTLS=opportunistic
EOF

# 重启服务
sudo systemctl restart systemd-resolved

# 确认生效
resolvectl status

7.3 WireGuard DNS 配置

在 WireGuard 配置文件中指定 DNS:

# /etc/wireguard/wg0.conf
[Interface]
PrivateKey = xxxxxxxxxxxxxxxxxxxxxx
Address = 10.x.x.x/32
DNS = 10.64.0.1  # 使用 VPN 的 DNS 服务器

[Peer]
PublicKey = xxxxxxxxxxxxxxxxxxxxxx
Endpoint = vpn-server.com:51820
AllowedIPs = 0.0.0.0/0

7.4 防止 DNS 泄漏的 iptables 规则

# 只允许 VPN 接口的 DNS 查询
sudo iptables -A OUTPUT -o eth0 -p udp --dport 53 -j DROP
sudo iptables -A OUTPUT -o eth0 -p tcp --dport 53 -j DROP
sudo iptables -A OUTPUT -o wg0 -p udp --dport 53 -j ACCEPT
sudo iptables -A OUTPUT -o wg0 -p tcp --dport 53 -j ACCEPT

详见 DNS 泄漏科普


8. 推荐方案与选购建议

按使用场景推荐

场景推荐方案理由
海外Linux用户ExpressVPN (Lightway)Linux客户端最完善,速度最快
国内Linux翻墙sing-box + 订阅WireGuard秒封,需用混淆协议
极致隐私Mullvad (WireGuard)开源、审计、无邮箱注册
预算敏感PIA (WireGuard)$2.03/月,支持Linux
开发者/运维NordVPN (NordLynx)CLI工具完善,支持Kill Switch
自建方案WireGuard + 自有VPS完全控制,详见 VPN vs 代理

Linux 发行版兼容性

发行版ExpressVPNNordVPNSurfsharkMullvadPIAsing-box
Ubuntu 22.04/24.04
Debian 12
Fedora 39/40⚠️
Arch Linux⚠️ (AUR)⚠️ (AUR)⚠️
CentOS/RHEL 9⚠️⚠️⚠️

9. 常见问题排查

Q: WireGuard 连接后无法上网

# 检查配置
sudo wg show

# 检查路由表
ip route show

# 检查 DNS
resolvectl status

# 常见原因:AllowedIPs 未设为 0.0.0.0/0
# 修复:确保 [Peer] 中 AllowedIPs = 0.0.0.0/0

Q: OpenVPN 连接后 DNS 不工作

# 安装 openvpn-systemd-resolved
sudo apt install openvpn-systemd-resolved

# 在 .ovpn 文件中添加
echo "script-security 2" >> config.ovpn
echo "up /etc/openvpn/update-resolv-conf" >> config.ovpn
echo "down /etc/openvpn/update-resolv-conf" >> config.ovpn

Q: Clash 启动后浏览器不走代理

# 检查环境变量
echo $http_proxy
echo $https_proxy

# 如果为空,手动设置
export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890

# 永久生效:写入 ~/.bashrc 或 ~/.zshrc
echo 'export http_proxy=http://127.0.0.1:7890' >> ~/.bashrc
echo 'export https_proxy=http://127.0.0.1:7890' >> ~/.bashrc

Q: Kill Switch 启用后完全断网

# 紧急关闭 Kill Switch
sudo iptables -F
sudo iptables -P OUTPUT ACCEPT
sudo iptables -P INPUT ACCEPT
sudo iptables -P FORWARD ACCEPT

# 或运行之前写的关闭脚本
sudo ./killswitch-off.sh

总结

Linux 平台的 VPN 配置虽然比 Windows/Mac 复杂,但提供了无与伦比的控制力。总结建议:

  1. 海外用户:ExpressVPN Linux 客户端 + Lightway 协议,开箱即用
  2. 国内用户:sing-box + 订阅链接,WireGuard 在国内不可用
  3. 隐私极客:Mullvad + WireGuard 命令行 + iptables Kill Switch
  4. 自建方案:WireGuard + 自有 VPS,完全掌控

🔧 小易点评:Linux 翻墙的核心不是选哪个VPN,而是选对协议——海外用 WireGuard,国内用 sing-box/Clash。协议选对了,剩下的都是配置问题。

需要跨平台方案?查看我们的 Windows VPN 指南Mac VPN 指南