[关闭]
@GEEKO 2018-12-19T06:01:30.000000Z 字数 9499 阅读 1231

FRP搭建内网穿透

frp


简介

frp是啥

frp 是一个可用于内网穿透的高性能的反向代理应用,支持 tcp, udp, http, https 协议。
此处输入图片的描述

frp 的作用

利用处于内网或防火墙后的机器,对外网环境提供 http 或 https 服务。
对于 http, https 服务支持基于域名的虚拟主机,支持自定义域名绑定,使多个域名可以共用一个80端口。
利用处于内网或防火墙后的机器,对外网环境提供 tcp 和 udp 服务,例如在家里通过 ssh 访问处于公司内网环境内的主机。

免费FRP服务器

服务器是0.20.0版本,请使用相同版本客户端,支持UDP打洞直连穿透,免费服务器仅供测试,安全问题自己掂量
如果有需要内网穿透的,可以联系我,我自己服务器有搭建对应的FRP服务端
连接地址为:frpzj.kskxs.com:7000
特权认证密码为:frp888
免费多级域名格式 *.frpzj.kskxs.com 支持8081端口的域名绑定映射方式
将域名CNAME解析至 frpzj.kskxs.com 即可绑定自己的域名
此服务器开放50000-60000范围的TCP、UDP端口映射
隧道状态查询:frpzj.kskxs.com:7500
查询帐号和密码均为:admin

FRP相关站点资料

GITHUB: https://github.com/fatedie
官网: https://diannaobos.com/frp

本次安装环境

安装环境:
服务器:阿里云 centos 7
客户端:ubuntu 16

安装配置

服务端安装

  1. # 手动配置frps.ini文件需要注意 = 前后都有空格,如果没有空格,则会配置不生效
  2. [common]
  3. bind_port=7000 # 客户端连接服务端的对外端口
  4. dashboard_port = 7500 # 服务端管理页面对外端口
  5. token = 123456 # 这里是客户端连接授权的凭证
  6. # dashboard 用户名密码,默认都为 admin
  7. dashboard_user = admin # 服务端管理页面登录账号
  8. dashboard_pwd = admin # 服务端管理页面登录密码
  9. vhost_http_port = 80 # http 开放80端口
  10. vhost_https_port = 443 # https 开放443端口
  11. # frps 服务端日志配置
  12. log_file=/home/jesn/tool/frp/logs/frps.log
  13. log_level=info
  14. log_max_day=7

客户端配置

  1. [common]
  2. server_addr = 100.100.100.100 # 服务器公网IP
  3. server_port = 7001 # FRPS对外接口端口
  4. token = 123456 # 服务器token凭证
  5. log_file = frpc.log
  6. log_level = info
  7. log_max_days = 3
  8. # ssh 配置
  9. [ssh]
  10. type = tcp
  11. local_ip = 127.0.0.1
  12. local_port = 22
  13. remote_port = 7022

Web配置HTTP

  1. vhost_http_port = 80 # http 开放80端口
  2. vhost_https_port = 443 # https 开放443端口
  1. [web]
  2. type = http # 类型为http
  3. local_port = 80 # 本地端口
  4. custom_domains = www.yourdomain.com # 你的域名

完整的frps和frpc的配置

