Tutorial for setting up IP-Table tunnel as relay server
This page shows you how to turn a server into a relay for your Hiddify Manager server using IP-Tables, the firewall built into Linux. It is the simplest method: one script, no extra software to keep running.
A relay server is a second server, usually inside your own country, that your users connect to. It forwards their traffic to your main Hiddify server abroad. This helps when the main server's IP is blocked or slow from your country. Read more about relay servers.
There is also a video tutorial in Persian for this method.
Prerequisites
- A main server with Hiddify Manager installed. See the installation guide.
- A relay server running Ubuntu or Debian, with a clean IP and enough bandwidth and CPU for your users. RAM matters little: a small, cheap server (for example 256 MB of RAM) is enough, and you can run several of them.
- SSH access to the relay server as
root. New to SSH? See how to connect to a server via SSH. - The IP address of your main server.
Set up the relay server
- Connect to your relay server over SSH.
-
Run this command:
-
When asked
Enter your main server IP like(1.1.1.1):, type your main server's IP and pressEnter. -
The script installs
iptablesandiptables-persistent. If a blue screen asks whether to save the current IPv4 (and IPv6) rules, choose Yes.The script forwards TCP ports
80and443, and all UDP traffic, to your main server, and saves the rules so they come back after a reboot. -
The script turns on IP forwarding (needed for the tunnel) only until the next reboot. Make it permanent:
Check that it worked
Run this on the relay server:
You should see DNAT lines that point to your main server's IP. If you do not, run the script again and check the IP you typed.
Add the relay server to Hiddify Manager
- Point a subdomain (for example
relay.example.com) at the relay server's IP with anArecord. On Cloudflare, keep the proxy off (grey cloud). - In the panel, open Domains, click Add domain, enter the subdomain and choose the mode Relay.
- Edit your subscription domain, select the relay domain under Show configs of, then apply the changes.
For the full steps, see How to add a relay server (domain) to HiddifyManager.
Screenshots from an older panel version
Remove the relay rules
The forwarding rules live in the nat table. To delete them and save the empty rule set, run this on the relay server:
Warning
This deletes every rule in the nat table, including any you added yourself.
To also turn IP forwarding off, delete the file you created: