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 would like to know how to do the following.

I would like so, when you connect to a domain example.com - it'll forward that to lets say 15.46.43.33:26046 (This is for a game, not Apache). Is this possible with IPTables, or any other software for Linux (CentOS 6.2)? - Appreciate it :)

share|improve this question
    
Please define "connect" –  S19N Aug 8 '12 at 10:10
    
Like, connect to server - for this example, the game. So they would connect to the server, so they can play. –  Daniel Aug 8 '12 at 10:33

2 Answers 2

up vote 0 down vote accepted

I think you need a domain (example.com in your example) and a DNS A record to associate the hostname to its IP address. If you're on a home DSL connection you may want to check a dynamic DNS service (Google for it) which will update the hostname/IP address association when it changes.

Not really sure this fits ServerFault, though.

share|improve this answer
    
I already have the domain, and it's a dedicated server hosted in a datacenter - all ports are open, so that's not the issues. The domain is already ported to the IP. All I need is the IPTables "command" or what ever it's called - for it to work. –  Daniel Aug 8 '12 at 10:47
    
So start your game server (check with sudo netstat -putan its port is open) and connect to it ("example.com:26046" as you say). I don't see any need to forward. –  S19N Aug 8 '12 at 10:49
    
I can connect perfectly to my server, the issue is that my users need to type the port, and that can get annoying after some time. –  Daniel Aug 8 '12 at 11:03
    
So the client tries to connect to a default port which is different than the one used by your server? And you cannot run the game server at the default port? –  S19N Aug 8 '12 at 11:07
    
I have many servers I host, and they all can't be on default port. And the issue is that you need to type the port, I would like so you type a hostname such as server1.example.com & then it would connect to: 13.414.5.3:13634. –  Daniel Aug 8 '12 at 11:34

Yes this is possible with iptables or any higher level iptables configuration software, say, shorewall. Of course you should point that domain to the Linux router you can control (e.g. login as root).

share|improve this answer
    
Already done :) Can you show an example? Thanks :) –  Daniel Aug 8 '12 at 10:48
    
Hmm, it looks like your software resides on the same server your domain points to (from your comment above), is that true? There are two different iptables commands for forwarding the port to the same server and to the other server. –  Alex Aug 8 '12 at 10:55
    
The domain is pointing at the server, that the game-server is hosted on, and IPTables is on that as well. So, yes that's true. –  Daniel Aug 8 '12 at 11:04
    
Why don't you just listen on that port without a redirection then? Anyway iptables -t nat -A PREROUTING -i eth0 -p tcp --dport $srcPortNumber -j REDIRECT --to-port $dstPortNumber should help. Please substitute eth0, $srcPortNumber and $dstPortNumber with real values. –  Alex Aug 8 '12 at 11:09
    
Almost it! It just need to be a domain name, instead of a port, so I would connect to something.com & it'll redirect that to 10.256.24.21:25754 (example). –  Daniel Aug 8 '12 at 11:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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