frps 完整配置

  1. # [common] is integral section
  2. [common]
  3. # A literal address or host name for IPv6 must be enclosed
  4. # in square brackets, as in "[::1]:80", "[ipv6-host]:http" or "[ipv6-host%zone]:80"
  5. bind_addr = 0.0.0.0
  6. bind_port = 7000
  7. # udp port to help make udp hole to penetrate nat
  8. bind_udp_port = 7001
  9. # udp port used for kcp protocol, it can be same with 'bind_port'
  10. # if not set, kcp is disabled in frps
  11. kcp_bind_port = 7000
  12. # specify which address proxy will listen for, default value is same with bind_addr
  13. # proxy_bind_addr = 127.0.0.1
  14. # if you want to support virtual host, you must set the http port for listening (optional)
  15. # Note: http port and https port can be same with bind_port
  16. vhost_http_port = 80
  17. vhost_https_port = 443
  18. # response header timeout(seconds) for vhost http server, default is 60s
  19. # vhost_http_timeout = 60
  20. # set dashboard_addr and dashboard_port to view dashboard of frps
  21. # dashboard_addr's default value is same with bind_addr
  22. # dashboard is available only if dashboard_port is set
  23. dashboard_addr = 0.0.0.0
  24. dashboard_port = 7500
  25. # dashboard user and passwd for basic auth protect, if not set, both default value is admin
  26. dashboard_user = admin
  27. dashboard_pwd = admin
  28. # dashboard assets directory(only for debug mode)
  29. # assets_dir = ./static
  30. # console or real logFile path like ./frps.log
  31. log_file = ./frps.log
  32. # trace, debug, info, warn, error
  33. log_level = info
  34. log_max_days = 3
  35. # auth token
  36. token = 12345678
  37. # heartbeat configure, it's not recommended to modify the default value
  38. # the default value of heartbeat_timeout is 90
  39. # heartbeat_timeout = 90
  40. # only allow frpc to bind ports you list, if you set nothing, there won't be any limit
  41. allow_ports = 2000-3000,3001,3003,4000-50000
  42. # pool_count in each proxy will change to max_pool_count if they exceed the maximum value
  43. max_pool_count = 5
  44. # max ports can be used for each client, default value is 0 means no limit
  45. max_ports_per_client = 0
  46. # authentication_timeout means the timeout interval (seconds) when the frpc connects frps
  47. # if authentication_timeout is zero, the time is not verified, default is 900s
  48. authentication_timeout = 900
  49. # if subdomain_host is not empty, you can set subdomain when type is http or https in frpc's configure file
  50. # when subdomain is test, the host used by routing is test.frps.com
  51. subdomain_host = frps.com
  52. # if tcp stream multiplexing is used, default is true
  53. tcp_mux = true

