Koozali.org: home of the SME Server

Advanced DNS Config (MX Records)

Offline olej

  • *
  • 5
  • +0/-0
Advanced DNS Config (MX Records)
« on: March 14, 2010, 10:24:59 PM »
My setup:

Network: 192.168.0.0/255

WAN->LAN: SMTP etc. is routed directly from WAN->192.168.0.12

SME server sme.domain.com (192.168.0.2)
Setup as: Stand-alone server
Serving: DHCP, (local/split)DNS, HTTP
Email delivery settings:
    Unknown Users = reject
    Delegate mail servers = 192.168.0.12
 Hostnames and addresses:
    sme.domain.com 192.168.0.2
    mail.domain.com 192.168.0.12

Mailserver: mail.domain.com (192.168.0.12)

What I would like SME Server MX Records for domain.com (and optionally domain2.com and further domains) to point to 192.168.0.12 instead of the server itself.
Since I use a split DNS scenario where the SME acting as DHCP+DNS I need to know how to have the DNS feed the correct MX address (192.168.0.12) to my inside clients. This is both to make sure that resolving is correct on the inside but also so that the mailserver can verify its own MX.

Looking up the MX for domain.com and domain1.com with "dig domain.com" gives me the following:
domain.com.           86400   IN      MX      0 sme.domain.com.

Of course I'd like the result to look like this instead :)
domain.com.           86400   IN      MX      0 mail.domain.com.


How do I achieve this?
Is there perhaps a contrib (rpm) that gives me an "Advanced DNS" setup in the server-manager?
Otherwise, which files will I need to "nano" to get it to do what I want?

Thanks in advance. And sorry if this has already been asked a thousand times but a search gave me heaps and heaps of useless results. Thanks.
« Last Edit: March 14, 2010, 10:54:28 PM by olej »

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Re: Advanced DNS Config (MX Records)
« Reply #1 on: March 15, 2010, 12:29:47 AM »
How do I achieve this?

Via a custom template. /var/service/tinydns/root/data/ contains the template fragments.

Quote
Is there perhaps a contrib (rpm) that gives me an "Advanced DNS" setup in the server-manager?

Not to my knowledge.

Offline olej

  • *
  • 5
  • +0/-0
Re: Advanced DNS Config (MX Records)
« Reply #2 on: March 15, 2010, 11:09:51 PM »
Thanks for your reply Charlie.

I've modified the "data" fragments file - Under MX changing all "sme.domain.com" to "mail.domain.com".... Arghhh and found out that this is reset on service restart...
How would an example custom-template look?  I have figured out where to store custom-templates via a forum search but I have no clue how I should format the contents of my 99propermx file. Any help highly appreciated. Thanks.


Wouldn't it by the way be most logical for the SME Server to default to setting MX records to point to "mail.domain.tld" instead of "host.domain.tld"? This would avoid the hassle of nano/pico/vi'ing wierd config files etc. in case you want to direct mail towards another host using the "mail." subdomain.

Am I wrong in believing that servicename.domain.tld should relate to the actual service on that host? ;-)
« Last Edit: March 15, 2010, 11:27:41 PM by olej »

Offline janet

  • *****
  • 4,812
  • +0/-0
Re: Advanced DNS Config (MX Records)
« Reply #3 on: March 16, 2010, 01:58:21 PM »
Please search before asking, an answer may already exist.
The Search & other links to useful information are at top of Forum.

Offline olej

  • *
  • 5
  • +0/-0
Re: Advanced DNS Config (MX Records)
« Reply #4 on: March 16, 2010, 09:50:04 PM »
Thanks for your input Mary

I've already gone over that page 3 times in hopes of understanding exactly WHAT I should put in the custom template. The page you link to gives me examples of dhcpd.conf, masq, mysql and php.ini templates... not tinydns.

I have no clue as to what exactly needs to go into my custom fragment in order to define my MX servers.

I've previously (several years ago) worked with SME Server and defined fragments for other services solely because I was able to find examples or copy and edit the system fragments.
If I look at the tinydns fragments in the templates/etc/tinydns/data/ they are just full of code gibberish and not a single clear mention of my mx records. So even knowing about custom templates  I'm still SOL on creating a fragment pointing my various domains towards mail.thisdomain.tld.

What I need is someone who actually knows the answer or knows how to find it and willing to spell it out for me.

Here's a paste of /etc/e-smith/templates/var/service/tinydns/root/data/40mxRecords
Code: [Select]
{
    $OUT .= "# MX Records\n";
    foreach my $domain (get_domains())
    {
        $OUT .= "\@$domain:\:$SystemName." . get_local_domainname(). "\n";
    }
    $OUT .= "\n";
}

I can read the script but I don't know the variables nor how to craft this into defaulting to mail.thisdomain.tld instead of hostnameofSMEserver.thisdomain.tld.

Any help is still highly appreciated.

