|
| 1 | +# DNS Configuration |
| 2 | + |
| 3 | +This document describes the DNS records required for the mailserver to function properly. All DNS records must be configured in your domain's DNS zone to enable email delivery, authentication, and reputation management. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +The mailserver requires several DNS record types to operate correctly: |
| 8 | + |
| 9 | +- **MX Record**: Directs incoming emails to your mailserver |
| 10 | +- **A/AAAA Records**: Resolve the mailserver hostname to IP addresses |
| 11 | +- **SPF Record**: Authorizes your mailserver to send emails for your domain |
| 12 | +- **DKIM Record**: Provides public key for email signature verification |
| 13 | +- **DMARC Record**: Defines email authentication policy and reporting |
| 14 | + |
| 15 | +## MX Record |
| 16 | + |
| 17 | +The Mail Exchange (MX) record directs incoming emails to your mailserver. This is the primary DNS record that tells other mail servers where to deliver emails for your domain. |
| 18 | + |
| 19 | +### Configuration |
| 20 | + |
| 21 | +Create an MX record in your domain's DNS zone: |
| 22 | + |
| 23 | +``` |
| 24 | +Type: MX |
| 25 | +Name: @ (or your domain name) |
| 26 | +Priority: 10 |
| 27 | +Value: mail.example.com |
| 28 | +``` |
| 29 | + |
| 30 | +Replace `mail.example.com` with the value configured in the `MAILNAME` environment variable. The priority value (10 in this example) determines the order when multiple MX records exist. Lower numbers have higher priority. |
| 31 | + |
| 32 | +### Example |
| 33 | + |
| 34 | +For domain `example.com` with mailserver hostname `mail.example.com`: |
| 35 | + |
| 36 | +``` |
| 37 | +example.com. IN MX 10 mail.example.com. |
| 38 | +``` |
| 39 | + |
| 40 | +### Verification |
| 41 | + |
| 42 | +Verify the MX record using DNS lookup tools: |
| 43 | + |
| 44 | +```bash |
| 45 | +dig MX example.com |
| 46 | +# or |
| 47 | +nslookup -type=MX example.com |
| 48 | +``` |
| 49 | + |
| 50 | +## A and AAAA Records |
| 51 | + |
| 52 | +A and AAAA records resolve the mailserver hostname to IPv4 and IPv6 addresses respectively. These records are required for the MX record to function, as the MX record points to a hostname that must resolve to an IP address. |
| 53 | + |
| 54 | +### Configuration |
| 55 | + |
| 56 | +Create A and AAAA records for your mailserver hostname: |
| 57 | + |
| 58 | +``` |
| 59 | +Type: A |
| 60 | +Name: mail (or your mailserver hostname without domain) |
| 61 | +Value: 192.0.2.1 |
| 62 | +
|
| 63 | +Type: AAAA |
| 64 | +Name: mail (or your mailserver hostname without domain) |
| 65 | +Value: 2001:db8::1 |
| 66 | +``` |
| 67 | + |
| 68 | +Replace the IP addresses with your mailserver's actual IPv4 and IPv6 addresses. If your mailserver only has IPv4, you can omit the AAAA record, though IPv6 is recommended for modern email infrastructure. |
| 69 | + |
| 70 | +### Example |
| 71 | + |
| 72 | +For mailserver hostname `mail.example.com`: |
| 73 | + |
| 74 | +``` |
| 75 | +mail.example.com. IN A 192.0.2.1 |
| 76 | +mail.example.com. IN AAAA 2001:db8::1 |
| 77 | +``` |
| 78 | + |
| 79 | +### Verification |
| 80 | + |
| 81 | +Verify the A and AAAA records: |
| 82 | + |
| 83 | +```bash |
| 84 | +dig A mail.example.com |
| 85 | +dig AAAA mail.example.com |
| 86 | +# or |
| 87 | +nslookup mail.example.com |
| 88 | +``` |
| 89 | + |
| 90 | +## SPF Record |
| 91 | + |
| 92 | +The Sender Policy Framework (SPF) record authorizes your mailserver to send emails on behalf of your domain. SPF helps prevent email spoofing by specifying which mail servers are allowed to send emails for your domain. |
| 93 | + |
| 94 | +### Configuration |
| 95 | + |
| 96 | +Create a TXT record with SPF policy: |
| 97 | + |
| 98 | +``` |
| 99 | +Type: TXT |
| 100 | +Name: @ (or your domain name) |
| 101 | +Value: v=spf1 mx a ip4:192.0.2.1 ip6:2001:db8::1 ~all |
| 102 | +``` |
| 103 | + |
| 104 | +### SPF Mechanisms |
| 105 | + |
| 106 | +Common SPF mechanisms used in mailserver configurations: |
| 107 | + |
| 108 | +- `mx`: Authorizes the mail servers listed in MX records |
| 109 | +- `a`: Authorizes the IP addresses of A records for the domain |
| 110 | +- `ip4:192.0.2.1`: Explicitly authorizes a specific IPv4 address |
| 111 | +- `ip6:2001:db8::1`: Explicitly authorizes a specific IPv6 address |
| 112 | +- `include:example.com`: Includes SPF policy from another domain |
| 113 | +- `~all`: Soft fail for all other sources (recommended during testing) |
| 114 | +- `-all`: Hard fail for all other sources (recommended for production) |
| 115 | + |
| 116 | +### Example |
| 117 | + |
| 118 | +For domain `example.com` with mailserver at `mail.example.com`: |
| 119 | + |
| 120 | +``` |
| 121 | +example.com. IN TXT "v=spf1 mx a ip4:192.0.2.1 ~all" |
| 122 | +``` |
| 123 | + |
| 124 | +### Verification |
| 125 | + |
| 126 | +Verify the SPF record: |
| 127 | + |
| 128 | +```bash |
| 129 | +dig TXT example.com |
| 130 | +# or use SPF validation tools |
| 131 | +``` |
| 132 | + |
| 133 | +SPF records must be published as TXT records. Some DNS providers may also support the deprecated SPF record type, but TXT is the standard. |
| 134 | + |
| 135 | +## DKIM Record |
| 136 | + |
| 137 | +DomainKeys Identified Mail (DKIM) records publish the public key used to verify email signatures. DKIM signing is configured through the management interface, which generates the DNS TXT record that must be published. |
| 138 | + |
| 139 | +### Configuration |
| 140 | + |
| 141 | +DKIM records are generated through the management interface: |
| 142 | + |
| 143 | +1. Access the management interface |
| 144 | +2. Navigate to **DKIM** in the menu bar |
| 145 | +3. Select the domain for DKIM configuration |
| 146 | +4. Generate the DKIM key pair |
| 147 | +5. Copy the provided DNS TXT record |
| 148 | +6. Add the record to your domain's DNS |
| 149 | + |
| 150 | +### Record Format |
| 151 | + |
| 152 | +DKIM records use a specific subdomain format: |
| 153 | + |
| 154 | +``` |
| 155 | +Type: TXT |
| 156 | +Name: default._domainkey (or selector._domainkey) |
| 157 | +Value: v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC... |
| 158 | +``` |
| 159 | + |
| 160 | +The record name includes a selector (typically `default`) and the `_domainkey` subdomain. The value contains the DKIM version, key type, and public key. |
| 161 | + |
| 162 | +### Example |
| 163 | + |
| 164 | +For domain `example.com` with selector `default`: |
| 165 | + |
| 166 | +``` |
| 167 | +default._domainkey.example.com. IN TXT "v=DKIM1; k=rsa; p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC..." |
| 168 | +``` |
| 169 | + |
| 170 | +### Verification |
| 171 | + |
| 172 | +After publishing the DKIM record, verify it through the management interface. The interface checks DNS propagation and validates the record format. You can also verify manually: |
| 173 | + |
| 174 | +```bash |
| 175 | +dig TXT default._domainkey.example.com |
| 176 | +``` |
| 177 | + |
| 178 | +See [DKIM Signing](DKIM_SIGNING.md) for detailed DKIM configuration instructions. |
| 179 | + |
| 180 | +## DMARC Record |
| 181 | + |
| 182 | +Domain-based Message Authentication, Reporting & Conformance (DMARC) records define email authentication policy and enable reporting. DMARC works in conjunction with SPF and DKIM to provide comprehensive email authentication. |
| 183 | + |
| 184 | +### Configuration |
| 185 | + |
| 186 | +Create a TXT record with DMARC policy: |
| 187 | + |
| 188 | +``` |
| 189 | +Type: TXT |
| 190 | +Name: _dmarc |
| 191 | +Value: v=DMARC1; p=none; rua=mailto:[email protected] |
| 192 | +``` |
| 193 | + |
| 194 | +### DMARC Policy Options |
| 195 | + |
| 196 | +Common DMARC policy settings: |
| 197 | + |
| 198 | +- `p=none`: Monitor mode - no action taken, useful for initial deployment |
| 199 | +- `p=quarantine`: Quarantine emails that fail authentication |
| 200 | +- `p=reject`: Reject emails that fail authentication (recommended for production) |
| 201 | + |
| 202 | +### DMARC Tags |
| 203 | + |
| 204 | +- `v=DMARC1`: DMARC version (required) |
| 205 | +- `p=`: Policy for emails that fail authentication (none, quarantine, reject) |
| 206 | +- `rua=mailto:[email protected]`: Email address for aggregate reports |
| 207 | +- `ruf=mailto:[email protected]`: Email address for forensic reports |
| 208 | +- `pct=100`: Percentage of emails to apply policy to (default: 100) |
| 209 | +- `aspf=r`: SPF alignment mode (relaxed or strict) |
| 210 | +- `adkim=r`: DKIM alignment mode (relaxed or strict) |
| 211 | +- `fo=0`: Failure reporting options |
| 212 | + |
| 213 | +### Example Policies |
| 214 | + |
| 215 | +**Monitoring mode** (recommended for initial deployment): |
| 216 | + |
| 217 | +``` |
| 218 | +_dmarc.example.com. IN TXT "v=DMARC1; p=none; rua=mailto:[email protected]" |
| 219 | +``` |
| 220 | + |
| 221 | +**Quarantine mode** (after monitoring period): |
| 222 | + |
| 223 | +``` |
| 224 | +_dmarc.example.com. IN TXT "v=DMARC1; p=quarantine; rua=mailto:[email protected]; pct=100" |
| 225 | +``` |
| 226 | + |
| 227 | +**Reject mode** (production, after validation): |
| 228 | + |
| 229 | +``` |
| 230 | +_dmarc.example.com. IN TXT "v=DMARC1; p=reject; rua=mailto:[email protected]; aspf=r; adkim=r" |
| 231 | +``` |
| 232 | + |
| 233 | +### Verification |
| 234 | + |
| 235 | +Verify the DMARC record: |
| 236 | + |
| 237 | +```bash |
| 238 | +dig TXT _dmarc.example.com |
| 239 | +``` |
| 240 | + |
| 241 | +## DNS Record Summary |
| 242 | + |
| 243 | +For a complete mailserver setup, configure the following DNS records: |
| 244 | + |
| 245 | +| Record Type | Name | Value | Purpose | |
| 246 | +|------------|------|-------|---------| |
| 247 | +| MX | `@` | `10 mail.example.com` | Direct incoming emails | |
| 248 | +| A | `mail` | `192.0.2.1` | Resolve mailserver hostname (IPv4) | |
| 249 | +| AAAA | `mail` | `2001:db8::1` | Resolve mailserver hostname (IPv6) | |
| 250 | +| TXT (SPF) | `@` | `v=spf1 mx a ~all` | Authorize sending servers | |
| 251 | +| TXT (DKIM) | `default._domainkey` | `v=DKIM1; k=rsa; p=...` | Email signature verification | |
| 252 | +| TXT (DMARC) | `_dmarc` | `v=DMARC1; p=none; rua=...` | Authentication policy | |
| 253 | + |
| 254 | +## Troubleshooting |
| 255 | + |
| 256 | +### Common Issues |
| 257 | + |
| 258 | +**Emails not being received:** |
| 259 | +- Verify MX record points to correct hostname |
| 260 | +- Ensure A/AAAA records resolve the mailserver hostname |
| 261 | +- Check firewall rules allow connections on port 25 |
| 262 | + |
| 263 | +**Emails marked as spam:** |
| 264 | +- Verify SPF record is correctly configured |
| 265 | +- Ensure DKIM record is published and verified |
| 266 | +- Check DMARC policy is not too restrictive during initial setup |
| 267 | +- Review DMARC reports for authentication failures |
| 268 | + |
| 269 | +**DKIM verification failures:** |
| 270 | +- Verify DKIM DNS record is published correctly |
| 271 | +- Check DNS propagation is complete |
| 272 | +- Ensure the selector matches between DNS and mailserver configuration |
| 273 | +- Verify the public key in DNS matches the private key in mailserver |
| 274 | + |
| 275 | +**SPF failures:** |
| 276 | +- Verify all sending IP addresses are included in SPF record |
| 277 | +- Check for syntax errors in SPF record |
| 278 | +- Ensure SPF record is published as TXT record type |
| 279 | +- Review SPF mechanisms (mx, a, ip4, ip6) are appropriate for your setup |
0 commit comments