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 HiddifyManager server abroad. This helps when the main server's IP is blocked or slow from your country. Read more about relay servers.
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.
If ufw is on
If the ufw firewall is on on the relay server, it must allow forwarding: in /etc/default/ufw set DEFAULT_FORWARD_POLICY to "ACCEPT" and run sudo ufw reload. Your provider’s firewall must also leave ports 80 and 443 open.
Add the relay server to Hiddify Manager
- With an
Arecord, point a subdomain (for examplerelay.example.com) at the relay server’s IP. In Cloudflare keep the proxy off (DNS only). - In the panel, open Domains in the sidebar, click Add Domain, type the subdomain and click Check.
-
In the Mode step, under How is it set up?, choose Relay. Under Which TLS?, Valid TLS is usually best; since this script forwards port 80 to the main server too, the panel can get a certificate for the relay domain.

-
If you chose Reality or Fake, enter the relay server’s IP in that domain’s Advanced › Force Configs to Use These IPs / Domains.
- Edit your subscription domain, also select the relay domain in Show configs of, and apply the changes (Actions › Apply Now).
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: