I now have a working solution which i want to share here for others wanting to protect their linux Minecraft server with Spectrum.
-
Add your DNS to Cloudflare
-
Create 2 subdomains, for the example i will have java.subdomain.com and bedrock.subdomain.com
-
Added java.subdomain.com to spectrum
-
Create an A record for bedrock.subdomain.com to the servers Public IP
-
Create a SVR, it would be something like _minecraft._udp.bedrock.subdomain.com pointing to bedrock.subdomain.com on 19132. Priority 0 and Weight 5
-
Setup your linux firewall to allow allow in port 25565 on TCP for all the cloudflare IPs as people will connect through cloudflare spectrum. Deny everywhere else on 25565. Deny 25565 for subdomain bedrock.subdomain.com and allow all for your bedrock port 19132
This might seem confusing but the idea here is people can connect on Minecraft java client using java.subdomain.com which is pushed though cloudflare spectrum servers. But players cannot be sneaky and connect on java clients through bedrock.subdomain.com on 25565
All connects through bedrock.subdomain.com is allowed on bedrock client as its pushed through geyser on 19132 only.
The trick here is linux looks at rules in order of number, you need to get this right.
I set deny to 25565 on bedrock.subdomain.com as rule 2 and then after that allowed all cloudflare ips. Then after that i denied 25565 to anywhere.
To add all the cloudflare ips to the firewall you can use a script like this
for cfip in $(curl -s https://www.cloudflare.com/ips-v4 https://www.cloudflare.com/ips-v6); do
sudo ufw allow proto tcp from $cfip to any port 25565 comment 'Cloudflare IP';
done
Im sure if you're doing this, you have enough knowledge to work out the firewall rules yourself and test it.
I also had to ping java.subdomain.com in cmd and then find the IP cloudflare was giving it and add it to the cloudlfare IPs as allow in the firewall.
Once i completed all this i found in the java client the server i added under java.subdomain.com was available but the server under bedrock.subdomain.com i added was not.
I could also connect to the server through bedrock without issue on bedrock.subdomain.com. java.subdomain.com wont work on default as geyser uses 19132.
Their isn't much information out there on this so i hope this guide helps you out.