frpc完整配置

  1. # [common] is integral section
  2. [common]
  3. # A literal address or host name for IPv6 must be enclosed
  4. # in square brackets, as in "[::1]:80", "[ipv6-host]:http" or "[ipv6-host%zone]:80"
  5. server_addr = 0.0.0.0
  6. server_port = 7000
  7. # if you want to connect frps by http proxy or socks5 proxy, you can set http_proxy here or in global environment variables
  8. # it only works when protocol is tcp
  9. # http_proxy = http://user:passwd@192.168.1.128:8080
  10. # http_proxy = socks5://user:passwd@192.168.1.128:1080
  11. # console or real logFile path like ./frpc.log
  12. log_file = ./frpc.log
  13. # trace, debug, info, warn, error
  14. log_level = info
  15. log_max_days = 3
  16. # for authentication
  17. token = 12345678
  18. # set admin address for control frpc's action by http api such as reload
  19. admin_addr = 127.0.0.1
  20. admin_port = 7400
  21. admin_user = admin
  22. admin_pwd = admin
  23. # connections will be established in advance, default value is zero
  24. pool_count = 5
  25. # if tcp stream multiplexing is used, default is true, it must be same with frps
  26. tcp_mux = true
  27. # your proxy name will be changed to {user}.{proxy}
  28. user = your_name
  29. # decide if exit program when first login failed, otherwise continuous relogin to frps
  30. # default is true
  31. login_fail_exit = true
  32. # communication protocol used to connect to server
  33. # now it supports tcp and kcp and websocket, default is tcp
  34. protocol = tcp
  35. # specify a dns server, so frpc will use this instead of default one
  36. # dns_server = 8.8.8.8
  37. # proxy names you want to start divided by ','
  38. # default is empty, means all proxies
  39. # start = ssh,dns
  40. # heartbeat configure, it's not recommended to modify the default value
  41. # the default value of heartbeat_interval is 10 and heartbeat_timeout is 90
  42. # heartbeat_interval = 30
  43. # heartbeat_timeout = 90
  44. # 'ssh' is the unique proxy name
  45. # if user in [common] section is not empty, it will be changed to {user}.{proxy} such as 'your_name.ssh'
  46. [ssh]
  47. # tcp | udp | http | https | stcp | xtcp, default is tcp
  48. type = tcp
  49. local_ip = 127.0.0.1
  50. local_port = 22
  51. # true or false, if true, messages between frps and frpc will be encrypted, default is false
  52. use_encryption = false
  53. # if true, message will be compressed
  54. use_compression = false
  55. # remote port listen by frps
  56. remote_port = 6001
  57. # frps will load balancing connections for proxies in same group
  58. group = test_group
  59. # group should have same group key
  60. group_key = 123456
  61. # enable health check for the backend service, it support 'tcp' and 'http' now
  62. # frpc will connect local service's port to detect it's healthy status
  63. health_check_type = tcp
  64. health_check_interval_s = 10
  65. health_check_max_failed = 1
  66. health_check_timeout_s = 3
  67. [ssh_random]
  68. type = tcp
  69. local_ip = 127.0.0.1
  70. local_port = 22
  71. # if remote_port is 0, frps will assign a random port for you
  72. remote_port = 0
  73. # if you want to expose multiple ports, add 'range:' prefix to the section name
  74. # frpc will generate multiple proxies such as 'tcp_port_6010', 'tcp_port_6011' and so on.
  75. [range:tcp_port]
  76. type = tcp
  77. local_ip = 127.0.0.1
  78. local_port = 6010-6020,6022,6024-6028
  79. remote_port = 6010-6020,6022,6024-6028
  80. use_encryption = false
  81. use_compression = false
  82. [dns]
  83. type = udp
  84. local_ip = 114.114.114.114
  85. local_port = 53
  86. remote_port = 6002
  87. use_encryption = false
  88. use_compression = false
  89. [range:udp_port]
  90. type = udp
  91. local_ip = 127.0.0.1
  92. local_port = 6010-6020
  93. remote_port = 6010-6020
  94. use_encryption = false
  95. use_compression = false
  96. # Resolve your domain names to [server_addr] so you can use http://web01.yourdomain.com to browse web01 and http://web02.yourdomain.com to browse web02
  97. [web01]
  98. type = http
  99. local_ip = 127.0.0.1
  100. local_port = 80
  101. use_encryption = false
  102. use_compression = true
  103. # http username and password are safety certification for http protocol
  104. # if not set, you can access this custom_domains without certification
  105. http_user = admin
  106. http_pwd = admin
  107. # if domain for frps is frps.com, then you can access [web01] proxy by URL http://test.frps.com
  108. subdomain = web01
  109. custom_domains = web02.yourdomain.com
  110. # locations is only available for http type
  111. locations = /,/pic
  112. host_header_rewrite = example.com
  113. # params with prefix "header_" will be used to update http request headers
  114. header_X-From-Where = frp
  115. health_check_type = http
  116. # frpc will send a GET http request '/status' to local http service
  117. # http service is alive when it return 2xx http response code
  118. health_check_url = /status
  119. health_check_interval_s = 10
  120. [web02]
  121. type = https
  122. local_ip = 127.0.0.1
  123. local_port = 8000
  124. use_encryption = false
  125. use_compression = false
  126. subdomain = web01
  127. custom_domains = web02.yourdomain.com
  128. [plugin_unix_domain_socket]
  129. type = tcp
  130. remote_port = 6003
  131. # if plugin is defined, local_ip and local_port is useless
  132. # plugin will handle connections got from frps
  133. plugin = unix_domain_socket
  134. # params with prefix "plugin_" that plugin needed
  135. plugin_unix_path = /var/run/docker.sock
  136. [plugin_http_proxy]
  137. type = tcp
  138. remote_port = 6004
  139. plugin = http_proxy
  140. plugin_http_user = abc
  141. plugin_http_passwd = abc
  142. [plugin_socks5]
  143. type = tcp
  144. remote_port = 6005
  145. plugin = socks5
  146. plugin_user = abc
  147. plugin_passwd = abc
  148. [plugin_static_file]
  149. type = tcp
  150. remote_port = 6006
  151. plugin = static_file
  152. plugin_local_path = /var/www/blog
  153. plugin_strip_prefix = static
  154. plugin_http_user = abc
  155. plugin_http_passwd = abc
  156. [secret_tcp]
  157. # If the type is secret tcp, remote_port is useless
  158. # Who want to connect local port should deploy another frpc with stcp proxy and role is visitor
  159. type = stcp
  160. # sk used for authentication for visitors
  161. sk = abcdefg
  162. local_ip = 127.0.0.1
  163. local_port = 22
  164. use_encryption = false
  165. use_compression = false
  166. # user of frpc should be same in both stcp server and stcp visitor
  167. [secret_tcp_visitor]
  168. # frpc role visitor -> frps -> frpc role server
  169. role = visitor
  170. type = stcp
  171. # the server name you want to visitor
  172. server_name = secret_tcp
  173. sk = abcdefg
  174. # connect this address to visitor stcp server
  175. bind_addr = 127.0.0.1
  176. bind_port = 9000
  177. use_encryption = false
  178. use_compression = false
  179. [p2p_tcp]
  180. type = xtcp
  181. sk = abcdefg
  182. local_ip = 127.0.0.1
  183. local_port = 22
  184. use_encryption = false
  185. use_compression = false
  186. [p2p_tcp_visitor]
  187. role = visitor
  188. type = xtcp
  189. server_name = p2p_tcp
  190. sk = abcdefg
  191. bind_addr = 127.0.0.1
  192. bind_port = 9001
  193. use_encryption = false
  194. use_compression = false

问题vS解决方案

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注