Thanks

Offline olej

  • *
  • 5
  • +0/-0
Re: Advanced DNS Config (MX Records)
« Reply #5 on: March 16, 2010, 10:07:01 PM »
Ha!
I couldn't wait for help any longer so I just hacked away on my own. Luckily I guessed right. All I had to do was replace "$SystemName" with "mail" and do the default
signal-event post-upgrade
signal-event reboot

Now "dig mydomain.tld mx" gives me "mail.mydomain.tld".
Hoorah!

For those interested this is my new /etc/e-smith/templates-custom/var/service/tinydns/root/data/40mxRecords

Code: [Select]
{
    $OUT .= "# MX Records\n";
    foreach my $domain (get_domains())
    {
        $OUT .= "\@$domain:\:mail." . get_local_domainname(). "\n";
    }
    $OUT .= "\n";
}

This will output mail.primarydomain.tld as mx handler for all domains handled by SME Server.

Now if only I could figure out which part of
Code: [Select]
$OUT .= "\@$domain:\:mail." . get_local_domainname(). "\n";is syntax and which is variable so I can switch "get_local_domainname()" out with "$domain" then I'll be flying :)

Is this correct syntax to output mail.domain.tld? (I want mx handler for domain2.tld to be definable via the A Record mail.domain2.tld)
Code: [Select]
{
    $OUT .= "# MX Records\n";
    foreach my $domain (get_domains())
    {
        $OUT .= "\@$domain:\:mail.$domain" .  "\n";
    }
    $OUT .= "\n";
}
^^ apparently it is not correct as dig domain2.tld mx still gives me mail.primarydomain.tld... now what do I do. I've searched google for "get_local_domainname()" and there just isn't any documentation on that variable.... great!

Peace out ya'll!
« Last Edit: March 16, 2010, 10:57:17 PM by olej »

Offline Normando

  • *
  • 841
  • +2/-1
    • Unixlan
Re: Advanced DNS Config (MX Records)
« Reply #6 on: March 17, 2010, 07:42:28 AM »
olej, all variables come from SME db configuration located in /home/e-smith/db. Pay attention to the files 'accounts' - 'configuration' - 'domains' - 'hosts' - 'networks'.

Please, do not edit manually those files. Take a look at:

http://wiki.contribs.org/DB_Variables_Configuration

and

http://wiki.contribs.org/Db_command_tutorial

Offline olej

  • *
  • 5
  • +0/-0
Re: Advanced DNS Config (MX Records)
« Reply #7 on: March 17, 2010, 10:14:05 PM »
olej, all variables come from SME db configuration located in /home/e-smith/db. Pay attention to the files 'accounts' - 'configuration' - 'domains' - 'hosts' - 'networks'.

Please, do not edit manually those files. Take a look at:

http://wiki.contribs.org/DB_Variables_Configuration

and

http://wiki.contribs.org/Db_command_tutorial

I've already been to those pages. TinyDNS is somehow completely uncovered by all documentation... *sigh*

Anyways. Thank you but I think you're referring to the DB contents with regards to those files!?. I'm talking about the variable that is called in the 40mxRecords called "get_local_domainname" or is that an operator?! I don't know I'm no programmer.

This is 3 nights I've spent on a silly little detail now. How effing difficult should it be for someone to change default mx records.

I don't need to learn perl-scripting but I would very much like if someone in here who knows this system better than me not point me towards the documentation that I've already read but instead help me fix this piece of code to output the right stuff....

Please help me sort syntax and variables/operators of the following so it does what I've tried explaining like 3 times above...

Thank you.

Code: [Select]
{
    $OUT .= "# MX Records\n";
    foreach my $domain (get_domains())
    {
        $OUT .= "\@$domain:\:mail.$domain" .  "\n";
    }
    $OUT .= "\n";
}
I'm trying to have the above output mail.domain1.tld for domain1, mail.domain2.tld for domain2 and henceforth.

should it be $OUT .= "\@$domain:\:mail.@$domain" .  "\n"; instead?
or perhaps: $OUT .= "\@$domain:\:mail." . get_domainname(). "\n";
or perhaps: $OUT .= "\@$domain:\:mail." . $domain. "\n";
or perhaps: $OUT .= "\@$domain:\:mail." . @$domain. "\n";
or perhaps: $OUT .= "\@$domain:\:mail." . $domain "\n";
or perhaps: $OUT .= "\@$domain:\:mail." . @$domain "\n";
or perhaps: $OUT .= "\@$domain:\:mail." $domain. "\n";
or perhaps: $OUT .= "\@$domain:\:mail." @$domain. "\n";
etc etc etc etc.... I don't understand the syntax with the dots and the @s and I can't lookup variables like the "get_local_domainname" because it's apparently undocumented. And please don't give me a link to Perl for Dummies.

