The MX record in a zone file explained

A zone file stores the DNS data of a specific domain. DNS data includes names and IP addresses of resources available within the domain. DNS or name servers use zone files to translate names into IP addresses. MX records define mail servers in the zone file for the domain. It uses the following syntax.

domain-name TTL class resource-type preference mail-server

The following image shows the zone file of the example.com domain.

example zone file

The above zone file includes the following MX records.

	3w	IN 	MX 	10	mail.example.com.
		IN 	MX	20	mail.example.net.

Let's understand the meaning of the above records field-by-field.

The domain-name Field

This field defines the domain for which this record will specify the mail server. If we leave this field empty, the record will inherit its value from the previous record's name field. If we use a single character @ in this field, it replaces the character with the $ORIGIN directive's value. In our example zone file, the value of this field in MX records will be example.com.

The following image shows how MX records get this value.

name field in the zone file

The TTL Field

This field defines the maximum time resolver systems can cache this record. If you leave this field empty, the record uses the $TTL directive's value. In our example zone file, we have two MX records. In the first record, we defined this field's value. In the second record, we left this field empty. Because of this, the first record will use the specified value. The second record will use the $TTL directive's value.

The class Field

This field defines the class of the record. There are three classes IN, CH, and HS. Currently, only the IN class is in use. It shows the record belongs to the Internet class.

The resource-type field

This field defines the resource type. Mail servers use the MX record type. You can create many types of records in the zone file. Some of them are compulsory while the remaining are optional. The most common types are SOA, NS, MX, A, AAAA, and CNAME.

  • An SOA record defines the zone for which the zone file is authorized to resolve queries.
  • An NS record defines the authorized name servers for the zone.
  • An MX record defines the authorized mail servers for the zone.
  • An A record maps an IPv4 address with the name of a host or a service.
  • An AAAA record maps an IPv6 address with the name of a host or a service.
  • A CNAME record maps an alias name with the canonical name of a host or a service.

The preference Field

This field defines the priority of mail servers. If you configure multiple mail servers, you can use this field to specify the order in which they should be used. You can use any value between 0 and 96535. In order, a lower value has higher priority than a higher value. Typically, administrators use values in multiples of 10. They use the value 10 for the most preferred mail server, 20 for the second most preferred mail server, and so on. This method allows them to add additional MX records without changing the existing order.

In our example, we used this field to configure the mail server mail.example.com as the main mail server and the mail server mail.example.net as the backup mail server. To define mail.example.com as the main mail server, we used the value 10 which is the lowest in the configured priority order. We used value 20 for mail.example.net to define it as the backup mail server.

The mail-server Field

This field defines the email server for the domain we configure in the domain name field. In our example, we configured two mail servers mail.example.com and mail.example.net for the domain example.com (automatically configured from the SOA record in the domain-name field).

We configured mail.example.com as the primary mail server and mail.example.net as the backup mail server. Our primary mail server is available within the domain (example.com). Our backup mail server is available in the external domain (example.net). With this configuration, if the primary mail server fails, the backup mail server will receive emails for the domain and forward them to the primary mail server when it comes online again.

This field only defines the name of the email server. It does not specify the IP address of the email server. To configure the email server's IP address, we use a host (A) record. We only create a host record for the email server available within the domain. In our example, we need to add a host record for mail.example.com.

If the mail server is available outside the domain, we do not need to add a host record for that in the zone file of this domain. We need to add a host record for it in the zone file of that particular domain. In our example, we configured a host record for mail.example.com in the zone file of the example.com domain. We will add a host record for mail.example.net in the zone file of the example.net domain.

The host record

If the email server is available within the domain, we need to create a host record for it. A host record maps a service or a host to an IP address. It uses the following syntax.

resource-name TTL class resource-type IP address

The resource-name field defines the name of the service or host you want to map with an IP address. You can use a relative name in this field. A relative name does not end with a dot. If you use a relative name, it uses the $ORIGIN directive's value to convert it into the FQDN name. For example, if you specify a name mail in this field and the value of the $ORIGIN directive is example.com., DNS will read it as mail.example.com.

The TTL and class fields have the same meaning as the TTL and class fields of an MX record.

Resource type A belongs to IPv4 addresses. For IPv6 addresses, the resource type is AAAA.

The IP address field defines the IP address of the resource configured in the resource name field.

Conclusion

An MX record maps the IP address and name of the mail server in the zone file. In this tutorial, I explained how to create and format this record.

ComputerNetworkingNotes Linux Tutorials The MX record in a zone file explained

We do not accept any kind of Guest Post. Except Guest post submission, for any other query (such as adverting opportunity, product advertisement, feedback, suggestion, error reporting and technical issue) or simply just say to hello mail us ComputerNetworkingNotes@gmail.com