- 注册
- 2024-12-01
- 消息
- 2
- 金粒
- 金粒485粒
- 钻石
- 钻石0颗
- 嗨币
- 嗨币0元
- 福建
- 厦门市 用户
- 主题 作者
- #1
通过frp内网穿透+一台有公网ip的云服务器 实现ssh连接没有公网ip的服务器
1.准备工作
A.一台有[B]固定公网ip[/B]的云服务器([B][COLOR=rgb(209, 72, 65)]没有的话 本文可以不用看了[/COLOR][/B]), 作为frp服务端
(awa阿里云新用户99块一年,腾讯云阿里云好像都有学生优惠来的)
B.内网机器,作为frp客户端
2.下载安装frp
在服务端和客户端
从frp的github release下载安装包并解压 然后cd到目录:
(服务端和客户端都下载)
[URL]https://github.com/fatedier/frp[/URL]
也可以可以直接wget下载:
wget [URL]https://github.com/fatedier/frp/releases/download/v0.51.3/frp_0.51.3_linux_amd64.tar.gz[/URL]
tar -xzf frp_0.51.3_linux_amd64.tar.gz
cd frp_0.51.3_linux_amd64
进到目录以后 可以看到文件主要分为两部分
- frps(s stand for server)
- frpc(c stand for client)
like this:
root@Slave1:~/Downloads/frp_0.51.3_linux_amd64# ls
frpc frpc_full.ini frpc.ini frps frps_full.ini frps.ini LICENSE
root@Slave1:~/Downloads/frp_0.51.3_linux_amd64#
3.配置frp服务端(在云服务器配置)
在云服务器上,进入frp目录,修改frps.ini配置文件
填入以下内容:
[common]
bind_port = 7000 # 服务端监听的端口
然后启动服务端:
./frps -c frps.ini
记得要确保服务器的防火墙允许7000端口
有的服务器提供商可能会有安全组的设置,记得要在安全组设置里打开7000端口
如 阿里云ecs设置:

4.配置frp客户端(在内网机器上配置)
在客户端上,进入frp目录,修改frpc.ini配置文件
填入以下内容:
[common]
server_addr = <云服务器公网IP> # 替换为你的服务端 IP 地址
server_port = 7000 # 与服务端保持一致
[ssh]
type = tcp
local_ip = 127.0.0.1
local_port = 22 # 内网机器的 SSH 服务端口
remote_port = 6000 # 暴露在服务端的端口,任选未被占用的端口
然后启动客户端:
./frpc -c frpc.ini
5.测试ssh链接
用其他设备 通过云服务器的公网ip 和 remote_port 端口(比如刚刚选的6000) 链接内网机器的22端口
ssh <username>@<云服务器的公网ip> -p 6000
username是内网机器的用户名
服务端的frps启动以后是这样的:

客户端的frpc启动以后是这样的:

ssh连接测试一下

good
6.在客户端机子 把frp设置为系统后台服务(在内网机器上配置)
为了让frp在系统重启以后 也能自动运行, 设置成系统服务
编辑 /etc/systemd/system/frpc.service
文件
填入以下内容:
[Unit]
Description=FRP Client Service
After=network.target
[Service]
ExecStart=/path/to/frpc -c /path/to/frpc.ini
Restart=always
User=root
[Install]
WantedBy=multi-user.target
其中 /path/to/frpc
和 /path/to/frpc.ini
替换为 frpc可执行二进制文件 和 frpc配置文件 的绝对路径
start,stop,enable,disable, 查看状态,查看日志
sudo systemctl start frpc.service
sudo systemctl stop frpc.service
sudo systemctl enable frpc.service
sudo systemctl enable frpc.service
sudo systemctl status frpc.service
sudo journalctl -u frpc.service
done!
最后编辑: