目录

Ubuntu/Debian

建立VPN(虚拟专用网络)通常用于安全地连接不同网络或访问受限制的资源,以下是常见VPN类型及建立方法: 常见VPN类型 远程访问VPN 用户通过客户端连接到企业/家庭网络(如OpenVPN、L2TP/IPsec)。 站点到站点VPN 连接两个局域网(如企业分支机构间通过IPsec VPN互联)。 商业VPN服务 使用第三方...

建立VPN(虚拟专用网络)通常用于安全地连接不同网络或访问受限制的资源,以下是常见VPN类型及建立方法:


常见VPN类型

  1. 远程访问VPN

    用户通过客户端连接到企业/家庭网络(如OpenVPN、L2TP/IPsec)。

  2. 站点到站点VPN

    连接两个局域网(如企业分支机构间通过IPsec VPN互联)。

  3. 商业VPN服务

    使用第三方服务(如NordVPN、ExpressVPN)保护隐私或绕过地理限制。


自建VPN步骤(以OpenVPN为例)

准备条件

  • 一台具有公网IP的服务器(如云服务器VPS)。
  • 服务器操作系统(推荐Ubuntu/CentOS)。
  • 管理员权限(root/sudo)。

安装OpenVPN

sudo apt install openvpn easy-rsa
# CentOS
sudo yum install epel-release
sudo yum install openvpn easy-rsa

配置证书

# 复制Easy-RSA工具
make-cadir ~/openvpn-ca
cd ~/openvpn-ca
# 编辑变量文件
nano vars
# 修改KEY_COUNTRY, KEY_PROVINCE等参数
# 生成证书
source vars
./clean-all
./build-ca          # 生成CA证书
./build-key-server server  # 服务器证书
./build-key client1 # 客户端证书
./build-dh          # Diffie-Hellman密钥
openvpn --genkey --secret keys/ta.key  # TLS-auth密钥

配置服务器

# 复制配置文件模板
sudo cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz /etc/openvpn/
sudo gzip -d /etc/openvpn/server.conf.gz
# 编辑配置文件
sudo nano /etc/openvpn/server.conf

确保以下关键配置:

port 1194
proto udp
dev tun
ca /path/to/ca.crt
cert /path/to/server.crt
key /path/to/server.key
dh /path/to/dh.pem
server 10.8.0.0 255.255.255.0
push "redirect-gateway def1 bypass-dhcp"
push "dhcp-option DNS 8.8.8.8"
keepalive 10 120
tls-auth /path/to/ta.key 0
cipher AES-256-CBC
user nobody
group nogroup
persist-key
persist-tun
status openvpn-status.log
verb 3

启动OpenVPN

sudo systemctl start openvpn@server
sudo systemctl enable openvpn@server

配置客户端

  1. 将生成的客户端证书(client1.crtclient1.keyca.crtta.key)下载到本地。
  2. 创建客户端配置文件(client.ovpn):
    client
    dev tun
    proto udp
    remote your_server_ip 1194
    resolv-retry infinite
    nobind
    persist-key
    persist-tun
    ca ca.crt
    cert client1.crt
    key client1.key
    remote-cert-tls server
    tls-auth ta.key 1
    cipher AES-256-CBC
    verb 3
  3. 使用OpenVPN客户端导入配置并连接。

其他VPN方案

  • WireGuard:更轻量、高性能,适合移动设备。
    # Ubuntu安装
    sudo apt install wireguard
    wg genkey | tee privatekey | wg pubkey > publickey
  • SoftEther VPN:支持多种协议,适合企业环境。

注意事项

  1. 防火墙:确保服务器防火墙放行VPN端口(如UDP 1194)。
    sudo ufw allow 1194/udp
  2. 日志排查:若连接失败,检查/var/log/syslog或OpenVPN日志。
  3. 安全性:定期更新证书,禁用弱加密算法。

如果需要更简单的方案,可直接使用商业VPN服务或路由器内置的VPN功能(如PPTP/L2TP),如需具体场景的配置细节,请补充说明!

Ubuntu/Debian

扫描二维码推送至手机访问。

本文转载自互联网,如有侵权,联系删除。

本文链接:https://kuaimiao-m.com/post/53.html

扫描二维码手机访问

文章目录