内网穿透实用指南 – Frp+NAS

概念:

  • NAS – 简单的说就是一个私有化的存储中心。(本人的nas直接丢到了出租屋,但是比较傻的出租屋的房东路由带上我的路由器有两级路由,这也是写这篇分享的由头了)
  • Frp – 一种内网穿透技术。
  • 内网穿透 – 就是通过其他公网 IP 来访问本地没有公网 IP 网络环境的一个技术。

关于其他:

  • 内网穿透技术众多,比如花生壳内网穿透、Ngrok、Frp 都是现在主流的内网穿透技术。
    但我个人认为 Frp 是目前最好用配置最简单的(经过测试)。
  • 花生壳
    配置简单方便,比较傻瓜化。但要收费。虽然也有免费版,但由于免费版的流量限制,基本上没有什么实际作用。
  • Ngrok
    发布时间相对较长,对象较为成熟的一种内网穿透技术。但由于功能的强大。配置较为繁琐。
  • Frp
    配置简单,第一次用就配置成功了。并且适用于各大主流平台设备。

基本步骤

由于 Frp 官网GitHub文档还是比较详细。我不过多做解释。

Frp 的基础架构如下,分为服务端和客户端,原理是通过一台公网服务器,做客户端代理。这样,不管你的User端有几层路由,原则上只要可以和公网通讯即可完成穿透。这就意味着你需要类似VPN一样准备一台代理服务器做穿透。这里推荐大家用腾讯云广州的CVM,速度还是比较快的。

 

服务器端配置:

登录服务器,在 Release页面 下载自己服务器对应版本 Frp

wget https://github.com/fatedier/frp/releases/download/v0.28.1/frp_0.28.1_linux_amd64.tar.gz

实例中:腾讯云用的 centos7 所以我选择 linux_amd64 64位的

使用 tar 指令解压 tar.gz 文件

tar -zxvf frp_0.12.0_linux_amd64.tar.gz

进入 frp 目录

cd frp_0.12.0_linux_amd64

删除不必要的客户端文件

rm -f frpc frpc_full.ini frpc.ini

版本不同可能稍有差异

frpc 为客户端文件
frps 为服务器端文件

配置服务器端文件

vi frps.ini

frps.ini 为服务器配置文件
编辑配置文件

[common]
bind_port = 7000
vhost_http_port = 8080
dashboard_port = 7500
dashboard_user = 用户名
dashboard_pwd = 密码
max_pool_count = 5
authentication_timeout = 900

subdomain_host = canmeng.net

[ssh]
listen_port = 6000
auth_token = 和客服端 token 对应

简单解释:

[common] 必填的
bind_port Frp 服务端口(可自定义)
vhost_http_port http 访问端口(可自定义)
dashboard_port dashboard 界面端口
dashboard_user 登录 dashboard 用户名
dashboard_pwd 登录 dashboard 密码
max_pool_count 最大连接池数量
authentication_timeout 超时验证时间
subdomain_host 自定义二级域名

[ssh]
listen_port ssh 访问端口
auth_token 用户身份认证

官方详细配置

保存上面配置文件吗,启动 frp 服务器

./frps -c ./frps.ini

需要后台运行,请看下面
服务端配置结束。

打开ip:7500 即可看到frp的 dashboard 界面

客户端配置

客户端就是您本地需要做外网服务的设备,可以是 PC、Mac、NAS、路由器、或者虚拟机里的 liunx 系统。

这篇文章主要是利用 Frp 技术访问在群晖 NAS 服务的应用。实例也是 NAS 系统。

SSH 登录群晖 NAS (群晖必须开启 ssh)

下载 Frp, 删除服务端文件。(因为和服务端配置一样,不再一一赘述。)

sudo -i // 切换 root 用户
wget https://github.com/fatedier/frp/releases/download/v0.28.1/frp_0.28.1_linux_386.tar.gz
tar -zxvf frp_0.12.0_linux_386.tar.gz
cd frp_0.12.0_linux_386
rm -f frps frps_full.ini frps.ini

编辑 frpc.ini 文件(客户端配置文件)

vi frpc.ini

编辑配置文件如下

[common]
server_addr = ip
server_port = 7000
auth_token = 和服务器端对应
pool_count = 1

[ssh]
type = tcp
local_ip = NAS 局域网ip
local_port = 22
remote_port = 6000

[nas]
type = http
local_port = 5000
subdomain = sss

[web]
type = http
local_port = 80
subdomain = web

简单解释:

[common] 必填的
server_addr 服务器端公网
server_port frp 服务端口,和服务器端 bind_port 一致
auth_token 和前面服务器端 [ssh] auth_token 一致
pool_count 连接池数量

[ssh]
type 服务类型(tcp、http、https、udp)
local_ip NAS 本地局域网内网 ip
local_port NAS 开启 ssh 服务端口号,默认 22
remote_port 服务器端 ssh 端口,和服务器端 [ssh] listen_port 配置一致

[nas] NAS 管理界面
type = http 服务类型为 http
local_port NAS 默认端口 5000
subdomain = sss 二级域名 sss.canmeng.net 访问 NAS

[web] NAS web Station 服务,没用可以不用设置
type = http 类型为 http
local_port = 80 NAS web 服务端口
subdomain = web 二级域名 web.canmeng.net

使用自定义二级域名的时候,域名 *.canmeng.net 要解析到服务器 IP,或者解析相关二级域

官方详细配置

保存,运行。(后台运行,请看下面)

./frpc -c ./frpc.ini

此时在服务端会看到”start proxy sucess”字样,即连接成功。

测试运行

ssh 测试

ssh -p 6000 user@服务器ip
user 为你登录群晖 NAS 的用户名

nas 界面

打开浏览器输入 sss.canmeng.net:8080, 显示群晖登录界面成功。

NAS web Station

打开浏览器输入 web.canmeng.net:8080, 显示页面成功。

后台运行

后台运行服务的方法有很多,这里只说一种可以在服务器端(Linux)和客户端(NAS)都可以用的 nohup指令

服务器端

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

客户端

nohup ./frpc -c ./frpc.ini &

自动启动

进入群晖控制面板 > 任务计划 > 新增 > 触发任务 > 用户定义的脚本

添加脚本

/root/frp_0.28.0_linux_386/frpc -c /root/frp/frpc.ini

注意:frp_0.28.0_linux_386 需要换成你自己的路径

 

勾选任务,点击保存即可

总结

除了NAS,内网穿透的应用场景还有很多,非常感谢Frp的作者七牛云的fatedier。作为补充材料,就写这么多吧。希望对大家有些许帮助。



