打通两个局域网

网络概况

公司局域网 公网 家庭局域网 可以访问 可以访问 公司局域网 公网 家庭局域网

考虑借助公网来进行内网穿透,本文使用的工具是frp。本文使用的公网ip是47.92.90.25,笔者自己租用的阿里云服务器,域名是www.hacksprit.top。

frp

frp is a fast reverse proxy to help you expose a local server behind a NAT or firewall to the Internet. As of now, it supports TCP and UDP, as well as HTTP and HTTPS protocols, where requests can be forwarded to internal services by domain name. frp also has a P2P connect mode.

架构

在这里插入图片描述

基本使用
安装及配置文件
  1. Firstly, download the latest programs from Release page according to your operating system and architecture.

  2. Put frps and frps.ini onto your server A with public IP.(公网ip)

  3. Put frpc and frpc.ini onto your server B in LAN (that can’t be connected from public Internet).(局域网ip)

准备条件

家庭局域网开启ssh服务,开启一个PHP的web服务。其他服务根据需要自行安装本文测试ssh服务和web服务。

(1) ssh服务
安装ssh服务

sudo apt-get install openssh-server

启动ssh服务

 sudo /etc/init.d/ssh start

查看ssh服务是否启动成功

ssh -o port=22 burning@127.0.0.1

如果成功启动可看到如下所示的页面:
在这里插入图片描述
(2) Web服务
通过如下的命令就可以开启一个web服务。

wget -O install.sh https://download.xp.cn/install.sh && sudo bash install.sh

在这里插入图片描述
Nginx的反向代理在后续文章中会介绍。简单来说就是Nginx代理内网服务器对外提供服务。而正像代理代理的是客户端的请求。

公司局域网ip地址

在这里插入图片描述

frp的配置和使用

(1)公网47.92.90.25做为frp的服务器。编辑frps.ini。
在这里插入图片描述运行frps,开启服务端。设置http端口是7002。阿里云需要开启相应的端口,通过安全规则进行配置。

./frps -c frps.ini

在这里插入图片描述
(1)家庭局域网192.168.42.36做为frp的客户端。编辑frpc.ini。

[common]
server_addr = 47.92.90.25
server_port = 7000

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

[web]
type = http         
local_port = 80   
custom_domains = www.hacksprit.top   

local_port = 80 是本地web服务的端口。

启动客户端frpc

 ./frpc -c frpc.ini

在frp服务器端看到如下信息:
在这里插入图片描述(2) 通过公司局域网进行测试

首先测试web服务: 在浏览器中输入www.hacksprit.top:7002成功访问到家庭局域网开启的服务。
在这里插入图片描述
再测试ssh服务: 在终端输入命令

ssh -o port=6000 burning@47.92.90.25

最终成功访问家庭局域网的ssh服务。
在这里插入图片描述

公众号

更过内容,欢迎关注我的微信公众号:无情剑客。
在这里插入图片描述

评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

helloworddm

你的鼓励是我创作最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值