marcel
By:
marcel

How to setup srv1.domain.com, srv2.domain.com with mutliple domains per VPS

September 11, 2014 3.4k views

Hi,

I want to setup this:
VPS 1: hostname srv1.mydomain.com
VPS 2: hostname srv2.mydomain.com

On both VPS-es I want to host like maximum 5 websites.
For all the websites I want mailserver per site. Like mailserver hostname is: mail.website1.com and for the second website on VPS 1 it would be mail.website2.com.

I know how to setup a VPS with mutliple domains (done this using VirtualMin), but how to set up multiple VPS-es where the hostname is a subdomain / hostname of my purchased domain (srv1. or srv2, etc.). How would I setup mail correctly per server?

I now was thinking about this as DNS for mydomain.com:
srv1.mydomain.com points to Droplet 1 (A record)
srv2.mydomain.com points to Droplet 2 (A record)

In DOs DNS manager I have set-up a add a new website for every website on srvX. The A records of this website redirects to either VPS1 or VPS2 depending on what srvX the website is on.

This seems to work, but now: how to setup mail? (just the DNS settings, I already set up mailservers with postfix and dovecot)

Should I just add mail.websiteX.com per website, which points to a specific VPS?
Because I have read that the VPS name has to be the mailserver name for the PTR record to setup correctly. That would make it impossible to add multiple mail.websiteX records?

Thanks!

1 Answer

On DO environment you have many ways to do this... but I list two

you need to choose the default VPS-es domain...
Pratic example

VPS1
vps1.domain1.com

VPS2
vps2.domain1.com

When you rename your vps to this names automatically this point to your vps IP, this is PTR record

vps1.domain1.com PTR xxx.xxx.xxx.xxx
vps2.domain1.com PTR xxx.xxx.xxx.xxx

When you create DNS records for domains like:

domain1.com MX 5 vps1.domain1.com
domain2.com MX 5 vps1.domain1.com
domain3.com MX 5 vps1.domain1.com

domain4.com MX 5 vps2.domain1.com
domain5.com MX 5 vps2.domain1.com

AND TXT SPF records you use something like "v=spf1 mx ~all"
this allow vps1 hosts to send mail for your domains.
Are necessary? Not, but prevents that messages will be marked as spam.

Other way to do this are:

domain1.com MX 5 mail.domain1.com
domain2.com MX 5 mail.domain2.com
domain3.com MX 5 mail.domain3com

domain4.com MX 5 mail.domain4.com
domain5.com MX 5 mail.domain5.com

And yours respectives "A" records
and TXT SPF record something like "v=spf1 ip:xxx.xxx.xxx.xxx ~all" or "v=spf1 include:vps1.domain1.com ~all"

A think thats help you!

Regards

  • Awesome, thanks a lot for this. I think I got it and I must get it working using this.

    Two questions more though:

    1. For the first option, what would my mailserver be for example to use in a mailclient? Because there are no A records for mail.domain1.com, etc?
    2. Lets say I have domainname 'myservers.com'. I have 2 VPS-es, vps1.myservers.com and vps2.myservers.com. At the domain registar for 'myservers.com', should I just create 2 A records for VPS1 and VPS2 and point those to the droplets IP`s for vps1 and vps2? Actually, at the moment I already have a droplet for 'myservers.com', which droplet name is already myservers.com. So I would add a DNS record to that droplet like vps1.myserver.com A XX.XX.XX right?

    Because in your situation myservers.com (in your text domain1.com) is actually a domain on vps1.myservers.com. In my situation myservers.com is a droplet for itself, with its own mail.myservers.com records. (which is working). So could this remain, or should I rename this droplet to srv1.myservers.com.

    Thanks a lot.

  • Right,

    On the first option (i think that is your choice) so you can do something like this, look:

    srv1.myservers.com IN A 111.111.111.111
    srv2.myservers.com IN A 222.222.222.222

    on DO painel, you rename your VPS-es to
    srv1.myservers.com
    srv2.myservers.com
    and this will create PTR records on DO name servers like
    111.111.111.111 IN PTR srv1.myservers.com
    222.222.222.222 IN PTR srv2.myservers.com

    for each domain you can create.

    domain1.com IN A 111.111.111.111
    domain1.com IN MX srv1.myservers.com
    domain1.com IN TXT "v=spf1 include:srv1.myservers.com ~all"
    mail.domain1.com IN CNAME domain1.com
    www.domain1.com IN CNAME domain1.com

    Right? :)

    Best regards

  • Awesome. I`m going to set it up like this. Thanks a lot.

  • Hi,

    I have set this up following your description and it is working flawless!

    Only thing is I needed to add an A record for mail.domain1.com else my outgoing mailserver would not work using mail.domain1.com. It did work using domain1.com as mailserver. Incoming does work for mail.domain1.com without the A record (with just the cname record).

    Thanks anyway for your help!

  • Hi,

    The e-mail is working, but we receive a lot of messages that mails are not reaching us. No error message or something, maisl just are not delivered. Also, lots of mails we sent are delivered to spambox of the user.

    I have setup a mainserver in virtaualmin. The domain we e-mail from is a subserver (can this be the reason why it is not working?)

    The subserver has a mx 5 record to the mainserver and an txt record. Also an A record to the IP of the server for mail.subserver.

    The mainserver has no mx or txt records. Can it go wrong there? Because the subserver points to the mainserver and the mainserver has nog Mx record? I don`t know how this works exactly. If the subservers mx records points to the mainservers hostname, would the mainserver need Mx and txt records too?

    Thanks.

Have another answer? Share your knowledge.