内网穿透(ubuntu)
使用frp 内网穿透
1、准备局域网电脑
2、准备带公网ip 的电脑/服务器(阿里云、腾讯云都可以等)
3、frp下载
frp介绍
下载解压后文件如下:
frpc # 客户端二进制文件
frpc_full.ini # 客户端配置文件完整示例
frpc.ini # 客户端配置文件
frps # 服务端二进制文件
frps_full.ini # 服务端配置文件完整示例
frps.ini # 服务端配置文件
1、客户端:局域网电脑配置文件
vim frpc.ini
[common]
server_addr = 你的公网ip x.x.x.x
server_port = 7000
token = asdfghjkl
[ssh]
type = tcp
local_ip = 127.0.0.1
local_port = 22
remote_port = 6000
[jupyter]
type = http
local_ip = 127.0.0.1
local_port = 8888
custom_domains = jupyter.你的域名(比如baibai.com)
[neo4j]
type = http
local_ip = 127.0.0.1
local_port = 7474
custom_domains = neo4j.你的域名(比如baibai.com)
- 访问远程web服务链接,不用加端口号: http://neo4j.baibai.com ; http://jupyter.baibai.com
2、服务端:带公网电脑配置文件
vim frps.ini
[common]
bind_addr = 0.0.0.0
bind_port = 7000
vhost_http_port = 80
token = asdfghjkl
3、启动服务端、客户端测试
./frps -c ./frps.ini
./frpc -c ./frpc.ini
假设用户名为test,则通过ssh连接到LAN中的服务器:ssh -oPort=6000 test@x.x.x.x
4、启动
4.1 后台启动
nohup /path/to/your/fprs -c /path/to/your/frps.ini > /path/to/your/nohup.out 2>&1 &
nohup /path/to/your/fprc -c /path/to/your/frpc.ini > /path/to/your/nohup.out 2>&1 &
4.2 开机自启
4.2.1 systemctl方式
vim /usr/lib/systemd/system/frps.service
[Unit]
Description=frp server
After=network.target
[Service]
Type=simple
ExecStart=nohup /path/to/your/fprs -c /path/to/your/frps.ini > /path/to/your/nohup.out 2>&1 &
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
[Install]
WantedBy=multi-user.target
-
启动frps
sudo systemctl start frps
-
再打开自启动
sudo systemctl enable frps
-
重启
sudo systemctl restart frp
-
停止
sudo systemctl stop frps
-
查看状态
sudo systemctl status frps
4.2.1 supervisor方式
sudo apt install supervisor
cd /etc/supervisor/conf.d
vim frp.conf
[program:frp]
command =nohup /path/to/your/fprs -c /path/to/your/frps.ini > /path/to/your/nohup.out 2>&1 &
autostart = true
- 重启supervisor
sudo systemctl restart supervisor
- 查看supervisor运行状态
sudo supervisorctl status