Proxying Minecraft with FRP
Introduction
Section titled “Introduction”This guide is for running a proxy for Minecraft in the more literal sense. This will not go over how to setup a proxy like Velocity and setting up routing from a single proxy server to multiple Minecraft servers. This is for setting up a tunnel connection between a public proxy server and a Minecraft server. People will send traffic to the public server, which then gets directed to the Minecraft server.
Backstory
Section titled “Backstory”So imagine yourself in this situation. You’ve just setup a new Minecraft server. You can play on it by yourself, on your own network, no issue. However, there’s a problem. Some friends (or a friend, whatever case you’re in) want to join you in your new Minecraft server. With your new guests wanting to join in, you need to somehow expose it to the public internet so that your friends can join. You can port forward and directly expose your Minecraft server on its designated but maybe you can’t port forward as you’re behind CGNAT. Maybe you’re not comfortable with poking holes in your firewall and exposing your home network to the public internet.
I found myself in this situation a while back, as I was setting up a Minecraft server for myself and someone else to play on. I had VPN access back to my house, but that wasn’t really great as it would allow only me to play on the server, and my friend would need to install my VPN software and configure it to join my VPN in order to remote back into my house and play.
I looked for some ways to expose my Minecraft server without having to port forward on my home network. I banged my head against the wall for a while. It was not fun. I tried playit.gg, rathole, iptables port forwarding, and NGINX streams. All seemed to either not work at all, or be unreliable in my case. I tried destroying and recreating my public server to no avail.
Tutorial
Section titled “Tutorial”After a few weeks of suffering, I stumbled upon frp. It looked slightly intimidating, but was overall nice to setup. This program will need to be installed on both the Minecraft server and your public server. The Minecraft server is considered the client while your public server is considered the server. I will be referring to them as such. Here is a guide on how I’ve set it up for my Minecraft server(s):
Requirements
Section titled “Requirements”- A computer running the Minecraft server (This guide assumes it runs Linux)
- A public Linux server with the ability to expose ports
Server setup
Section titled “Server setup”- Download the latest release from the frp Github using this command (good enough for 99% of cases, v0.63.0 was the latest version at the time of release)
wget -O frp.tar.gz https://github.com/fatedier/frp/releases/download/v0.63.0/frp_0.63.0_linux_amd64.tar.gzor by using this script to automatically get the correct download for your system
# coming soon^tm- Open up the downloaded file
tar -xvzf frp.tar.gz- Rename the extracted folder to
frpfor easier typing
mv frp_0.63.0_linux_amd64 frp- Enter the
frpfolder
cd frp- Move the
frps(the server component offrp) executable to/usr/local/bin
mv frps /usr/local/bin- Remove all other files aside from
frps.toml
rm -f frpc* LICENSE- Open
frps.tomland replace its text with what’s below.
nano frps.toml # command for opening filebindAddr = "0.0.0.0"bindPort = 7000auth.method = "token"auth.token = "insert-super-secret-token"This configuration will tell frps to run on port 7000 and setup authentication using a simple token. Of course, replace the sample token with a new token you made. You will also need this token later.
Take note of the IP or domain that you used for your public server, as we’ll need that later as well.
- Expose port 7000 for
frps
sudo iptables -I INPUT 6 -m state --state NEW -p tcp --dport 7000 -j ACCEPTsudo netfilters-persistent savesudo netfilters-persistent reload- Start
frpswith yourfrps.toml
frps -c /path/to/frps.tomlCongrats, you have now setup a frp server! Now we will have your client (at-home Minecraft server) connect to it!
Client Setup
Section titled “Client Setup”- Download the latest release from the frp Github using this command (good enough for 99% of cases, v0.63.0 was the latest version at the time of release)
wget -O frp.tar.gz https://github.com/fatedier/frp/releases/download/v0.63.0/frp_0.63.0_linux_amd64.tar.gzor by using this script to automatically get the correct download for your system
# coming soon^tm- Open up the downloaded file
tar -xvzf frp.tar.gz- Rename the extracted folder to
frpfor easier typing
mv frp_0.63.0_linux_amd64 frp- Enter the
frpfolder
cd frp- Move the
frpc(the client component offrp) executable to/usr/local/bin
mv frpc /usr/local/bin- Remove all other files aside from
frpc.toml
rm -f frps* LICENSE- Open
frpc.tomland replace its text with what’s below.
nano frpc.toml # command for opening fileserverAddr = "server.domain.or.ip"serverPort = 7000auth.method = "token"auth.token = "insert-super-secret-token"
[[proxies]]name = "bedrock-server"type = "udp"localIP = "127.0.0.1"localPort = 19132remotePort = 19132This configuration will tell frp client to connect to the public server on port 7000 and authenticate using the token you made earlier. It connects the Minecraft server running on UDP port 19132 on your home computer to the public frp server’s UDP port 19132.
In this case, this is connecting a Bedrock server running in your house to the public frp server as a proxy configuration. Bedrock servers by default use UDP port 19132. The configuration options starting with local refer to the machine you’re running the Minecraft server on, while remote refers to the public frp server you’ve setup earlier.
On the public frp server, you’ll also need to expose UDP port 19132, which can be done using these commands
sudo iptables -I INPUT 6 -m state --state NEW -p udp --dport 19132 -j ACCEPTsudo netfilters-persistent save # commands to save this rule to the machine so that it works after a rebootsudo netfilters-persistent reload- Start
frpcwith yourfrpc.toml
frpc -c /path/to/frpc.tomlCongrats, you have now connected your home Minecraft server to your public frp server! From here, all your friends need to do is to connect to your public server in order to play.
Further Reading
Section titled “Further Reading”Now that you have setup frp and connected your home server to your public server, there are a few things you can do to further improve this.
Auto-starting
Section titled “Auto-starting”With frps and frpc left as is, you would need to manually restart them every time you reboot either your home server, or the public server. This can be solved with setting up an auto-start service on both your home server and the public server.
- On the public server, create
/etc/systemd/system/frps.service
sudo touch /etc/systemd/system/frps.service- Open
/etc/systemd/system/frps.serviceand paste in this text
sudo nano /etc/systemd/system/frps.service[Unit]Description=Fast Reverse Proxy tunneling server
[Service]ExecStart=/usr/local/bin/frps -c /home/<username>/frp/frps.toml
[Install]WantedBy=multi-user.target- Remember to replace
<username>with the name of your user on the public server
-
Save and exit.
-
Start and enable the service
sudo systemctl start frps.servicesudo systemctl enable frps.service- Check the status of the service
sudo systemctl status frps.serviceOn your home server, the process is identical. Just replace frps with frpc.
Using a Java Minecraft server
Section titled “Using a Java Minecraft server”If you’re running a Java server instead of a Bedrock similar, the only thing that needs to be changed is the iptables command used and the frp configs used on both the server and client.
Server Changes
Section titled “Server Changes”Instead of running:
sudo iptables -I INPUT 6 -m state --state NEW -p udp --dport 19132 -j ACCEPTyou would instead run:
sudo iptables -I INPUT 6 -m state --state NEW -p tcp --dport 25565 -j ACCEPTThis would expose TCP port 25565 on the server, as that is the default port of a Java server. If you chose to use a different port, replace 25565 with your desired port.
Client Changes
Section titled “Client Changes”In your frpc.toml, replace your [[proxies]] section with the text below.
[[proxies]]name = "java-server"type = "tcp"localIP = "127.0.0.1"localPort = 25565remotePort = 25565- If your Minecraft server is on a different port, simply replace the value of
localPortto your desired port number.