DEV Community

Abhishek Sinha
Abhishek Sinha

Posted on

Self Host Without Public IP

FRP (Fast Reverse Proxy) Setup on Linux Machine to bypass CGNAT. [Self-Hosting] Updated Doc: Feb 2025

Image description

This guide provides step-by-step instructions to download, configure, test, and set up FRP (frps for the server and frpc for the client) as a systemd service on Ubuntu/Debian systems.

Prerequisites

  • Server: A machine with a public IP address to host frps.
  • Client: A machine (behind NAT or firewall) where frpc will run.
  • Both Machines: Ubuntu/Debian operating system with wget installed.

1. Download and Install FRP

On the Server (Public Machine)

  1. Download latest FRP [Choose package according to machine architecture]:
   wget https://github.com/fatedier/frp/releases/download/v0.61.1/frp_0.61.1_linux_amd64.tar.gz
Enter fullscreen mode Exit fullscreen mode
  1. Extract the Archive:
   tar -zxvf frp_0.61.1_linux_amd64.tar.gz
Enter fullscreen mode Exit fullscreen mode
  1. Edit frps Configuration File:
   cd frp_0.61.1_linux_amd64
   sudo nano frps.toml
Enter fullscreen mode Exit fullscreen mode

Update the following content if required:

   bind_port = 7000
   auth.token = "mysecret"
Enter fullscreen mode Exit fullscreen mode

On the Client (Local Machine)

  1. Download latest FRP [Choose package according to machine architecture]:
   wget https://github.com/fatedier/frp/releases/download/v0.61.1/frp_0.61.1_linux_amd64.tar.gz
Enter fullscreen mode Exit fullscreen mode
  1. Extract the Archive:
   tar -zxvf frp_0.61.1_linux_amd64.tar.gz
Enter fullscreen mode Exit fullscreen mode
  1. Edit frpc Configuration File:
   cd frp_0.61.1_linux_amd64
   sudo nano frpc.toml
Enter fullscreen mode Exit fullscreen mode

Add the following content:

   server_addr = "x.x.x.x"  # Replace with your server's public IP
   server_port = 7000
   auth.token = "mysecret"
   login_fail_exit = false

   [[proxies]]
   name = "example1"
   type = "tcp"
   local_port = 81
   remote_port = 6000

   [[proxies]]
   name = "example2"
   type = "tcp"
   local_port = 83
   remote_port = 6001
Enter fullscreen mode Exit fullscreen mode
  1. NOTE: Need to allow these remote ports on frps [server with public ip] firewall.

2. Testing the Setup

On the Server

  1. Start frps Manually:
   frps -c /etc/frp/frps.toml
Enter fullscreen mode Exit fullscreen mode

On the Client

  1. Start frpc Manually:
   frpc -c /etc/frp/frpc.toml
Enter fullscreen mode Exit fullscreen mode
  1. Test Connections:
    • Access the services exposed via the server's public IP on ports 6000 and 6001 to ensure they're correctly forwarded to the client's local services on ports 81 and 83, respectively.

3. Setting Up as a Systemd Service

To ensure that FRP starts on boot and can be managed easily, set up both frps and frpc as systemd services.

On the Server

  1. Copy binary and config file to required places

    sudo cp frp_0.61.1_linux_amd64/frps /usr/local/bin/
    sudo mkdir -p /etc/frp
    sudo cp frp_0.61.1_linux_amd64/frps.toml /etc/frp/
    
  2. Create Systemd Service File for frps:

   sudo nano /etc/systemd/system/frps.service
Enter fullscreen mode Exit fullscreen mode

Add the following content:

   [Unit]
   Description=FRP Server Service
   After=network.target

   [Service]
   Type=simple
   ExecStart=/usr/local/bin/frps -c /etc/frp/frps.toml
   Restart=on-failure
   RestartSec=5s

   [Install]
   WantedBy=multi-user.target
Enter fullscreen mode Exit fullscreen mode
  1. Reload Systemd and Start frps Service:
   sudo systemctl daemon-reload
   sudo systemctl enable frps
   sudo systemctl start frps
Enter fullscreen mode Exit fullscreen mode
  1. Check Service Status:
   sudo systemctl status frps
Enter fullscreen mode Exit fullscreen mode

On the Client

  1. Copy binary and config file to required places

    sudo cp frp_0.61.1_linux_amd64/frpc /usr/local/bin/
    sudo mkdir -p /etc/frp
    sudo cp frp_0.61.1_linux_amd64/frpc.toml /etc/frp/
    
  2. Create Systemd Service File for frpc:

   sudo nano /etc/systemd/system/frpc.service
Enter fullscreen mode Exit fullscreen mode

Add the following content:

   [Unit]
   Description=FRP Client Service
   After=network.target

   [Service]
   Type=simple
   ExecStart=/usr/local/bin/frpc -c /etc/frp/frpc.toml
   Restart=on-failure
   RestartSec=5s

   [Install]
   WantedBy=multi-user.target
Enter fullscreen mode Exit fullscreen mode
  1. Reload Systemd and Start frpc Service:
   sudo systemctl daemon-reload
   sudo systemctl enable frpc
   sudo systemctl start frpc
Enter fullscreen mode Exit fullscreen mode
  1. Check Service Status:
   sudo systemctl status frpc
Enter fullscreen mode Exit fullscreen mode

By following these steps, you will have successfully set up FRP on both your server and client machines, allowing seamless access to services behind NAT or firewalls.

Also after testing or setup up full you can then use Nginx proxy manager or any other reverse proxy on the server with public ip to add reverse proxy to the remote ports with the required domain etc. Note the hostname for a proxy should be entered as the server's internal ip or if not available then public ip because localhost/127.0.0.1 will not work.

Top comments (0)