How to only open the TCP port 25565 for multiple Minecraft servers?

Solution 1:

The only reason this works for HTTP is because there is a Host: header within the protocol that can be inspected. It is not possible to do this by listening on a single port if you don't also have something in the protocol that indicates where the connection should be routed.

I don't believe the Minecraft protocol has this extra information in it... If you are absolutely 100% restricted to a single internet-facing port, then your options are not user-friendly:

  • Tunnelling (e.g: VPN / SSH / SOCKS) - users will need to setup software on their side. Once connected, they can connect to the actual Minecraft server. NOTE: this will also likely impact the playability (i.e: increased latency)
  • Source based packet routing - each user can access one server, but they may see a different server depending on where that user is connecting from.

I recommend that you listen on multiple ports.

Solution 2:

You can try to do with Bind9 of Linux (I used Debian with raspberrypi [Raspbian]) with the SVR Records.

  • Install Bind9 in Linux: sudo apt-get install bind9 bind9-doc -y
  • And restart the daemon of Bind9 when it finished to install: /etc/init.d/bind9 restart

You need to do your first Domain, for to do it you need do this:

zone "origensone.net" {
        type master;
        file "/var/lib/bind/origensone.net.hosts";
};

The up text is the config file link of this domain DNS database. (This is that you need enter in the file what I tell you to continue)
For example my domain in this way is: origensone.net

FILE: /etc/bind/named.conf.local
//
// Do any local configuration here
//

// Consider adding the 1918 zones here, if they are not used in your
// organization
//include "/etc/bind/zones.rfc1918";

// This is a new area for our domain:
zone "origensone.net" {
        type master;
        file "/var/lib/bind/origensone.net.hosts";
};
  • The file "/var/lib/bind/origensone.net.hosts"; is where are the DNS with the SubDomains, is how a DNS database of this domain and subdomains, ALIAS, CNAMEs, etc.

This is how I have my Minecraft Servers in my local DNS Server:

FILE: /var/lib/bind/origensone.net.hosts
$ttl 3600
origensone.net.    IN    SOA    DnsServer. (
            1616892692 ; Serial
            3600 ; Refresh
            600 ; Retry
            1209600  ; Expire
            3600 ) ; Minimum
origensone.net.    IN    NS    DnsServer. ; --// DnsServer is the hostname of the machine == 127.0.0.1 or 192.168.1.10 == DnsServer.local //--
origensone.net.    IN    A    <PublicIP (of IP Router)>

; --// Subdomain to IP Directions: //--
dnsservidor        IN    A    <PrivateIP-1_for_DNSServerHosting> ; --// 192.168.1.10 for example for the DNSServer. //--
mcservidor        IN    A    <PrivateIP-2_for_MinecraftServerHosting>  ; --// 192.168.1.11 for the server of minecraft hosting servers. //--
mcservidortorouter        IN    A    <PublicIP (of IP Router)>

; --// The Canonical Names: //--
mcmods                    IN    CNAME    mcservidor
mcsurvi                    IN    CNAME    mcservidor

; --// This're the SVR records: //--
_minecraft._tcp.mcsurvi.origensone.net. SRV 0 5 25566 mcservidortorouter.origensone.net. 
_minecraft._tcp.mcmods.origensone.net. SRV 0 5 25567 mcservidortorouter.origensone.net.

_service._protocol.name. TTL Class SRV Priority Weight Port Target: _minecraft._tcp.mcsurvi.origensone.net. SRV 0 5 25566 mcservidortorouter.origensone.net.

  1. _service = _minecraft
  2. _protocol.name = _tcp
  3. TTL is same of Time to Live (Is in Default).
  4. Class = mcsurvi.origensone.net
  5. SRV
  6. Priority = 0
  7. Weight = 5
  8. Port = 25566
  9. Target → mcservidortorouter.origensone.net.

The localhost is the IP: 127.0.0.1

This is a example in SVR records; In this case I'm using two subdomains in ALIAS for can get the two servers: origensone.net (domain):

  1. mcsurvi (subdomain) → For survival = mcsurvi.origensone.net
  2. mcmods (subdomain) → For mods = mcmods.origensone.net

When you'll have this with Bind9 DNS Server and the all parts completed, find the instructions here for confirmed what works good the DNS to Port here!.

Or when you finished for confirm that's all good, you need to do this:

  1. In a terminal of Linux put this commands:
  • nslookup
     # Press Enter.
    set query=srv
    _minecraft._tcp.mcsurvi.origensone.net
    

This is in Windows CMD: [The grey spaces are my Public IP for that are censured] enter image description here

This is in Raspbian (DnsServer.): [Grey block is my name for that is censured] enter image description here

For try to do this you can do it in the same server or in other computer that have that DNS Server Connected in the NetworkCard of that Host).

And IF this works, when we will go to do a PING to this subdomain.domain the console give to our the ping correctly of 192.168.1.11 or that's same the IP of Minecraft Hosting Server.