OPEN.V.x.N官方地址
https://openvpn.net/community-resources/how-to/需求
公司网络IP不固定,每半个月网络拨号就会换一个IP地址,登陆公司的堡垒机会出现IP地址不对的状况,无法访问堡垒机。最开始的解决方案是,根据公司IP地址得出IP前8位不会产生变化,在阿里云上对端口的IP地址进行重新调整,约束IP地址的前8位。但是依然可能会出现因为IP堡垒机被黑的情况。同时,公司运维需要人员可以在故障发生时在有电脑的环境下可以快速解决问题,因为不在上班时间,IP不确定,需要登陆阿里云添加端口的IP,很麻烦。所以决定搭建一个OPENVPN,OPENVPN1194端口对外开放,运维人员用ca证书和用户密码登陆,通过OPEN.V.x.N访问公司堡垒机和其他服务器。
环境1v2G
ubuntu18.04
数据盘50G
操作本操作使用的GITHUB开源安装OPENVPN
GITHUB地址
GitHub - guoew/openvpn-install: OpenVPN road warrior installer for Debian, Ubuntu and CentOS
视用户环境已配置好
如果时间同步出现问题,建议安装NTP,
sudo apt-get update && sudo apt-get install -y gnupg2 curl software-properties-common ntp && sudo systemctl enable ntp && sudo systemctl start ntp
有显示输出表明安装成功
安装git
apt-get install git
下载软件包安装(建议规划好下载的目录)
git clone https://github.com/guoew/openvpn-install.git cd openvpn-install && bash openvpn-install.sh
运行bash openvpn-install.sh 后会出现六个交互界面
确定OPENVPN服务器监控的内网地址,即本机在内网的IP
First, provide the IPv4 address of the network interface you want OpenVPN listening to. IP address: xxxx.xxxx.xxxx.xxxx
确定OPENVPN的公网IP
This server is behind NAT. What is the public IPv4 address or hostname? Public IP address / hostname: xxxx.xxxx.xxxx.xxxx
确定连接的网络协议
Which protocol do you want for OpenVPN connections? 1) UDP (recommended) 2) TCP Protocol [1-2]: 1
确定连接开放的端口
What port do you want OpenVPN listening to? Port: 1194
确定使用的域名地址解析,即DNS
Which DNS do you want to use with the VPN? 1) Current system resolvers 2) 1.1.1.1 3) Google 4) OpenDNS 5) Verisign DNS [1-5]: 1
确定ovpn证书文件的名称(唯一)
Finally, tell me your name for the client certificate. Please, use one word only, no special characters. Client name: client
点击确定开始自动配置
Okay, that was all I needed. We are ready to set up your OpenVPN server now. Press any key to continue...
配置完成之后,在阿里云上打开对应的端口
在userfile.sh中添加账号和密码,用空格隔开,如果有多个用户换行添加
cat /etc/openvpn/userfile.sh username password
下载服务器中的配置文件为客户端做准备
/安装文件夹/client.ovpn (设置了OVPN名称,就会有一个该名称的OVPN文件) /etc/openvpn/server/ca.crt
重新运行脚本openvpn-install.sh脚本,会出现四个菜单选项(1添加、2撤销、3卸载、4退出),可根据自身实际情况应用
Looks like OpenVPN is already installed. What do you want to do? 1) Add a new user 2) Revoke an existing user 3) Remove OpenVPN 4) Exit Select an option [1-4]:
安装OPEN.V.x.N客户端
客户端安装地址
https://swupdate.openvpn.org/community/releases/openvpn-install-2.4.0-I602.exe
可自定义安装地址
安装好后在安装目录中找到config文件夹,里面会只有一个README.TXT文件
将从服务器下载的ovpn文件和ca.crt文件复制在config文件内
打开客户端点击connect,输入服务器中设置的用户名和密码,连接
客户端问题如果出现没有文件的情况,右键点击右下角运行图标,点击Import file导入从服务器下载的文件
如果是安装之后卸载过,重新安装出现之前的OPENVPN服务器的地址或者OV.x.N文件
卸载此软件,并且删除之前的安装目录
在电脑资源管理器中搜索OV.x.N文件,找到删除它
重新安装OPEN.V.x.N软件



