At the TCP/IP stack level, a network socket is uniquely identified by the combination of four elements: source IP, source port, destination IP, and destination port. This means you can indeed run multiple services on the same port number if they're bound to different IP addresses on the same machine.
Here's how to bind services to specific IP addresses in different programming languages:
// Python example using sockets
import socket
# First service on 192.168.1.100:25565
sock1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock1.bind(('192.168.1.100', 25565))
# Second service on 192.168.1.101:25565
sock2 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock2.bind(('192.168.1.101', 25565))
// Node.js example
const net = require('net');
// First server
const server1 = net.createServer();
server1.listen(25565, '192.168.1.100');
// Second server
const server2 = net.createServer();
server2.listen(25565, '192.168.1.101');
Before implementing this solution, ensure your system meets these requirements:
- Multiple IP addresses assigned to the network interface (using IP aliasing or multiple interfaces)
- Sufficient file descriptors limit (especially important for game servers)
- Proper firewall rules for each IP-port combination
Verify your configuration using these commands:
# Linux/MacOS
netstat -tulnp | grep 25565
ss -tulnp | grep 25565
# Windows
netstat -ano | findstr 25565
When running multiple game servers on the same machine:
- Monitor CPU and memory usage carefully
- Consider using cgroups or containers for resource isolation
- Adjust kernel parameters like net.ipv4.ip_local_port_range if needed
Watch out for these issues:
- Accidentally binding to 0.0.0.0 (all interfaces) instead of specific IPs
- Port conflicts with ephemeral ports
- Application-level restrictions in server software
Yes, it's absolutely possible to run multiple services on the same port using different IP addresses on a single machine. This is a fundamental networking concept where ports are bound to IP address + port combinations, not just ports alone.
The TCP/IP stack identifies connections using the quadruple: source IP, source port, destination IP, and destination port. This means:
192.168.1.100:25565 (Game Server A)
192.168.1.101:25565 (Game Server B)
are treated as completely separate endpoints by the networking stack.
Here's how to configure this in Linux using multiple IPs on one interface:
# Add secondary IP address
sudo ip addr add 192.168.1.101/24 dev eth0
# Verify the IP is added
ip addr show eth0
For game servers, you need to explicitly bind to specific IPs:
import socket
# Server 1
server1 = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server1.bind(('192.168.1.100', 25565))
# Server 2
server2 = socket.socket(socket.AF_INET, socket.SOCK.SOCK_STREAM)
server2.bind(('192.168.1.101', 25565))
Each IP address has its own complete port space (0-65535). The network interface simply routes traffic based on the destination IP. This means:
- You can have service A on IP1:80
- Service B on IP2:80
- Service C on IP1:443
- All simultaneously on the same interface
This technique is frequently used for:
- Hosting multiple game servers
- Web hosting with SSL certificates
- Development environments
- Load testing scenarios
If you encounter issues:
# Check port binding
sudo netstat -tulnp | grep 25565
# Verify IP configuration
ip route show