虎泰克博客

使用OpenVPN进行内网穿透


内网穿透方法很多,常用得有ngrok,frp,花生壳等。我选择OpenVpn主要是安全性更好点。花生壳、ngrok和frp,实现得内网穿透。知道你域名或者外网IP就能直接连到你得对应机器得端口上。 而openvpn方式有点不一样。A服务器运行server,B客户机运行client连接A服务器,C客户机运行client连接A服务器。然后B就能直接与C通信。

需求

内网穿透方法很多,常用得有ngrok,frp,花生壳等。我选择OpenVpn主要是安全性更好点。花生壳、ngrok和frp,实现得内网穿透。知道你域名或者外网IP就能直接连到你得对应机器得端口上。
而openvpn方式有点不一样。A服务器运行server,B客户机运行client连接A服务器,C客户机运行client连接A服务器。然后B就能直接与C通信。

搭建server

1
wget https://git.io/vpn -O openvpn-install.sh && bash openvpn-install.sh

一键傻瓜式,只要填入相关信息就可搭建成功。

虎bmm泰oebfg克ungf新bw闻prdx网ev版权所有,请勿未授权转载!!!

配置调整

其实任何东西都不修改的情况下,客户机直接使用生成的client.ovpn即可跑起来了。
不过这样的话。所有流量都是走的服务器上,对于我来说。只是想要B和C能通信,并不需要全局走openvpn。那么需要修改下2个东西即可。

修改server.ovpn

/etc/openvpn/server.conf注释掉这一行

1
#push "redirect-gateway def1 bypass-dhcp"


修改client.ovpn

client.ovpn注释掉这一行

1
#setenv opt block-outside-dns


结束

修改后,所有流量还是正常走本地,但是B和C可以使用openvpn分配的内网IP进行通信。至于用途,比如用ipad连上openvpn后。就可以直接访问家里PC的后台服务等等。。。。
还有其他用法。比如修改client.ovpn加入,可以强制该段走net_gateway或vpn_gateway

1
2
route 192.168.123.0 255.255.255.0 net_gateway
route 192.168.123.0 255.255.255.0 vpn_gateway




Statement: all articles / drawings reproduced on this website are for the purpose of transmitting more information and facilitating discussion, which does not mean that the website, the host and the organizer agree with their opinions or confirm the authenticity of their contents. The contents of the articles are for reference only. If the rights of the original author are violated, please contact the website administrator.

Sign in to comment

Comment list

    No data