Unity多人扑克类游戏部署至DigitalOcean Droplet:Ubuntu16.04端口开放求助
Hey there! Let's walk through how to open the necessary ports on your DigitalOcean Ubuntu 16.04 Droplet for your Unity multiplayer poker game using Master Server Kit. I’ll break this down into simple, actionable steps since you mentioned you’re new to server management—no jargon overload, promise!
First things first: you need to know exactly which ports your Master Server Kit and Unity game are using.
- Check your Master Server Kit configuration files or settings panel. Common defaults are
23466(for the master server, handling room creation/player joins) and23467(for the game server, handling in-game traffic), but don’t assume—verify your setup. - Unity’s default multiplayer port is often
7777, so double-check if your game uses that too.
Ubuntu 16.04 comes with UFW (Uncomplicated Firewall) pre-installed, and it’s super straightforward to use. Here’s what to do:
- First, enable UFW if it’s not already running:
You’ll get a warning about disrupting existing connections—just confirm withsudo ufw enableyif you’re sure you want to proceed. - Allow incoming traffic for your game ports. Replace
<PORT>with the actual numbers you found in Step 1. For example, if you’re using 23466 and 23467:# Allow TCP for master server (handles room/join requests) sudo ufw allow 23466/tcp # Allow UDP for game server (faster in-game traffic) sudo ufw allow 23467/udpPro tip: If you’re unsure which protocol (TCP/UDP) your server uses, you can allow both for each port to cover your bases:
sudo ufw allow 23466/tcp sudo ufw allow 23466/udp sudo ufw allow 23467/tcp sudo ufw allow 23467/udp - Verify the rules are applied correctly by checking UFW’s status:
You should see your allowed ports listed in the output—this means traffic can now flow through those ports.sudo ufw status
DigitalOcean has its own cloud-level firewall that adds another layer of protection on top of UFW. It’s optional but highly recommended:
- Log into your DigitalOcean control panel, go to your Droplet’s page.
- Click the "Firewalls" tab, then hit "Create Firewall".
- Name your firewall something descriptive, like "Game Server Firewall".
- Under "Inbound Rules", add new rules for each port:
- For TCP ports: Select "TCP" as the protocol, enter the port number in "Port Range", and set "Sources" to "Anywhere" (so anyone can connect to your game).
- For UDP ports: Do the same, but select "UDP" as the protocol.
- Attach the firewall to your Droplet, then save the changes.
Now that the ports are open, you need to point your game to your Droplet’s public IP instead of the local Unity IP:
- In your Master Server Kit settings, replace the local IP (like
127.0.0.1or your home LAN IP) with your Droplet’s public IP address (you can find this in your DigitalOcean control panel). - Make sure all client builds are configured to connect to this public IP and the correct ports you opened.
If you run into issues connecting from a remote client:
- Double-check UFW’s status with
sudo ufw statusto ensure your port rules are active. - Use this command to confirm your Master Server is actually listening on the right ports:
You should see your server process listed here—if not, your server might not be running correctly.sudo netstat -tulpn | grep <PORT_NUMBER> - Ensure you don’t have other firewall tools (like iptables) running that could block traffic. UFW is the default for Ubuntu 16.04, but if you installed something else, you’ll need to configure that too.
内容的提问来源于stack exchange,提问作者Tabi

