Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a game server on Centos 6.3 which has a single static IP, but hosts 3 different games, each on a different port. Port 4000 is the game's default query port and I host instances on subsequent ports.

At the moment, players have to connect to each game by typing an IP/hostname and a port, like so:

  • 123.123.123:4001 or server1.mygame.com:4001 for game 1
  • 123.123.123:4002 or server2.mygame.com:4002 for game 2
  • 123.123.123:4003 or server3.mygame.com:4003 for game 3

What I'd like to do is make it so that players don't need to type the ports, and only have to remember the hostnames:

  • server1.mygame.com for game 1
  • server2.mygame.com for game 2
  • server3.mygame.com for game 3

I understand that this (port redirection/forwarding) isn't possible using only DNS A-Records or whatever. So I set up Apache to listen on the default query port for the game, and used name-based virtual hosts to attempt to 301 Redirect connections to their appropriate ports. E.g. a vhost name matching server1.mygame.com was 301'd to port 4001.

This worked in the browser - I saw the redirects working fine! But sadly it didn't work in the game. My guess is the game can't follow 301 redirects. I also tried a reverse-proxy through Apache but this also failed.

So I'm wondering if there's any way to set up name-based port forwarding without using Apache.

Summary:

Basically I need these rules put into place somehow:

Connection to 123.123.123 established on port 4000 (query port).
If the hostname is "server1.mygame.com" --> forward to 4001.
If the hostname is "server2.mygame.com" --> forward to 4002.
If the hostname is "server3.mygame.com" --> forward to 4003.

All without Apache or 301 redirects.

Is this possible?

share|improve this question

closed as off topic by Zoredache, Michael Hampton, Ward, Scott Pack, MikeyB Sep 24 '12 at 16:44

Questions on Server Fault are expected to relate to professional server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer 1

up vote 1 down vote accepted

There is no such concept as a "name" in TCP and UDP protocols, so you can't do that.

Alternatives are to implement the name thing at the application level protocol (eg. like in HTTP 1.1) or to use different IP addresses or different TCP/UDP ports.

Unless your game is speaking HTTP the whole Apache thing you put in place is useless, as Apache is an HTTP server. And if your game claims to speak HTTP then it must understand Redirects... otherwise it is just a partial, unfinished, HTTP client.

(Apache can serve other protocols too, but this is irrelevant here)

share|improve this answer
    
Fair enough. That makes sense. However is there no application which could do this? Obviously, the hostname is "getting through" to the server (because Apache can receive it and determine which hostname was typed). So it seems relatively trivial to me to be able to identify/separate the hostname from the TCP/UDP request and act on that somehow. No? –  Stephen Mulligan Sep 11 '12 at 19:15
    
No. As I already wrote the hostname is "getting through" (in the browser/apache example) thanks to the HTTP protocol, it does not get through at the UDP or TCP level. Does your game communicate over HTTP? If not, it has to implement name-based routing explicitly because the underlying protocols (TCP and UDP) do not. –  Luke404 Sep 11 '12 at 19:17
    
Ahh I see. So the game is most likely resolving the hostname before it makes a [non-HTTP] request? In that case, is there any way of intercepting and examining the packets that the game sends to my server so I can see what information I have to work with? –  Stephen Mulligan Sep 11 '12 at 19:18
    
Yes, that's how TCP/IP networks work. There are plenty of packet sniffers out there, you could start by reading tcpdump's man page. –  Luke404 Sep 11 '12 at 19:19
    
Great, thanks! It's slightly frustrating that there's nothing that can be done at the DNS level. I feel like it's a shame that the game "has" the hostname but "throws it away" to make the IP lookup before making the request. I know that's how the TCP/IP protocol works but... kinda frustrating that we have to buy separate IPs or whatever to achieve the simple thing I'm trying to do here. Thank you anyway! –  Stephen Mulligan Sep 11 '12 at 19:24

Not the answer you're looking for? Browse other questions tagged or ask your own question.