[Frp内网穿透] 搭建教程

为了便于交流共同学习,博主QQ群242629020stm32-MCU认认真真交流群) 欢迎批评指导!!!电梯:https://jq.qq.com/?_wv=1027&k=5n1AfYq

参考:http://koolshare.cn/thread-65379-1-1.html

官方说明书:https://github.com/fatedier/frp/blob/master/README_zh.md#%E9%80%9A%E8%BF%87-ssh-%E8%AE%BF%E9%97%AE%E5%85%AC%E5%8F%B8%E5%86%85%E7%BD%91%E6%9C%BA%E5%99%A8

本处高能:因Frp作者更换新的模块,导致Frp v0.18.0与之前的版本不兼容,如果升级请服务器端同步升级。升级命令:

wget --no-check-certificate https://raw.githubusercontent.com/clangcn/onekey-install-shell/master/frps/install-frps.sh -O ./install-frps.sh
bash install-frps.sh update

frp 是一个高性能的反向代理应用,可以帮助您轻松地进行内网穿透,对外网提供服务,支持 tcp, http, https 等协议类型,并且 web 服务支持根据域名进行路由转发。

已测试过的平台:

CentOS 6 32/64bit
CentOS 7 32/64bit
Debian 6 32/64bit
Debian 7 32/64bit
Debian 8 32/64bit
Ubuntu 14 32/64bit

一、安装命令这个命令是在你自己的服务器上运行的!是在你自己的服务器上运行的!是在你自己的服务器上运行的!不是在路由器里运行的!不是在路由器里运行的!不是在路由器里运行的! 

wget --no-check-certificate https://raw.githubusercontent.com/clangcn/onekey-install-shell/master/frps/install-frps.sh -O ./install-frps.sh
chmod 700 ./install-frps.sh
./install-frps.sh install

二、更新命令

./install-frps.sh update

四、卸载命令

./install-frps.sh uninstall

五、服务器端管理命令

/etc/init.d/frps start
/etc/init.d/frps stop
/etc/init.d/frps restart
/etc/init.d/frps status
/etc/init.d/frps config
/etc/init.d/frps version

//++++++++++++++++++++++++++++++ 分割线以下是精华,百度谷歌都搜不到 ++++++++++++++++++++++++++++++++

 当我在服务端搭建完毕,使用客户端准备连接,提示我出现了:

 login to server failed: dial tcp xxx.xxx.xxx.xxx:xxxx connect: no route to host

我确保此时的服务端已经运行。但是相应的端口却一直没有打开。我使用的是centos,我忽然之间想起来这应该是防火墙的锅!!!

然后我使用命令把防火墙关闭

/etc/init.d/iptables stop

然后客户端现象果然有所变化,提示我

authorization failed

[control.go:113] login to server failed: authorization failed
authorization failed

一同百度谷歌,得知和2个问题有关:

说明书中……

身份验证

从 v0.10.0 版本开始,所有 proxy 配置全部放在客户端(也就是之前版本的特权模式),服务端和客户端的 common 配置中的 token 参数一致则身份验证通过。

需要注意的是 frpc 所在机器和 frps 所在机器的时间相差不能超过 15 分钟,因为时间戳会被用于加密验证中,防止报文被劫持后被其他人利用。

这个超时时间可以在配置文件中通过 authentication_timeout 这个参数来修改,单位为秒,默认值为 900,即 15 分钟。如果修改为 0,则 frps 将不对身份验证报文的时间戳进行超时校验。

但是并没有演示token如何设置,这里我贴一个示范:

frpc.ini

[common]
server_addr = #vps服务器IP地址
server_port = 8000
token = 123456

[ssh]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 6000




frps.ini

# [common] is integral section
[common]
# A literal address or host name for IPv6 must be enclosed
# in square brackets, as in "[::1]:80", "[ipv6-host]:http" or "[ipv6-host%zone]:80"
bind_addr = 0.0.0.0
bind_port = 5443
# udp port used for kcp protocol, it can be same with 'bind_port'
# if not set, kcp is disabled in frps
kcp_bind_port = 8000
# if you want to configure or reload frps by dashboard, dashboard_port must be set
dashboard_port = 6443
# dashboard assets directory(only for debug mode)
dashboard_user = admin
dashboard_pwd = Wmol2gC5
# assets_dir = ./static
vhost_http_port = 80
vhost_https_port = 443
# console or real logFile path like ./frps.log
log_file = ./frps.log
# debug, info, warn, error
log_level = info
log_max_days = 3
# auth token
token = zhcjFTGM4jLINl9i
# only allow frpc to bind ports you list, if you set nothing, there won't be any limit
#allow_ports = 1-65535
# pool_count in each proxy will change to max_pool_count if they exceed the maximum value
max_pool_count = 50
# if tcp stream multiplexing is used, default is true
tcp_mux = true
#my tyn add
authentication_timeout = 900
token = 123456

将2个文件的token对应起来就可以解决这个问题了。

最后将服务端和客户端都启动起来,通过一下命令进行ssh测试

通过 ssh 访问内网机器,假设用户名为 test:
ssh -oPort=6000 [email protected]

注意:要先启动服务端再启动客户端,否则客户端直接退出了的。

客户端后台启动命令

nohup ./frps -c ./frps.ini &

猜你喜欢

转载自blog.csdn.net/MrYarnell/article/details/82077472