SRV records are cool
I am currently hosting a Minecraft server for my friends and I to play on, and I do (as you may be aware) own a domain. The issue is that I’m hosting it on a non-standard port—i.e., it is not reachable on 25565. This would mean that when my friends want to connect to my server, they’d have to enter something like subdomain.example.com:12345, which is annoying to remember.
That is, until I found out about SRV records, which I was completely unaware of. SRV records redirect traffic from a domain to a specific IP:Port combination, and they solve exactly this kind of problem.
Working example
Let’s assume your domain is minecraft.yourname.com and you host a Minecraft server on IP 123.123.123.1:12345. In order have your friends connect solely through minecraft.yourname.com, you’d have to create two DNS records:
- an
Arecord which points to123.123.123.1; - an
SRVrecord which redirectsminecraft.yourname.comto yourArecord on port12345.
Further assuming you have Cloudflare as your DNS provider, you can easily create your A record from the DNS records settings. In this case:
- in the
Namefield, input your subdomainminecraft; - in the
IPv4 addressfield, input123.123.123.1; - disable Cloudflare’s proxy (the orange cloud).
Disabling the proxy is not necessary, but adding an SRV record would still expose your IP. You’d get a warning saying exactly this if you didn’t.
Now add the SRV record:
- in the
Namefield, write_minecraft._tcp.minecraft:_minecraftspecifies which application the record redirects to;_tcpindicates that it uses TCP as a transport protocol;minecraftis the subdomain which hosts this service;
- in the
Priorityfield, write0(the highest priority); - in the
Weightfield, write5; - in the
Portfield, write12345, the port for your Minecraft server; - in the
Targetfield, writeminecraft.yourname.com.
Note that if you only have a single server (which you probably do), priority and weight mean nothing: priority is used to select the preferred host, while weight is used as a tie breaker among hosts with the same priority. It’s a load balancing feature which becomes irrelevant with a single service.
And there you go, you now can connect to your Minecraft server through minecraft.yourname.com! You can check that this went through correctly with dig:
dig minecraft.yourname.com +short
dig _minecraft._tcp.minecraft.yourname.com SRV +short
You should see the following two answers:
123.123.123.1
0 5 12345 minecraft.yourname.com.