前言

这个东西我也是突然心血来潮,然后把家里电脑系统装成了win server 2016,既然是服务器系统,里面没有点网站什么的,岂不是不像话。但是家庭宽带是没有固定的公网IP的,比如我是移动的宽带,动态公网IP。我这里有2种选择,如果你有路由器可以刷梅林固件的,那就比较方便。普通的只能用通用的教程了,肯定要比较麻烦的

准备

frp内网穿透,原理差不多是把本地局域网的IP+端口映射到别的独立IP的机子,所以你需要一台VPS,这里我是国外cloudcone的机子。系统是centos7

用过路由器(梅林)

这里提供了一键脚本(VPS上使用

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

注意:请在路由器上开启虚拟内存

Loading network version for frps, please wait...
frps Latest release file frp_0.8.1_linux_amd64.tar.gz    #此步骤会自动获取frp最新版本,自动操作,无需理会
Loading You Server IP, please wait...
You Server IP:12.12.12.12                                           #自动获取你服务器的IP地址
Please input your server setting:

Please input frps bind_port [1-65535](Default Server Port: 5443):      #输入frp提供服务的端口,用于服务器端和客户端通信
Please input frps dashboard_port [1-65535](Default dashboard_port: 6443): #输入frp的控制台服务端口,用于查看frp工作状态
Please input frps vhost_http_port [1-65535](Default vhost_http_port: 80):  #输入frp进行http穿透的http服务端口
Please input frps vhost_https_port [1-65535](Default vhost_https_port: 443): #输入frp进行https穿透的https服务端口
Please input privilege_token (Default: WEWLRgwRjIJVPx2kuqzkGnvuftPLQniq): #输入frp服务器和客户端通信的密码,默认是随机生成的
Please input frps max_pool_count [1-200](Default max_pool_count: 50):     #设置每个代理可以创建的连接池上限,默认50

##### Please select log_level #####
1: info
2: warn
3: error
4: debug
#####################################################
Enter your choice (1, 2, 3, 4 or exit. default [1]):        #设置日志等级,4个选项,默认是info


Please input frps log_max_days [1-30]
(Default log_max_days: 3 day):            #设置日志保留天数,范围是1到30天,默认保留3天。

##### Please select log_file #####
1: enable
2: disable
#####################################################
Enter your choice (1, 2 or exit. default [1]):      #设置是否开启日志记录,默认开启,开启后日志等级及保留天数生效,否则等级和保留天数无效

检查你的输入

============== Check your input ==============
You Server IP   : 12.12.12.12
Bind port       : 5443
Dashboard port  : 6443
vhost http port : 80
vhost https port: 443
Privilege token : WEWLRgwRjIJVPx2kuqzkGnvuftPLQniq
Max Pool count  : 50
Log level       : info
Log max days    : 3
Log file        : enable
==============================================

安装结束后显示:

Congratulations, frps install completed!
==============================================
You Server IP   : 12.12.12.12
Bind port       : 5443
Dashboard port  : 6443
vhost http port : 80
vhost https port: 443
Privilege token : WEWLRgwRjIJVPx2kuqzkGnvuftPLQniq
Max Pool count  : 50
Log level       : info
Log max days    : 3
Log file        : enable           #  将上面信息添加到你的路由器frp穿透插件中吧
==============================================
frps Dashboard: http://12.12.12.12:6443/   #  这个是frp控制台访问地址
==============================================

更新命令

./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

注:以上图片来自koolshare论坛【填坑完毕】内网穿透利器Frp一键安装脚本及设置教程 下面配置图片于上面的监听端口不同 80换成8080,443换成了8443,在这里提醒一下,配置VPS的时候,监听80或者433 的时候如果提示端口被占用就用8080,8443

路由器端配置:

092323ty33ye3qjg4qj0na.png

创建网站

在winserver 创建一个网站,记得开放防火墙
201810010843441.png
然后在路由器上设置
201810010847062.png

域名解析

在你的域名提供商哪里解析域名 iP填写vps的IP

通用教程

数据准备

  • 公网IP: X.X.X.X(VPS)
  • 内网IP: 192.168.1.101
  • 映射到公网的域名:xxx.com
    VPS是Linux系统,本地是win

服务器端

1.文件下载

VPS作为frp服务端(frps),首先去项目地址的releases页面下载与服务端系统匹配的文件并解压,并且可以删除客户端相关的文件(frpc文件夹,frpc.ini,frpc_full.ini)
20181003152340.png
注意自己的架构GitHub地址

2.编辑配置文件

编辑frps.ini为以下内容:

[common]
bind_port = 7000
vhost_http_port = 8080

bind_port为客户端与服务端进行通信的端口,vhost_http_port为服务端http服务的端口。其它更丰富的配置可参考frps_full.ini和项目帮助文档。

3.启动服务端

进行到解压后的frp目录,然后通过./frps -c frps.ini命令即可启动服务端,如下图所示:
5990755-c6fec2ea7352f900.jpg

4.设置开机启动和后台运行

上一步中的frps占据了整个命令窗口,所以接下来要考虑如何让它在后台运行并且开机自启:
首先通过vi /etc/systemd/system/frps.service命令新建文件并写入以下内容:

[Unit]
Description=frps daemon
After=syslog.target  network.target
Wants=network.target

[Service]
Type=simple
ExecStart=/usr/frp/frp_0.16.0_linux_386/frps -c /usr/frp/frp_0.16.0_linux_386/frps.ini
Restart= always
RestartSec=1min

[Install]
WantedBy=multi-user.target

注意ExecStart中要配置成自己的路径.
然后使用systemctl start frps即可启动frps, 用systemctl enable frps即可将frps设置为开机启动。

客户端配置

1.文件下载

具有内网IP的电脑将作为客户端(frpc), 本文中客户端使用的是win64位系统,所以在releases页面下载frp_0.16.0_windows_amd64.zip解压,删除与服务端相关的文件(frps文件夹,frps.ini,frps_full.ini)

2.编辑配置文件

编辑frpc.ini为以下内容:

[common]
server_addr = X.X.X.X
server_port = 7000

[RDP]
type = tcp
local_ip = 0.0.0.0
local_port = 3389
remote_port = 6000

[web]
type = http
local_port = 8080
custom_domains = xxx.com

注意sever_addr配置为公网电脑的IP,server_port与frps.ini中的bind_port一致。RDP为远程桌面的配置,web为http通信的配置。web中的custom_domains为绑定到公网IP的域名。

3.启动服务端

双击frpc.exe或者用命令 frpc -c frpc.ini即可启动客户端,如下图所示:
5990755-1f2b2eef51c39f56.jpg
随后我们就可以在服务端的命令窗口看到客户端的连接信息,如下所示:
5990755-3473d1e00cf2262f.jpg

4.设置开机启动和后台运行

同样的道理,我们也需要对客户端设置后台运行和开机自启。借助 winsw 工具可以将frpc注册为windows系统中的服务。
下载winsw最新版,为了方便将其重命名为winsw.exe, 将该文件和frpc.exe放在一起,然后新建winsw.xml写入以下内容:

<service>
    <id>frp</id>
    <name>frp</name>
    <description>用frp发布本地电脑网站到外网</description>
    <executable>frpc</executable>
    <arguments>-c frpc.ini</arguments>
    <logmode>reset</logmode>
</service>

然后使用winsw installfrpc start命令即可将frpc安装为系统服务。
win+r后通过services.msc进入到服务列表页面找到frp服务。
5990755-e2077fe9512c8ca6.jpg
为了确保frpc在连接失败后自动尝试重新连接,在恢复tap页进行如下设置:
5990755-87c0941ef5c495fc.jpg
通用教程来自简书-zAcamy丶

最后修改:2022 年 04 月 18 日
感谢您的支持