文章最后更新时间为:2021 年 06 月 04 日 09:37:07 Loading... ## 准备 ## 一个有公网IP的服务器(国内外皆可) 客户端 ## frp脚本 ## frp脚本下载:https://github.com/fatedier/frp/releases/ ![选择合适版本下载][1] 选择合适的版本下载. ## 服务器配置 ## 下载脚本 > wget https://github.com/fatedier/frp/releases/download/v0.35.1/frp_0.35.1_linux_386.tar.gz 解压 > tar zxvf frp_0.35.1_linux_386.tar.gz 进入frp目录 > cd frp_0.35.1_linux_386 ![ls查看目录下的文件][2] 这里服务端,需要用到`frps`,`frps.ini`,`systemd`(其他的删除也行) 这里需要配置`frps.ini`这个配置文件 `vim frps.ini`打开文件 #[必须]标识头 [common] #[必须]服务器IP(0.0.0.0为服务器全局所有IP可用,假如你的服务器有多个IP则可以这样做,或者填写为指定其中的一个服务器IP,支持IPV6.) bind_addr = 0.0.0.0 #[必须]FRP通讯端口(用于和客户端内网穿透传输数据的端口) bind_port = 7000 #用于KCP协议UDP通讯端口(也可以和“bind_port”共用同一端口,如果没有设置,则kcp在frps中被禁用) kcp_bind_port = 7000 #UDP通讯端口(以帮助使UDP打洞穿透NAT) bind_udp_port = 7001 #[必须]连接认证密钥-特权模式(客户端连接到本服务端的登录验证密钥) privilege_token = www.roaing.com #如果你想支持http,必须指定http端口监听 vhost_http_port = 80 #如果你想支持https,必须指定https端口监听 vhost_https_port = 443 #限制只能使用服务端的指定端口(只允许客户端绑定你列出的端口,如果你什么都不设置的话,不会有任何限制。可自定义!开放这些端口,给客户端使用,包括tcp、udp、kcp、) privilege_allow_ports = 2000-3000,3001,3003,4000-50000 #自定义二级域名(通过在 frps 的配置文件中配置 subdomain_host,就可以启用该特性。之后在 frpc 的 http、https 类型的代理中可以不配置 custom_domains,而是配置一个 subdomain 参数。只需要将 *.{subdomain_host} 解析到 frps 所在服务器。之后用户可以通过 subdomain 自行指定自己的 web 服务所需要使用的二级域名,通过 {subdomain}.{subdomain_host} 来访问自己的 web 服务。) subdomain_host = frps.com #每个内网穿透服务限制最大连接池上限(每个内网穿透可以创建的连接池上限,避免大量资源占用) max_pool_count = 5 #如果使用tcp流复用,默认值为true(不开启则,false客户端和服务器端之间的连接支持多路复用,不再需要为每一个用户请求创建一个连接,使连接建立的延迟降低,并且避免了大量文件描述符的占用,使 frp 可以承载更高的并发数。) tcp_mux=true #心跳配置,不建议修改,默认值是90 heartbeat_timeout = 90 #客户端与服务端时间相差验证(假如客户端设备的时间和服务端的时间相差大于设定值,那么拒绝客户端连接。如果设置为0,则不验证时间,默认值为900秒,可自定义。) authentication_timeout = 900 #绑定服务端IP(0.0.0.0为服务器全局所有IP可用,假如你的服务器有多个IP则可以这样做,或者填写为指定其中的一个服务器IP,支持IPV6.) dashboard_addr = 0.0.0.0 #WEB端口(访问WEB服务端IP:端口) dashboard_port = 7500 #用户名(如果没有设置,默认值是admin) dashboard_user = admin #登录密码(如果没有设置,默认值是admin) dashboard_pwd = admin #记录日志(日志存放路径) log_file = /etc/frp/log/frps.log #日志记录类别(可选:trace, debug, info, warn, error) log_level = info #最多保存多少天日志 log_max_days = 7 根据以上注释,选择自己合适的配置使用, 这里,我的配置 #与客户端进行通信的端口 server_port = 7000 server_addr = 0.0.0.0 #用户名 user = admin #token token = admin 记得要放行这个端口 然后启动frps > ./frps -c frps.ini ## 客户端配置 ## 下载frp > wget https://github.com/fatedier/frp/releases/download/v0.35.1/frp_0.35.1_freebsd_amd64.tar.gz 解压 > tar frp_0.35.1_freebsd_amd64.tar.gz 进入frp目录 > cd frp_0.35.1_linux_amd64 这里服务端,需要用到`frpc`,`frpc.ini`,`systemd`(其他的删除也行) 这里需要配置`frpc.ini`这个配置文件 `vim frpc.ini`打开文件 # [common] 部分不可缺少 [common] # server_addr 服务器ip,必须包含IP地址 或者 域名 主机名 # 用方括号括起来,例如 "[::1]:80", "[ipv6-host]:http" 或 "[ipv6-host%zone]:80" server_addr = 0.0.0.0 server_port = 7000 # 如果您想通过 http 代理或 socks5 代理连接frps,则可以在此处或在全局环境变量中设置 http_proxy # 仅在协议为tcp时有效 # http_proxy = http:// user:passwd@192.168.1.128:8080 # http_proxy = socks5:// user:passwd@192.168.1.128:1080 # 日志文件 路径,例如./frpc.log log_file = ./frpc.log # trace, debug, info, warn, error log_level = info log_max_days = 3 # FRP 身份验证 token = 12345678 # 通过 http api 设置控制 frpc 管理员地址 admin_addr = 127.0.0.1 admin_port = 7400 admin_user = admin admin_pwd = admin # 提前建立连接,默认值为零 pool_count = 5 # 如果使用tcp流多路复用,则默认为true,它必须与 frps.ini 相同 tcp_mux = true # your proxy name will be changed to {user}.{proxy} user = your_name # 决定首次登录失败时是否退出程序,否则继续重新登录到 frps # 默认为true login_fail_exit = true # 用于连接服务器的通信协议 # 现在它支持tcp,kcp和websocket,默认为tcp protocol = tcp # 如果 tls_enable 为 true,则 frpc 将通过 tls 连接 frps tls_enable = true # specify a dns server, so frpc will use this instead of default one # dns_server = 8.8.8.8 # proxy names you want to start divided by ',' # default is empty, means all proxies # start = ssh,dns # heartbeat configure, it's not recommended to modify the default value # the default value of heartbeat_interval is 10 and heartbeat_timeout is 90 # heartbeat_interval = 30 # heartbeat_timeout = 90 # 'ssh' is the unique proxy name # if user in [common] section is not empty, it will be changed to {user}.{proxy} such as 'your_name.ssh' [ssh] # tcp | udp | http | https | stcp | xtcp, 默认:tcp type = tcp local_ip = 127.0.0.1 local_port = 22 # true 或 false,如果为 true,则将对 frps 和 frpc 之间的消息进行加密,默认为 false use_encryption = false # 如果为 true,则邮件将被压缩 use_compression = false # 远程端口 remote_port = 6001 # frps将负载均衡同一组中代理的连接 group = test_group # 可以将多个相同类型的 proxy 加入到同一个 group 中,从而实现负载均衡的功能。 group_key = 123456 # 启用后端服务的运行状况检查,它现在支持'tcp'和'http' # frpc将连接本地服务的端口以检测其健康状态 health_check_type = tcp # 检查连接超时 health_check_timeout_s = 3 # 如果连续3次失败,代理将从frps中删除 health_check_max_failed = 3 # 每 10 秒将进行一次检查 health_check_interval_s = 10 [ssh_random] type = tcp local_ip = 127.0.0.1 local_port = 22 # 如果 remote_port 为0,则 frps 将为您分配一个随机端口 remote_port = 0 # 如果要公开多个端口,请在节名称前添加“ range:”前缀 # frpc 将生成多个代理,例如'tcp_port_6010','tcp_port_6011'等。 [range:tcp_port] type = tcp local_ip = 127.0.0.1 local_port = 6010-6020,6022,6024-6028 remote_port = 6010-6020,6022,6024-6028 use_encryption = false use_compression = false [dns] type = udp local_ip = 114.114.114.114 local_port = 53 remote_port = 6002 use_encryption = false use_compression = false [range:udp_port] type = udp local_ip = 127.0.0.1 local_port = 6010-6020 remote_port = 6010-6020 use_encryption = false use_compression = false # 将您的域名解析为[server_addr],以便可以使用http://web01.yourdomain.com浏览web01、使用http://web02.yourdomain.com浏览web02 [web01] type = http local_ip = 127.0.0.1 local_port = 80 use_encryption = false use_compression = true # http用户名和密码是http协议的安全认证 # 如果未设置,则无需认证即可访问此custom_domains http_user = admin http_pwd = admin # 如果frps的域是frps.com,则可以通过URL http://test.frps.com 访问[web01]代理 subdomain = web01 #custom_domains域名 custom_domains = youname.com,www.youname.com # 位置仅适用于http类型 locations = /,/pic host_header_rewrite = example.com # 带有前缀“ header_”的参数将用于更新http请求标头 header_X-From-Where = frp health_check_type = http # frpc 将向本地 http 服务发送 GET http 请求'/ status' # http 服务在返回 2xx http 响应代码时仍处于活动状态 health_check_url = /status health_check_interval_s = 10 health_check_max_failed = 3 health_check_timeout_s = 3 [web02] type = https local_ip = 127.0.0.1 local_port = 8000 use_encryption = false use_compression = false subdomain = web01 custom_domains = web02.yourdomain.com # 如果不为空,则frpc将使用代理协议将连接信息传输到您的本地服务 # v1或v2或为空 proxy_protocol_version = v2 [plugin_unix_domain_socket] type = tcp remote_port = 6003 # 如果定义了插件,则 local_ip 和 local_port 无效 # 插件将处理从 frps 获得的连接 plugin = unix_domain_socket # 插件需要前缀 “ plugin_” 的参数 plugin_unix_path = /var/run/docker.sock [plugin_http_proxy] type = tcp remote_port = 6004 plugin = http_proxy plugin_http_user = abc plugin_http_passwd = abc [plugin_socks5] type = tcp remote_port = 6005 plugin = socks5 plugin_user = abc plugin_passwd = abc [plugin_static_file] type = tcp remote_port = 6006 plugin = static_file plugin_local_path = /var/www/blog plugin_strip_prefix = static plugin_http_user = abc plugin_http_passwd = abc [plugin_https2http] type = https custom_domains = test.yourdomain.com plugin = https2http plugin_local_addr = 127.0.0.1:80 plugin_crt_path = ./server.crt plugin_key_path = ./server.key plugin_host_header_rewrite = 127.0.0.1 [secret_tcp] # 如果类型是 secret tcp ,则 remote_port 是无用的 # 想要连接本地端口的用户应使用 stcp 代理部署另一个 frpc,并且角色为 visitor type = stcp # 用于访客身份验证的sk sk = abcdefg local_ip = 127.0.0.1 local_port = 22 use_encryption = false use_compression = false # 在stcp服务器和stcp访客中,frpc的用户应相同 [secret_tcp_visitor] # frpc角色访问者-> frps-> frpc角色服务器 role = visitor type = stcp # 您要访问的服务器名称 server_name = secret_tcp sk = abcdefg # 将此地址连接到访客stcp服务器 bind_addr = 127.0.0.1 bind_port = 9000 use_encryption = false use_compression = false [p2p_tcp] type = xtcp sk = abcdefg local_ip = 127.0.0.1 local_port = 22 use_encryption = false use_compression = false [p2p_tcp_visitor] role = visitor type = xtcp server_name = p2p_tcp sk = abcdefg bind_addr = 127.0.0.1 bind_port = 9001 use_encryption = false use_compression = false 根据以上注释,选择自己合适的配置使用, 这里,我的配置(我配置的是ssh) [common] server_addr = xx.xx.xx.xx(服务器IP) server_port = 7000 privilege_token = admin user = admin [ssh] type = tcp local_ip = 127.0.0.1 local_port = 22 remote_port = 6000 记得要把服务端6000端口也放行 启动frpc > ./frpc -c frpc.ini 连接成功的服务端 ![服务端连接成功][3] 连接成功的客户端 ![客户端连接成功][4] 尝试连接frp穿透后的ssh ![连接成功][5] 连接成功 [1]: https://gitee.com/r3387/wenyu/raw/master/%E6%90%AD%E5%BB%BAfrp%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F/1.PNG [2]: https://gitee.com/r3387/wenyu/raw/master/%E6%90%AD%E5%BB%BAfrp%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F/2.PNG [3]: https://gitee.com/r3387/wenyu/raw/master/%E6%90%AD%E5%BB%BAfrp%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F/frps.PNG [4]: https://gitee.com/r3387/wenyu/raw/master/%E6%90%AD%E5%BB%BAfrp%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F/frpc.PNG [5]: https://gitee.com/r3387/wenyu/raw/master/%E6%90%AD%E5%BB%BAfrp%E5%86%85%E7%BD%91%E7%A9%BF%E9%80%8F/ljcg.PNG Last modification:June 4, 2021 © Allow specification reprint Support Appreciate the author Like 0 如果觉得我的文章对你有用,请随意赞赏