Using frp to Expose Local Services, with a Synology NAS Example

If you want to access services at home while you are away but do not have a public IP address at home, frp is one practical way to expose those local services.

Overview

If you want to access services in your home network while away from home, but your home connection does not have a public IP, then you need some form of reverse proxy or NAT traversal.

frp overview

When a user cannot connect directly to services running at home, a server with a public IP can act as the bridge.

What we need to do next is install the frp server and client on the public server and the home side respectively.

Installation Location frp Component
Public server frp server, frps
Local machine (NAS, Windows, etc.) frp client, frpc

Download

[button color=“success” icon=“iconfont icon-fork” url=“https://github.com/fatedier/frp/releases”]GitHub[/button]

1
wget https://github.com/fatedier/frp/releases/download/v0.32.0/frp_0.32.0_linux_amd64.tar.gz

Installation

1. Server Side (the Host with a Public IP)

1
2
3
tar -xvf frp_0.32.0_linux_amd64.tar.gz
rm -f frpc*      # Delete the unused client files; optional
vim frps.ini     # Edit the configuration file

Add the following content and save it. Here, bind_port = 7000 is the port used for frp communication.

1
2
3
4
5
6
7
[common]
bind_port = 7000
vhost_http_port = 8080
max_pool_count = 5
authentication_timeout = 900
authentication_method = token
token = password

Then start the server and wait for the client to connect:

1
./frps -c frps.ini

frps started successfully

2. Client Side (Local NAS)

Extract the same package on the client side as well. If your client is Windows or macOS, just download the appropriate build from GitHub instead.

1
2
3
tar -xvf frp_0.32.0_linux_amd64.tar.gz
rm -f frps*      # Delete the unused server files; optional
vim frpc.ini     # Edit the configuration file

Add the following content and save it. Again, server_port = 7000 is the port used between frp client and server.

You can expose multiple services. For example, if you want to reach your NAS remotely, you can map the NAS’s local port 22 to port 6000 on the public server, or any other unused port.

That means visiting server-ip:6000 is effectively the same as connecting to 127.0.0.1:22 on your local NAS.

[scode type=“red”] Note: if your server has a firewall enabled, make sure every remote_port you use is opened in the firewall rules. [/scode]

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
[common]
server_addr = your-public-server-ip
server_port = 7000
token = password
pool_count = 1

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

[nas]
type = tcp
local_ip = 127.0.0.1
local_port = 5000
remote_port = 5000
use_compression = true

[mysql]
type = tcp
local_ip = 127.0.0.1
local_port = 3306
remote_port = 3306
use_compression = true
1
2
# Start the client the same way
./frpc -c frpc.ini

Client connected successfully

At this point the remote access setup is working, but if you want to use it long-term, you will probably also want background execution and auto-start on boot.

3. Start Automatically on Boot

I will show two approaches below. If your client or server is Windows or macOS, you can look up the corresponding startup method for that platform.

Synology DSM

1
2
cd /usr/syno/etc.defaults/rc.sysv/
vim frpc.sh     # Create the startup script

Put these two lines into the script:

1
2
cd /usr/frp_0.32.0_linux_amd64    # Enter the frpc directory
nohup ./frpc -c ./frpc.ini &      # Start frpc in the background

Grant execute permission to the script and edit the startup file:

1
2
chmod +x frpc.sh
vim /etc/rc

Type :$ to jump to the last line, then add the following before exit 0:

1
/usr/syno/etc.defaults/rc.sysv/frpc.sh

Add the startup script entry

You can now reboot the system and check whether frp starts successfully.

CentOS

  1. Create a systemd service:
1
vim /etc/systemd/system/frps.service

Add the following content. Remember to replace ExecStart with the actual path to your own frps binary.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
[Unit]
Description=Frp Server Service
After=network.target

[Service]
Type=simple
User=nobody
Restart=on-failure
RestartSec=5s
ExecStart=/home/izumi/frp_0.32.0_linux_amd64/frps -c /home/izumi/frp_0.32.0_linux_amd64/frps.ini

[Install]
WantedBy=multi-user.target
  1. Manage the service. In normal use, you only need commands 1 and 3:
1
2
3
4
sudo systemctl enable frps      # Enable auto-start
sudo systemctl disable frps     # Disable auto-start
sudo systemctl start frps       # Start frps
sudo systemctl status frps      # Check frps status

Official Documentation

This post only covers the basic setup. For more features and detailed usage, see: [button color=“success” icon=“iconfont icon-fork” url=“https://github.com/fatedier/frp/blob/master/README.md”]Official Documentation[/button]

转载请保留本文转载地址,著作权归作者所有