Does anyone understand what I'm trying to accomplish? It's so blatantly simple in idea but the practical part involving the e-smith db-system has apparently made it practically impossible?
« Last Edit: March 17, 2010, 10:29:26 PM by olej »

Offline Stefano

  • *
  • 10,894
  • +3/-0
Re: Advanced DNS Config (MX Records)
« Reply #8 on: March 18, 2010, 12:08:28 AM »
Does anyone understand what I'm trying to accomplish? It's so blatantly simple in idea but the practical part involving the e-smith db-system has apparently made it practically impossible?

IMO you should suscribe the dev ML and ask for clarification for the syntax.. or you could open a NFR in bugzilla for such a feature

Offline Stefano

  • *
  • 10,894
  • +3/-0
Re: Advanced DNS Config (MX Records)
« Reply #9 on: March 18, 2010, 12:48:11 AM »
just tried, not tested, should work

Code: [Select]
mkdir -p /etc/e-smith/templates-custom/var/service/tinydns/root/data
cp /etc/e-smith/templates/var/service/tinydns/root/data/40mxRecords /etc/e-smith/templates-custom/var/service/tinydns/root/data/
cd /etc/e-smith/templates-custom/var/service/tinydns/root/data

edit 40mxRecord as follow

Code: [Select]
{

    use esmith::DomainsDB;
    my $ddb = esmith::DomainsDB->open_ro;

    $OUT .= "# MX Records\n";
    foreach my $domain (get_domains())
    {
        my $tmpdomain = $ddb->get($domain);
        my $mx = ($tmpdomain->prop('RecordMX') || "");
        if ($mx eq "") {
        $OUT .= "\@$domain:\:$SystemName." . get_local_domainname(). "\n";
        }
        else {
        $OUT .= "\@$domain:\:$mx\n";
        }
    }
    $OUT .= "\n";
}

save

then, for each domain where you wand a different mx record
Code: [Select]
db domains setprop mydomain RecordMX yourvalue

expand template with
Code: [Select]
expand-template /var/service/tinydns/root/data

then
Code: [Select]
sv 1 /service/tinydns
sv 1 /service/dnscache

should work

HTH
« Last Edit: March 18, 2010, 12:50:35 AM by Stefano »

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Re: Advanced DNS Config (MX Records)
« Reply #10 on: March 29, 2010, 05:55:18 PM »
Since I use a split DNS scenario where the SME acting as DHCP+DNS I need to know how to have the DNS feed the correct MX address (192.168.0.12) to my inside clients.

I don't think you need to do that. Just configure "Delegate mail server" in the email config panel, and SME server will relay mail for your domain to 192.168.0.12.

Offline axessit

  • *****
  • 213
  • +0/-0
Re: Advanced DNS Config (MX Records)
« Reply #11 on: November 04, 2010, 09:25:06 PM »
Trying to set up a client's email server, so currently I have it connected on my LAN and hence my SME server is acting as the domain for my workstation.

I am trying to configure my SME to send email to client's SME box directly instead of trying to resolve to the internet (as they have domain set up by ISP) to test the email is all working fine.

I can send email from client's SME and i get it on my workstation as I have set the client SME to send to my SME. Tried setting the mx record template, but it's not working. Any clues?

Have set up the tinydns fragment as above,

did
Quote
db domains setprop clientdomain.co.nz RecordMX 192.168.2.10

but when I do a db domains show I don't see the clientdomain.co.nz entry.

Just for the record, my SME is 192.168.2.5.

Offline Stefano

  • *
  • 10,894
  • +3/-0
Re: Advanced DNS Config (MX Records)
« Reply #12 on: November 04, 2010, 09:31:59 PM »
did you create the custom fragment as suggested in my previous post?

Offline axessit

  • *****
  • 213
  • +0/-0
Re: Advanced DNS Config (MX Records)
« Reply #13 on: November 04, 2010, 09:38:24 PM »
Yep,

Code: [Select]
[root@postmanpat data]# more 40mxRecords
{
    use esmith::DomainsDB;
    my $ddb = esmith::DomainsDB->open_ro;
    $OUT .= "# MX Records\n";
    foreach my $domain (get_domains())
    {
        my $tmpdomain = $ddb->get($domain);
        my $mx = ($tmpdomain->prop('RecordMX') || "");
        if ($mx eq "") {
        $OUT .= "\@$domain:\:$SystemName." . get_local_domainname(). "\n";
        }
        else {
        $OUT .= "\@$domain:\:$mx\n";
        }
    }
    $OUT .= "\n";
}

While I'm at it, using Putty to access server, how to you paste from these forums into the Putty session ? Obviously no problem going the other way.....

Offline axessit

  • *****
  • 213
  • +0/-0
Re: Advanced DNS Config (MX Records)
« Reply #14 on: November 04, 2010, 09:42:55 PM »
Just googled putty text insert and found it - Ctrl-Ins.