369 thoughts on “内网穿透实用指南 – Frp+NAS”

  • Another thing I have really noticed is that often for many people, low credit score is the reaction of circumstances above their control. One example is they may be really saddled by having an illness so that they have substantial bills for collections. Maybe it’s due to a employment loss or inability to do the job. Sometimes divorce or separation can send the money in a downward direction. Many thanks for sharing your ideas on this web site.

  • obviously like your web-site but you need to take a look at the spelling on several of your posts. Several of them are rife with spelling problems and I to find it very troublesome to inform the truth however I?ll definitely come back again.

  • Hey very cool web site!! Guy .. Beautiful .. Amazing .. I’ll bookmark your web site and take the feeds additionally?I’m satisfied to seek out so many useful information here in the submit, we’d like develop extra techniques on this regard, thanks for sharing. . . . . .

  • I have observed that over the course of making a relationship with real estate owners, you’ll be able to get them to understand that, in every real estate purchase, a commission amount is paid. In the end, FSBO sellers will not “save” the commission rate. Rather, they struggle to earn the commission by way of doing a great agent’s task. In accomplishing this, they commit their money and also time to accomplish, as best they might, the duties of an realtor. Those responsibilities include disclosing the home by marketing, offering the home to prospective buyers, developing a sense of buyer desperation in order to prompt an offer, arranging home inspections, dealing with qualification investigations with the loan company, supervising fixes, and aiding the closing.

  • I have seen plenty of useful elements on your web page about personal computers. However, I have got the impression that netbooks are still not quite powerful more than enough to be a good choice if you frequently do things that require plenty of power, such as video modifying. But for web surfing, word processing, and majority of other typical computer functions they are perfectly, provided you may not mind the tiny screen size. Thank you sharing your thinking.

  • An impressive share! I have just forwarded this onto a friend who was conducting a little homework on this. And he in fact bought me breakfast due to the fact that I discovered it for him… lol. So allow me to reword this…. Thanks for the meal!! But yeah, thanks for spending time to talk about this matter here on your web site.

  • After I originally left a comment I appear to have clicked the -Notify me when new comments are added- checkbox and now each time a comment is added I recieve 4 emails with the exact same comment. There has to be a means you are able to remove me from that service? Cheers.

  • Also a thing to mention is that an online business administration training course is designed for individuals to be able to smoothly proceed to bachelor degree courses. The Ninety credit education meets the lower bachelor education requirements then when you earn your associate of arts in BA online, you may have access to up to date technologies in this particular field. Some reasons why students are able to get their associate degree in business is because they’re interested in the field and want to obtain the general education and learning necessary prior to jumping right into a bachelor diploma program. Thanks for the tips you really provide as part of your blog.

  • What?s Happening i’m new to this, I stumbled upon this I have found It positively useful and it has aided me out loads. I hope to contribute & aid other users like its helped me. Great job.

  • What i don’t understood is actually how you’re not really much more well-liked than you might be right now. You are very intelligent. You realize therefore considerably relating to this subject, produced me personally consider it from numerous varied angles. Its like men and women aren’t fascinated unless it is one thing to accomplish with Lady gaga! Your own stuffs excellent. Always maintain it up!

  • Thanks for your article. I have continually seen that the majority of people are wanting to lose weight since they wish to look slim and also attractive. Nevertheless, they do not always realize that there are other benefits to losing weight in addition. Doctors insist that fat people are afflicted with a variety of conditions that can be directly attributed to their particular excess weight. Fortunately that people who definitely are overweight and suffering from several diseases can reduce the severity of their illnesses by simply losing weight. You’ll be able to see a slow but noticeable improvement with health whenever even a small amount of weight loss is reached.

  • I’m often to blogging and i really appreciate your content. The article has actually peaks my interest. I’m going to bookmark your web site and maintain checking for brand spanking new information.

  • I’m often to blogging and i really appreciate your content. The article has actually peaks my interest. I’m going to bookmark your web site and maintain checking for brand spanking new information.

  • Throughout the awesome pattern of things you get a B+ for effort. Where exactly you lost us was first in your details. As it is said, the devil is in the details… And that couldn’t be more true right here. Having said that, permit me reveal to you what exactly did work. The authoring is actually extremely persuasive and this is possibly the reason why I am taking an effort in order to comment. I do not really make it a regular habit of doing that. Next, even though I can certainly notice a jumps in reason you make, I am not necessarily sure of just how you appear to unite your details which in turn make the conclusion. For right now I shall yield to your issue however hope in the near future you link the dots better.

  • One thing is that if you find yourself searching for a education loan you may find that you’ll need a co-signer. There are many conditions where this is correct because you may find that you do not use a past credit standing so the loan company will require that you’ve someone cosign the financing for you. Thanks for your post.

  • Thank you for sharing superb informations. Your web-site is so cool. I am impressed by the details that you have on this website. It reveals how nicely you perceive this subject. Bookmarked this web page, will come back for more articles. You, my friend, ROCK! I found just the information I already searched all over the place and just couldn’t come across. What an ideal website.

  • Normally I don’t learn post on blogs, however I wish to say that this write-up very compelled me to check out and do so! Your writing style has been surprised me. Thanks, very great article.

  • You made some good points there. I looked on the web to find out more about the issue and found most people will go along with your views on this site.

  • Hi there! This article couldn’t be written any better! Looking at this post reminds me of my previous roommate! He always kept preaching about this. I’ll forward this information to him. Pretty sure he’ll have a very good read. I appreciate you for sharing!

  • You could certainly see your skills in the paintings you write. The arena hopes for even more passionate writers like you who are not afraid to say how they believe. All the time go after your heart.

  • Thanks for the helpful content. It is also my belief that mesothelioma cancer has an really long latency time, which means that the signs of the disease would possibly not emerge till 30 to 50 years after the preliminary exposure to mesothelioma. Pleural mesothelioma, which is the most common sort and has effects on the area around the lungs, might cause shortness of breath, upper body pains, and a persistent coughing, which may bring about coughing up blood.

  • It?s really a nice and useful piece of information. I am glad that you shared this useful info with us. Please keep us informed like this. Thanks for sharing.

  • Many thanks for your post. I’d like to say that the expense of car insurance varies from one insurance plan to another, given that there are so many different issues which contribute to the overall cost. For instance, the make and model of the vehicle will have a huge bearing on the fee. A reliable aged family automobile will have a lower priced premium compared to a flashy sports vehicle.

  • That is the fitting blog for anybody who needs to seek out out about this topic. You understand a lot its almost onerous to argue with you (not that I actually would need?HaHa). You undoubtedly put a brand new spin on a subject thats been written about for years. Nice stuff, just great! Dr Vi PDO Thread Lift Melbourne 602A Bourke Street Melbourne Victoria Australia 3000

  • You’ve made some good points there. I checked on the net for more information about the issue and found most individuals will go along with your views on this website.

  • I was just seeking this information for a while. After six hours of continuous Googleing, finally I got it in your web site. I wonder what is the lack of Google strategy that don’t rank this kind of informative websites in top of the list. Normally the top sites are full of garbage.

  • That is the precise blog for anybody who desires to search out out about this topic. You realize a lot its nearly hard to argue with you (not that I actually would need?HaHa). You positively put a brand new spin on a subject thats been written about for years. Nice stuff, just great!

发表评论

邮箱地址不会被公开。 必填项已用*标注

− 1 = 1