It's not actually that hard of a problem to solve (I too, am a programmer). Auto-discovery systems function in one of two ways - either they do an L2 broadcast stating that the exist (as is the case with DHCP) or they do an L3 broadcast (IP-level on the broadcast IP of the current network). Clients listen for certain packet patterns.
That broadcast traffic can contain any kind of information - the client just has to be looking for it and it has to know how to interpret the contents.
So either the server is only broadcasting the IP and the client is responsible for trying to connect to the default ports on the target IP, or the server is already broadcasting IP:port and the client is not gathering the "port" part and is only trying to hit the default ports.
But you're right, it's a minor inconvenience. Having the output of this discussion, though, in the documentation would be useful.
@Jeremy Gamble - thanks for your previous post, it caused me to go back and take another look and things make a lot more sense now. I think that the reason that an instance opens the default ports is so the client (game) can auto-discover the server.
I tried starting two servers (as you suggest) and they do both start. However, only one server is discovered by the client.
To test this I did the following....
1. As root: disable firewall on server
root@server1:~# iptables -F; iptables -X; iptables -Z
root@server1:~# iptables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destinationChain FORWARD (policy DROP)
target prot opt source destinationChain OUTPUT (policy ACCEPT)
target prot opt source destination
2. As root: create user "minecraft" in /home/minecraft
adduser minecraft
3. As root: become user minecraft:
su - minecraft
4. As minecraft: create server directories
mkdir ~/s1 ~/s2
5. As minecraft: unzip server to ~/s1
unzip bedrock-server-1.14.32.1.zip -d ~/s1/
6. As minecraft: Unzip server to ~/s2
unzip bedrock-server-1.14.32.1.zip -d ~/s2/
7. Change server-name, levels-name and ports per the following:
minecraft@server1:~$ egrep "server-name|level-name|.*-port" s[12]/server.properties
s1/server.properties:server-name=Server1
s1/server.properties:server-port=19100
s1/server.properties:server-portv6=19101
s1/server.properties:level-name=level1
s2/server.properties:server-name=Server2
s2/server.properties:server-port=19200
s2/server.properties:server-portv6=19201
s2/server.properties:level-name=level2
8. Start server in ~/s1
minecraft@Server1:~$ cd s1
minecraft@Server1:~/s1$ LD_LIBRARY_PATH=. ./bedrock_server
NO LOG FILE! - setting up server logging...
[2020-04-03 10:01:24 INFO] Starting Server
[2020-04-03 10:01:24 INFO] Version 1.14.32.1
[2020-04-03 10:01:24 INFO] Session ID 0ec216b4-56b7-4d96-aea5-8b3f249b608c
[2020-04-03 10:01:24 INFO] Level Name: level1
[2020-04-03 10:01:24 INFO] Game mode: 0 Survival
[2020-04-03 10:01:24 INFO] Difficulty: 1 EASY
[2020-04-03 10:01:24 INFO] opening worlds/level1/db
[2020-04-03 10:01:25 INFO] IPv4 supported, port: 19100
[2020-04-03 10:01:25 INFO] IPv6 supported, port: 19101
[2020-04-03 10:01:25 INFO] IPv4 supported, port: 19132
[2020-04-03 10:01:25 INFO] IPv6 supported, port: 19133
[2020-04-03 10:01:26 INFO] Server started.
9. Start server in ~/s2
minecraft@server1:~$ cd s2/
minecraft@server1:~/s2$ LD_LIBRARY_PATH=. ./bedrock_server
NO LOG FILE! - setting up server logging...
[2020-04-03 10:02:02 INFO] Starting Server
[2020-04-03 10:02:02 INFO] Version 1.14.32.1
[2020-04-03 10:02:02 INFO] Session ID 15140ceb-984e-4cdc-befa-91b64643b06f
[2020-04-03 10:02:02 INFO] Level Name: level2
[2020-04-03 10:02:02 INFO] Game mode: 0 Survival
[2020-04-03 10:02:02 INFO] Difficulty: 1 EASY
[2020-04-03 10:02:02 INFO] opening worlds/level2/db
[2020-04-03 10:02:04 INFO] IPv4 supported, port: 19200
[2020-04-03 10:02:04 INFO] IPv6 supported, port: 19201
[2020-04-03 10:02:04 INFO] IPv4 supported, port: 60796
[2020-04-03 10:02:04 INFO] IPv6 supported, port: 57886
[2020-04-03 10:02:05 INFO] Server started.
10. Look at the open ports:
root@server1:~# netstat -plan | egrep bedrock_ser
udp 0 0 0.0.0.0:19100 0.0.0.0:* 18760/./bedrock_ser
udp 0 0 0.0.0.0:19132 0.0.0.0:* 18760/./bedrock_ser
udp 0 0 0.0.0.0:19200 0.0.0.0:* 18794/./bedrock_ser
udp 0 0 0.0.0.0:60796 0.0.0.0:* 18794/./bedrock_ser
udp6 0 0 :::57886 :::* 18794/./bedrock_ser
udp6 0 0 :::19101 :::* 18760/./bedrock_ser
udp6 0 0 :::19133 :::* 18760/./bedrock_ser
udp6 0 0 :::19201 :::* 18794/./bedrock_ser
11. Try to join the servers....
12. Kill Server1 process - Server 1 disappears from the list and server2 does not appear.
13. Kill Server2 process and then start ONLY Server 2
minecraft@cyclone:~/s2$ LD_LIBRARY_PATH=. ./bedrock_server
NO LOG FILE! - setting up server logging...
[2020-04-03 10:17:42 INFO] Starting Server
[2020-04-03 10:17:42 INFO] Version 1.14.32.1
[2020-04-03 10:17:42 INFO] Session ID 9362f75d-a13a-4825-a79b-641502d8fe4a
[2020-04-03 10:17:42 INFO] Level Name: level2
[2020-04-03 10:17:42 INFO] Game mode: 0 Survival
[2020-04-03 10:17:42 INFO] Difficulty: 1 EASY
[2020-04-03 10:17:42 INFO] opening worlds/level2/db
[2020-04-03 10:17:44 INFO] IPv4 supported, port: 19200
[2020-04-03 10:17:44 INFO] IPv6 supported, port: 19201
[2020-04-03 10:17:44 INFO] IPv4 supported, port: 19132
[2020-04-03 10:17:44 INFO] IPv6 supported, port: 19133
[2020-04-03 10:17:45 INFO] Server started.
14. Start Server 1 Process:
minecraft@cyclone:~/s1$ LD_LIBRARY_PATH=. ./bedrock_server
NO LOG FILE! - setting up server logging...
[2020-04-03 10:19:18 INFO] Starting Server
[2020-04-03 10:19:18 INFO] Version 1.14.32.1
[2020-04-03 10:19:18 INFO] Session ID 5c66f904-53d4-4109-bb18-b0ec64399fdf
[2020-04-03 10:19:18 INFO] Level Name: level1
[2020-04-03 10:19:18 INFO] Game mode: 0 Survival
[2020-04-03 10:19:18 INFO] Difficulty: 1 EASY
[2020-04-03 10:19:18 INFO] opening worlds/level1/db
[2020-04-03 10:19:20 INFO] IPv4 supported, port: 19100
[2020-04-03 10:19:20 INFO] IPv6 supported, port: 19101
[2020-04-03 10:19:20 INFO] IPv4 supported, port: 41620
[2020-04-03 10:19:20 INFO] IPv6 supported, port: 36583
[2020-04-03 10:19:21 INFO] Server started.
16. Check minecraft again....
So only one server is automatically discoverable at a time and this is probably because the first server that starts binds to the default ports 19132/19133.
You can go to the third tab in the client (Servers) and click "Add Server" and manually add the IP/port in there.
Note: The screenshots, above, are taken from the windows client. However, I also tried this on the Android client as well.
So, actually, in terms of being able to do what I wanted to be able to do (run multiple servers / worlds) from the same server, it turns out that I can do that. I was simply assuming (you know what they say about assumptions) that because the first process was binding to the default ports, that the second one would not start - which turns out not to be the case as the server just "picks different ports" to randomly open.
I do agree that randomly opening LISTEN ports is both undocumented and undesirable. It would be beneficial for us to understand why those ports are being opened, and what they are used for. (others have mentioned UPnP as a possibility).
Similarly, it would be beneficial for the auto-discover mechanism to be a bit more intelligent. I don't know how it works but based on what I'm observing here (and please note, I've not done any kind of deep packet inspection see what's happening), I'm guessing that the server does a network broadcast saying "I am a minecraft server - this is my IP" and the client checks that IP against the default ports, rather than the server saying "I am a minecraft server, this is my IP and port". Or maybe it does and the client's have a bug in them that they only check the default ports - I'm not sure. Either way, this process could be improved.
@Rebecca Reed - there are two bugs here that have been merged into one (IMHO, wrongly). I came here because BDS-2824 and BDS-3397 have been marked as duplicates of this one. But I am working with what I've got so....
According to the documentation (https://minecraft.gamepedia.com/Server.properties):
server-port=19132
# Which IPv4 port the server should listen to.
# Allowed values: Integers in the range [1, 65535]
server-portv6=19133
# Which IPv6 port the server should listen to.
# Allowed values: Integers in the range [1, 65535]
Ergo, per the documentation, if I change those values to something other than the default, then the server should listen on those ports.
But... according to the output, above, the server is, first, binding to my custom-defined in server.properties ports (ipv4: 19232, ipv6: 19233),. Hurray!
... And THEN it is binding to the default ports (ipv4: 19132, ipv6:19133). Booo!!!
This means I can only run a single bedrock_server instance on my hardware And because I can only serve a single world from a bedrock server instance, that means that I can only have a single world running on my home server (which is a real ballache when you have multiple kids that each want their own world).
OS: Ubuntu 18.04.4 LTS
This is what I'm seeing...
minecraft@server1:~/bedrock_server$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.4 LTS"
minecraft@server1:~/bedrock_server$ grep port server.properties | sed -e 's/^#.*//g' | grep -v ^$
server-port=19232
server-portv6=19233
minecraft@server1:~/bedrock_server$ LD_LIBRARY_PATH=. ./bedrock_server
NO LOG FILE! - setting up server logging...
[2020-04-02 12:51:37 INFO] Starting Server
[2020-04-02 12:51:37 INFO] Version 1.14.32.1
[2020-04-02 12:51:37 INFO] Session ID ed6a96e2-f484-42bd-b52b-274418abb2aa
[2020-04-02 12:51:37 INFO] Level Name: World Name
[2020-04-02 12:51:37 INFO] Game mode: 1 Creative
[2020-04-02 12:51:37 INFO] Difficulty: 2 NORMAL
[2020-04-02 12:51:37 INFO] opening worlds/World Name/db
[2020-04-02 12:51:39 INFO] IPv4 supported, port: 19232
[2020-04-02 12:51:39 INFO] IPv6 supported, port: 19233
[2020-04-02 12:51:39 INFO] IPv4 supported, port: 19132
[2020-04-02 12:51:39 INFO] IPv6 supported, port: 19133
[2020-04-02 12:51:40 INFO] Server started.
^Z
[1]+ Stopped LD_LIBRARY_PATH=. ./bedrock_server
minecraft@server1:~/bedrock_server$ bg
[1]+ LD_LIBRARY_PATH=. ./bedrock_server &
minecraft@cyclone:~/bedrock_server$ netstat -plan | grep :19[12]3[23]
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
udp 0 0 0.0.0.0:19132 0.0.0.0:* 6674/./bedrock_serv
udp 0 0 0.0.0.0:19232 0.0.0.0:* 6674/./bedrock_serv
udp6 0 0 :::19133 :::* 6674/./bedrock_serv
udp6 0 0 :::19233 :::* 6674/./bedrock_serv
So some part of the code is hard-coding those port values - at least in the linux branch of the code.
Correct, that's the conclusion that we've come to...
The first server that you start, no matter which ports you choose, will always open up on UDP:19132/19133 because these are the ports that are used for game discovery on the local network. You have no choice.
You can block them with a firewall [if you like] and it just means that you won't be able to discover the game automatically through the client - you'll need to specificy the IP:port in the "custom server" screen.
If you are hosting multiple servers on your system (like I do) and you do want ONE of them to be auto-discoverable, you must start that instance before any others (so it grabs the ports).
Unfortunately, there really is no way to work around this... bedrock server has no "server-ip" config (like Java edition did) to force binding to a single IP (ie - if your server had a bunch of VIPs, one for each server instance).
In java edition, you could specify "server-ip=10.1.1.10" ; but bedrock forces a bind of the port to 0.0.0.0.
From a product perspective, a better solution for this would be to have a registry process (which is independent from the server) listen on those ports and then have the mc servers register their existence with the that port at startup. However, having not seen the code, I suspect that would be an architectural change and my guess is that the client only expects to have a single server per host. It would also open up some security issues/concerns if that registry process didn't do some kind of IP authentication before accepting the record.
However, at the end of the day, not that many people have participated in this thread and highlighted it as an issue. My guess is that the PM/Dev team have marked this as "low priority - do not fix" because it will not end in global thermonuclear meltdown, and it's really only inconveniencing a few of us.