frps实现局域网内网穿透
局域网穿透:顾名思义,就是在没有公网IP的情况下,实现从公网访问局域网络的一种技术统称。
局域网内网穿透的很多方式:
- Cloudflare Tunnel 实现
- nps:
- frps:
我们今天要展示的就是frps
实现局域网内网穿透,以上所有的方式都是CS模式,分为服务器端和本地端展开:
服务器端:
# 安装配置frps
root@sgvpn2:# wget https://github.com/fatedier/frp/releases/download/v0.38.0/frp_0.38.0_linux_amd64.tar.gz
root@sgvpn2:# tar -xzf frp_0.38.0_linux_amd64.tar.gz && cd frp_0.38.0_linux_amd64
root@sgvpn2:/mnt/frp_0.38.0_linux_amd64# cat frps.ini
[common]
vhost_http_port = 80
bind_port = 7000
root@sgvpn2:/mnt/frp_0.38.0_linux_amd64# cat systemd/frps.service
[Unit]
Description=Frp Server Service
After=network.target
[Service]
Type=simple
User=root
Restart=on-failure
RestartSec=5s
ExecStart=/mnt/frp_0.38.0_linux_amd64/frps -c /mnt/frp_0.38.0_linux_amd64/frps.ini
LimitNOFILE=1048576
[Install]
WantedBy=multi-user.target
root@sgvpn2:/mnt/frp_0.38.0_linux_amd64# cp systemd/frps.service /usr/lib/systemd/system/
root@sgvpn2:/mnt/frp_0.38.0_linux_amd64# systemctl daemon-reload && systemctl start frps && systemctl enable frps
root@sgvpn2:/mnt/frp_0.38.0_linux_amd64# systemctl status frps | grep running
Active: active (running) since Wed 2024-08-07 14:43:29 UTC; 15min ago
本地客户端
[root@rocky01 frp] # wget https://github.com/fatedier/frp/releases/download/v0.38.0/frp_0.38.0_linux_amd64.tar.gz
[root@rocky01 frp] # tar -xzf frp_0.38.0_linux_amd64.tar.gz && mv frp_0.38.0_linux_amd64 frp && cd. frp
[root@rocky01 frp] # cat frpc.ini
[common]
server_addr = <公网IP>
server_port = 7000
[web]
type = http
local_port = 80
custom_domains = <自己注册的域名>
[root@rocky01 frp] # cat systemd/frpc.service
[Unit]
Description=Frp Client Service
After=network.target
[Service]
Type=simple
User=root
Restart=on-failure
RestartSec=5s
ExecStart=/opt/frp/frpc -c /opt/frp/frpc.ini
ExecReload=/opt/frp/frpc reload -c /opt/frp/frpc.ini
LimitNOFILE=1048576
[Install]
WantedBy=multi-user.target
[root@rocky01 frp] # cp systemd/frpc.service /usr/lib/systemd/system/
[root@rocky01 frp] # systemctl daemon-reload
[root@rocky01 frp] # systemctl start frpc.service && systemctl enable frpc.service
验证:在服务端检查,确认客户端和服务端已经建立通信。
root@sgvpn2:/mnt/frp_0.38.0_linux_amd64# systemctl status frps | grep new
Aug 07 14:43:29 sgvpn2 frps[72595]: 2024/08/07 14:43:29 [I] [control.go:444] [309dac36a69e1194] new proxy [web] success
剩下的就是在域名注册商那里添加DNS,将自定域名和服务器端的公网IP绑定,然后就可以快乐的公网访问局域网的相关应用了。
本文来自博客园,作者:Jas0n0ss,转载请注明原文链接:https://www.cnblogs.com/Jas0n0ss/p/18348047