黑科技-内网穿透frp
使用背景:微信开发、在家需要连接公司内网数据库、git 时,常常需要用到这个黑科技。
之前用过 ngrok ,但去国外“旅游”了一圈还是慢了些。和运维探讨了一下,他是用什么来做内网穿透的,曰:frp
frp 的作用(以下为官方说明):
1.利用处于内网或防火墙后的机器,对外网环境提供 http 或 https 服务。 2.对于 http, https 服务支持基于域名的虚拟主机,支持自定义域名绑定,使多个域名可以共用一个80端口。 3.利用处于内网或防火墙后的机器,对外网环境提供 tcp 和 udp 服务,例如在家里通过 ssh 访问处于公司内网环境内的主机。
使用方法
1.从 Release 页面下载最新版本的程序 (https://github.com/fatedier/frp/releases) 2.将 frps 及 frps.ini 放到具有公网 IP 的机器上, 并使用 screen 让 frp 在后台运行: screen -dmS frp ./frps -c ./frps.ini (要进入这个会话: screen -r frp) 3.将 frpc 及 frpc.ini 放到处于内网环境的机器上, 并使用 screen 让 frp 在后台运行: screen -dmS frp ./frpc -c ./frpc.ini (要进入这个会话: screen -r frp)
配置示例
服务端(有固定外网IP的一端)使用 frps #frps.ini配置: [common] bind_port = 5000 客户端(内网服务器,没有固定IP的)使用 frpc #frpc.ini配置: [common] server_addr = xxx.xxx.xxx.xxx server_port = 5000 [ssh] type = tcp local_ip = 127.0.0.1 local_port = 22 remote_port = 2222 [mysql] type = tcp local_ip = 192.168.44.10 local_port = 3306 remote_port = 1006 [web] type = http local_port = 80 custom_domains = www.yourdomain.com
根据以上配置示例, 做如下解释: 1.[ssh]解释: 通过公网ip:xxx.xxx.xxx.xxx的机器的代理,进入内网机器 ssh root@xxx.xxx.xxx.xxx -p 2222 2.[mysql]解释: 通过公网ip:xxx.xxx.xxx.xxx机器的代理,进入内网机器的mysql mysql -h xxx.xxx.xxx.xxx -uroot -P 1006 -proot
更详细的配置说明查看 github
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。
Thanks for your support.