如何使用frp内网穿透

如何使用frp内网穿透

如何使用frp内网穿透
我们能用frp干什么
通过SSH访问LAN中的计算机
下载软件
解压软件
修改服务器端配置
修改客户端配置
frp内网穿透实战

我们能用frp干什么?
在具有公网IP地址的服务器上,将NAT或防火墙后面的任何tcp或udp服务暴露给互联网。
通过具有公共IP地址(基于名称的虚拟主机支持)的服务器将NAT或防火墙后面的任何http和https服务暴露给互联网。
通过SSH访问LAN中的计算机
下载软件
软件:frp_0.12.0_linux_amd64.tar.gz 点击下载
wget: wget https://github.com/fatedier/frp/releases/download/v0.12.0/frp_0.12.0_linux_amd64.tar.gz

因为网络问题,推荐本地方式下载,通过FTP上传到服务器端再解压

说明:

坏境准备:一台有公网IP的服务器作为服务端,只有内网的机器作为客户端
1
解压软件
命令:tar -zxvf frp_0.12.0_linux_amd64.tar.gz
1
解压后目录如下: - frpc 客户端软件 - frpc_full.ini - frpc.ini 客户端配置文件 - frps 服务端软件 - frps_full.ini - frps.ini 服务端配置文件 - LICENSE
命令:cd frp*
1
修改服务器端配置
命令1:vi frps.ini
# frps.ini
[common]
bind_port = 7000

命令2(启动服务):./frps -c ./frps.ini
修改客户端配置
命令1:vi frpc.ini
[common]
server_addr = 112...*
server_port = 7000

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

命令2(启动服务):./frpc -c ./frpc.ini
说明: - server_addr 公网IP - server_port 服务器端口 - local_port 本地要替换的端口 - remote_port 替换端口(ssh连接时候改成这个端口)
OK,快用Xshell连接试试看吧!
ssh -oPort=6000 [email protected]
frp内网穿透实战
说一千,道一万,不如撸起袖子干一干
- 场景:有公网IP得阿里云服务器一台 A
- 只有内网联想服务器主机 B
B服务器 - frpc.ini
[common]
server_addr = 114.xx.xx.xxx
server_port = 7000

通过tcp来连接SSH

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

通过tcp来连接mysql

[mysql]
type = tcp
local_port = 3306
remote_port = 3306

use_encryption = true

use_compression = true

[tomcat]

type = http

local_port = 8083

custom_domains = tomcat.xxxx1.com

remote_port =

[web]

type = http

local_port = 8083

subdomain = tomcat

通过二级域名管理tomcat

[web01]
type=http
local_ip = 127.0.0.1
local_port = 8083
custom_domains = tomcat.xxxx1.com
localhost = /

通过二级域名管理nexus

[web02]
type=http
local_ip = 127.0.0.1
local_port = 8084
custom_domains = nexus.xxxx1.com
localhost = /
A服务器 - frps.ini 服务端简单配置
[common]
bind_port = 7000

privilege_allow_ports = 8082,8083

vhost_http_port = 80
vhost_https_port = 5051

subdomain_host = xxxx1.com

subdomain_host = xxxx2.com

dashboard_port = 7500

仪表板的用户名和密码都是可选的,如果没有设置,默认是admin。

dashboard_user = admin

dashboard_pwd = admin

执行
setsid ./frps -c ./frps.ini
1
frpc.ini
将请求域名作转发处理,因为vhost_http_port=80占用了80端口,导致生产环境上得网站不能直接通过域名来访问,如果vhost_http_port不等于80则导致访问通过子域名访问内网环境都需要在url后面加上81端口。
[common]
server_addr = 127.0.0.1
server_port = 7000

[ssh]

type = tcp

local_ip = 127.0.0.1

local_port = 22

remote_port = 6000

[web]
type = http
local_port = 81
custom_domains = www.xxxx.com
[linkai]
type = http
local_port = 82
custom_domains = www.xxxx1.om
[luming]
type = http
local_port = 83
custom_domains = www.xxxx.net
执行
setsid ./frpc -c ./frpc.ini
1
杀掉进程
命令1:ps -ef |grep frpc.ini(或frps.ini)
命令2:kill -9 xxxx
1
2
实战总结
1. 如果要使用二级域名形式必须得设置了*解析,或者你要得二级域名解析
2. 服务端必须设置 vhost_http_port = 80 才能直接通过配置域名访问
3. 服务端配置vhost_http_port 不为80时候,访问路径需要加上这个替换端口
4. 如果设置了privilege_allow_ports,需要注意白名单范围,不在范围内得端口不能访问
5. setsid()调用成功后,进程成为新的会话组长和新的进程组长,并与原来的登录会话和进程组脱离。由于会话过程对控制终端的独占性,进程同时与控制终端脱离。
6. subdomain_host 设置后,无法是使用custom_domains
能力有限,还请多多指教

猜你喜欢

转载自blog.csdn.net/whereisdog/article/details/82619778