0

My configuration:

  • Debian 8.6

  • VirtualBox with 5 VM's

  • 5 different domain names (domain1.com, domain2.com, domain3.com ...)

  • One static/public IP (195.113.xxx.yyy)

  • Server is in private network, public IP forwards all traffic to private IP of server

I need to point domain1.com >>> virtualbox VM1, domain2.com >>> virtualbox VM2

So:

  • when I ssh root@domain1.com -> I'm connecting to VM1 (sshd setup is not part of my question)

  • when I put domain1.com to browser I got result from apache on VM1 (apache setup is not part of my question)

Many thanks for you answer, I hope I wrote it as clear as possible :)

2

This doesn't work like that. TCP connections such as SSH and HTTP are established over IP and IP is layer 3, domain names are way beyond that, so you can't just say "send all traffic to that domain name to this VM".

You can use a reverse proxy for websites though: https://en.wikipedia.org/wiki/Reverse_proxy

For example, Apache can do this, you have to have it running on your host with the external IP.

Example:

<VirtualHost *:*>
  ProxyPreserveHost On
  ProxyPass / http://192.168.0.2/  #internal IP of your 1st domain
  ProxyPassReverse / http://192.168.0.2/ #internal IP of your 1st domain
  ServerName domain1.com
</VirtualHost>
<VirtualHost *:*>
  ProxyPreserveHost On
  ProxyPass / http://192.168.0.3/  #internal IP of your 2nd domain
  ProxyPassReverse / http://192.168.0.3/ #internal IP of your 2nd domain
  ServerName domain2.com
</VirtualHost>

If you want to use https keep in mind that you'll have to use SNI (which most but not all clients support).

For better understanding with pictures: http://iws.io/multiple-web-servers-over-a-single-ip-using-apache-as-a-reverse-proxy/

|improve this answer|||||
  • What do you think about using reverse DNS? – ememem Sep 22 '16 at 11:59
  • It is possible to do this with dnsmasq's ipset feature and iptables rules. You would be looking to do effectively this in reverse: marcschwieterman.com/blog/bypass-vpn-by-hostname I suggest this is massively bad idea and very fragile thou – Tim Fletcher Sep 22 '16 at 11:59
  • So what's the options when I got just one public IP and many VPSs with each domain name assigned? – ememem Sep 22 '16 at 12:01
  • @ememem As I said, if you want to use the machines for HTTP you can use what I posted in my answer, it might be available for other applications you use aswell but Domain Names do not impact a TCP connection. Reverse DNS has nothing to do with your problem, Reverse DNS gives you a domain name when you ask for an IP. What you want to do is to route traffic to internal IPs depending on the Domain Name that was requested. – Broco Sep 22 '16 at 12:08
-2

You have to use port forwarding . suppose vm1 ip is 192.168.1.5 . so you should forward port 80(http) and port 22(ssh) to 192.168.1.5 from your public ip(195.113.xxx.yyy). Do this for all vms. make host entry in /etc/hosts of your main server 192.168.1.5 domain1.com, so if you hit domain1.com it goes to 192.168.1.5

|improve this answer|||||
  • This won't work. Forwarding rules aren't domain based. Try what you posted and see for yourself. While you will connect to 192.168.1.5 from your HOST when you type in domain1.com, the host won't forward external requests to that ip. – Broco Sep 22 '16 at 12:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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