22

Ubuntu / macOS 配置frp内网穿透

 2 years ago
source link: https://www.enoch2090.me/ubuntu_macos_frp_reverse_proxy
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Ubuntu / macOS 配置frp内网穿透

Ubuntu / macOS 配置frp内网穿透

2021 年 9 月 16 日
住的地方没有公网 ip,为了可以做到出门只带个 iPad,决定配置一个 frp 内网穿透。
我用的是 Github 上开源的原版 frp,自己配置服务器,没有花里胡哨的功能,简洁明了。项目地址:
准备一台有公网地址的服务器,性能不是很重要,保证带宽就行。我用的是 Microsoft Azure Cloud 的服务器,2vCPU + 8GiB Mem 主频 2.4GHz,Github Student Pack 送一年免费使用,用作 frp 性能完全够了。
在服务器上运行:
wget https://github.com/fatedier/frp/releases/download/v0.37.1/frp_0.37.1_linux_amd64.tar.gz
tar -xf frp_0.37.1_linux_amd64.tar.gz
cd frp_0.37.1_linux_amd64
nohup ./frps -c ./frps.ini > frps_bkg.log 2>&1 &
默认端口是 frps.ini 里声明的 7000
然后在本地需要穿透的机器上配置 frpc。这里给出 Ubuntu 和 macOS 两种系统的对应命令。
Ubuntu:
wget https://github.com/fatedier/frp/releases/download/v0.37.1/frp_0.37.1_linux_386.tar.gz
tar -xf frp_0.37.1_linux_386.tar.gz
cd frp_0.37.1_linux_386
nano frpc.ini
在配置文件里把 [common] 下面的 server_addr 改成公网服务器的 ip。如果需要设置多个端口,在下面另外添加。
# frpc.ini
[common]
server_addr = x.x.x.x # 公网服务器的 ip 地址
server_port = 7000

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

[other_services]
type = tcp            # 其他需要暴露端口的服务
local_ip = 127.0.0.1
local_port = 10022
remote_port = 6001
在 macOS 上是
wget https://github.com/fatedier/frp/releases/download/v0.37.1/frp_0.37.1_darwin_amd64.tar.gz
tar -xf frp_0.37.1_darwin_amd64.tar.gz
cd frp_0.37.1_darwin_amd64
nano frpc.ini
修改配置文件方法同上。完成后运行
./frpc -c ./frpc.ini
有如下输出就表明连接成功:
(base) 
之后使用时,连接的是公网服务器+对应的 remote_port。映射原理如下:
frpc 的端口映射原理
frpc 的端口映射原理
如果按上面那个配置文件设置,本地机器的 22 端口→公网服务器 6000 端口; 本地机器的 10022 端口→公网服务器 6001 端口。所以 ssh 的方法就是
ssh -p 6000 [email protected]
用手机的AT&T网络测试了一下,连接成功。
notion image

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK