Dongxing's Wiki Dongxing's Wiki
首页
  • 剑指 Offer
  • LeetCode
  • 算法与数据结构
  • Python 语言
  • Web 开发
  • Hive
  • Elastic Search
  • 机器学习
  • NLP
  • 检索技术
  • 数据分析
  • 经验笔记
  • Linux 配置
  • 博客进化记
  • 杂谈
GitHub (opens new window)
首页
  • 剑指 Offer
  • LeetCode
  • 算法与数据结构
  • Python 语言
  • Web 开发
  • Hive
  • Elastic Search
  • 机器学习
  • NLP
  • 检索技术
  • 数据分析
  • 经验笔记
  • Linux 配置
  • 博客进化记
  • 杂谈
GitHub (opens new window)
  • 经验笔记

    • Git 常用命令速查
    • Let's Encrypt 免费泛域名通配符证书申请
    • 在Vmware虚拟机上搭建Hadoop+Spark集群
    • iTerm2 配置 ssh 记住密码一键登录
    • 使用frp进行内网穿透
      • 下载 frp
      • 转发 http 应用
      • 转发ssh
    • macOS 上的常用环境配置笔记
    • 使用 kutt.tt 自建短网址服务
    • 在Ubuntu上自建NextCloud
    • 换路由器后连接不上本地 NAS
  • 经验笔记
  • 经验笔记
anthony
2020-01-11
目录

使用frp进行内网穿透

特别说明

本文仅个人笔记,依据实际情况有不同的配置项,还请参阅frp文档

# 下载 frp

https://github.com/fatedier/frp/releases

# 转发 http 应用

frp需要运行在两台机器上,一台是具有公网ip的服务器,作为server端,另一台是内网机器,作为client端。 之后通过公网访问server端,server端会和内网client端通信,从而实现了公网访问没有公网ip的内网机器。

server端的配置,编辑 frps.ini文件

[common]
bind_port = 7000  # 设定服务端和客户端通信的端口
auth_token = frp
type = http
vhost_http_port = 8000  # 设定服务端暴露给用户的端口
custom_domains = xxxxx  # 如有,设置个性域名
1
2
3
4
5
6

server端的启动(通过nohup使之保持运行在后台)

nohup ./frps -c frps.ini &
1

client端的配置,编辑frpc.ini 文件

[common]
server_addr = xxxxx    # 服务器地址
server_port = 7000   # 跟上边写的服务器端口要对应起来
auth_token = frp  # 跟上边的token要对应起来
[web6]
type = http
local_port = 8888  # 本地服务的端口
custom_domains = xxxxx  # 跟上边域名对应起来
1
2
3
4
5
6
7
8

客户端的启动

nohup ./frpc -c frpc.ini &
1

客户端启动后,会和服务器端进行通信,并一直保持连接。

访问 xxxx:8000可以查看效果,8000是之前vhost_http_port这一项配置的

# 转发ssh

是的,转发ssh也很方便,服务器端配置 frps.ini:

[common]
bind_port = 7000  # 设置一个端口号就行啦
token = frp
1
2
3

客户端配置 frpc.ini

# frpc.ini
[common]
server_addr = x.x.x.x  # 服务器地址
server_port = 7000  # 上面设置的服务器端端口号
token = frp # 密码,跟上面对应起来

[ssh]
type = tcp
local_ip = 127.0.0.1 
local_port = 22  # 本地机器的ssh端口,一般默认为22
remote_port = 6000  # 在vps上的端口
1
2
3
4
5
6
7
8
9
10
11

按上面配置好后,记得在公网服务器防火墙或者安全组中,把 7000 和 6000 端口都放开。

将来使用时:

ssh local_user@server_ip -p 6000 
1

用户名是本地机器的用户名;@后面是服务器的地址,端口是上面配置的 remote_port。输入的密码是本地机器该用户的密码。

然后你就会惊奇地发现,可以在公网ssh到内网机器啦。

上次更新: 2021/08/29, 2:08:00
iTerm2 配置 ssh 记住密码一键登录
macOS 上的常用环境配置笔记

← iTerm2 配置 ssh 记住密码一键登录 macOS 上的常用环境配置笔记→

Theme by Vdoing | Copyright © 2017-2023 anthony 京ICP备17072417-3
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式