Ubuntu Server上OpenVPN搭建笔记

来源:互联网 发布:av去码软件 编辑:程序博客网 时间:2024/06/05 19:51

参考官方Guide:
https://help.ubuntu.com/lts/serverguide/openvpn.html

大致步骤如下:

  1. 服务器端
    1. 安装openvpneasy-rsa
    2. 构建根证书CA,获得ca.crt
    3. 使用构建的CA为服务器创建证书,获得myservername.crtmyservername.key
    4. 创建Diffie Hellman参数,获得dh2048.pem
    5. 使用构建的CA为客户端创建证书,获得client.crtclient.key
    6. 使用安全手段将ca.crtclient.crt、client.key移动至客户端待用
    7. 使用/usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz作为模板来配置服务器端的server.conf
    8. 编辑/etc/sysctl.conf取消注释#net.ipv4.ip_forward=1后使用sudo sysctl -p /etc/sysctl.conf重启sysctl启动IP forwarding
    9. 启动(或重启)openVPN服务:sudo service openvpn startsudo service openvpn restart
    10. ifconfig tun0检查tun0
  2. 客户端
    1. 根据平台安装客户端
      • sudo apt-get install openvpn
      • Linux Network-Manager GUI for OpenVPN
      • Tunnelblick for Mac
      • OpenVPN with GUI for Win 7
      • OpenVPN for openWRT
    2. 使用/usr/share/doc/openvpn/example/sample-config-files/client.conf作为模板来配置客户端client.conf
    3. 使用客户端的配置连接服务器

官方Guide没有的特别注意项:

  • server.conf中启用tls-auth ta.key 0,在client.conf中启用tls-auth ta.key 1,使用openvpn --genkey --secret ta.key生成ta.key
  • 如果多人使用用一张客户端证书登陆的话,启用server.conf中的duplicate-cn
  • server.conf中配置push路由,让登陆的客户端能够经由服务器的路由访问:

    push "route 10.8.0.0 255.255.255.0"push "route 192.168.1.0 255.255.255.0"push "route 0.0.0.0 0.0.0.0"
  • server.conf中启用push "redirect-getway def1 bypass-dhcp",客户端将只经由服务器访问网络。

  • windows客户端的client.conf中,需要配置dev-node "控制面板-网络中的本地链接名"
  • Ubuntu Server中
    • ufw allow openvpn开启防火墙允许openvpn
    • ufw default allow routed开启防火墙允许routed路由
    • ufw status verbose检查防火墙状态
    • ufw enable启用防火墙,ufw disable关闭防火墙
0 0
原创粉丝点击