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 2 servers with (of course :D) 2 IP's, for example:

123.456.789.101 & 101.987.654.321

Now I have a domain example.tld and want all requests go to 123.456.789.101, except the ones which hit port 12345. These should be sent to 101.987.654.321. How do I do that? I haven't found a solution which worked yet.

share|improve this question

closed as off-topic by joeqwerty, Iain, kasperd, mdpc, MadHatter May 25 at 7:43

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions must demonstrate a minimal understanding of the problem being solved. Try including attempted solutions, why they didn't work, and the expected results. See How can I ask better questions on Server Fault? for further guidance." – joeqwerty, Iain, MadHatter
If this question can be reworded to fit the rules in the help center, please edit the question.

5  
DNS doesn't do that. –  Michael Hampton May 24 at 18:22
    
You need to go and read up on how DNS works. –  Iain May 24 at 18:25

2 Answers 2

up vote 0 down vote accepted

You could use a simple nat rule in iptables of server 123.456.789.101, instead: Think of enabling ip forwarding first.

sysctl net.ipv4.ip_forward=1
iptables -t nat -A PREROUTING -p tcp --dport 12345 -j DNAT --to-destination 101.987.654.321:12345
iptables -t nat -A POSTROUTING -j MASQUERADE
share|improve this answer

Are your 2 servers behind the same router/Internet connection, or in two separate locations?

If they are behind the same router/Internet connection, you could use PAT (Port Address Translation) or VIP (Virtual IP) on your firewall/router to direct different ports on your public IP address to different servers/ports inside your private network. If they're not behind the same connection, you will need to use different subdomains, like ftp.example.tld could be hosted in one place and www.example.tld could be somewhere completely different.

share|improve this answer

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