想咗嚮右赱 2019-06-28
sudo yum update -y安装所需环境
sudo yum install epel-release -y安装openvpn,以及wget网络下载工具
sudo yum install -y openvpn wget下载easy-rsa秘钥生成工具
wget -O /tmp/easyrsa https://github.com/OpenVPN/easy-rsa-old/archive/2.3.3.tar.gz解压easy-rsa秘钥生成工具
tar xfz /tmp/easyrsa新建一个easy-rsa 文件夹
sudo mkdir /etc/openvpn/easy-rsa将解压的文件都拷贝到自建的easy-rsa中
sudo cp -rf easy-rsa-old-2.3.3/easy-rsa/2.0/* /etc/openvpn/easy-rsa给sammy用户授权,如果您是root可以忽略本步
sudo chown sammy /etc/openvpn/easy-rsa/
sudo cp /usr/share/doc/openvpn-2.4.4/sample/sample-config-files/server.conf /etc/openvpn使用vim(如果没有vim,可以用 yum install vim -y 来安装,也可以用vi来代替)配置server.conf文件
sudo vim /etc/openvpn/server.conf在server.conf文件中加入配置
>local 填写服务器的内网ip local xxx.xxx.xxx.xxx >配置连接方式是tcp proto tcp >连接模式tun dev tun > 配置dns push "dhcp-option DNS 223.5.5.5" push "dhcp-option DNS 223.6.6.6" >配置用户组 以及 用户 user nobody group nobody >给vpn客户机分配的地址池。最好别和openvpn部署机的内网ip在一个网段内 server 10.8.0.0 255.255.255.0 >ip绑定文件 ifconfig-pool-persist ipp.txt >设置路由 push "route 10.0.0.0 255.0.0.0" >指定ca.crt 下面会生成该文件 ca /etc/openvpn/certs/ca.crt >指定server.crt 下面会生成该文件 cert /etc/openvpn/certs/server.crt >指定server.key 下面会生成该文件 key /etc/openvpn/certs/server.key >指定dh.pem 下面会生成该文件 dh /etc/openvpn/certs/dh.pem client-to-client keepalive 10 120 comp-lzo status openvpn-status.log verb 3
sudo mkdir /etc/openvpn/easy-rsa/keys编辑vars文件
sudo nano /etc/openvpn/easy-rsa/varsvars文件中存储您自定义的一些信息,可以默认
. . . # These are the default values for fields # which will be placed in the certificate. # Don't leave any of these fields blank. export KEY_COUNTRY="US" export KEY_PROVINCE="NY" export KEY_CITY="New York" export KEY_ORG="DigitalOcean" export KEY_EMAIL="[email protected]" export [email protected] export KEY_CN=openvpn.example.com export KEY_NAME="server" export KEY_OU="Community" . . .切换到easy-rsa
cd /etc/openvpn/easy-rsa清空认证
./clean-all建立认证
./build-ca设置建立的服务器的key
./build-key-server server建立 dh协议
./build-dh将认证的文件拷贝到keys中
cd /etc/openvpn/easy-rsa/keys sudo cp dh2048.pem ca.crt server.crt server.key /etc/openvpn切换到easy-rsa并建立客户端的key
cd /etc/openvpn/easy-rsa ./build-key client拷贝openssl配置文件
cp /etc/openvpn/easy-rsa/openssl-1.0.0.cnf /etc/openvpn/easy-rsa/openssl.cnf关闭防火墙
service iptables stop开启openvpn
sudo systemctl start [email protected]查看openvpn
sudo systemctl status [email protected]关闭vpn
sudo systemctl stop [email protected]
client dev tun proto tcp remote 39.105.148.255 21205 resolv-retry infinite nobind persist-key persist-tun ca ca.crt cert client.crt key client.key user nobody group nobody comp-lzo verb 3