As already answered DNS A
and/or CNAME
records don't support a priority mechanism.
But consider SRV DNS records, which allow the use of DNS for publishing services and service discovery. Their main use is to allow services to run easily on non-standard ports and to reduce the configuration burden when setting up clients.
But they also include a priority and allow you set up multiple records, for example for a preferred and fallback option.
A SRV record has the following form:
_Service._Protocol.Name. TTL Class SRV Priority Weight Port Target
Service: the symbolic name of the service.
Protocol: the transport protocol of the service; this is usually either TCP or UDP.
Name: the domain name terminated with a . for which this record is valid - often omitted in DNS shorthand which then
defaults to the zone name.
TTL: standard DNS time to live field.
Class: standard DNS class field (this is always IN
for Internet).
Priority: the priority of the target host, lower value means more preferred.
Weight: A relative weight for records with the same priority.
Port: the TCP or UDP port on which the service is to be found.
Target: the canonical hostname of the machine providing the service.
Your application will need to be (re-) designed to support SRV records for service discovery, that is not something that will "just work" for all applications and protocols. See for example also this Q&A How widely are SRV records supported?
From the Wikipia article:
Provisioning for high service availability
The priority field determines the precedence of the use of the record's data. Clients should use the SRV records with the lowest-numbered priority value first, and fall back to records of higher value if the connection fails. If a service has multiple SRV records with the same priority value, clients should load balance them in proportion to the values of their weight fields. In the following example, both the priority and weight fields are used to provide a combination of load balancing and backup service.
; _service._proto.name. TTL class SRV priority weight port target.
_sip._tcp.example.com. 86400 IN SRV 10 60 5060 bigbox.example.com.
_sip._tcp.example.com. 86400 IN SRV 10 20 5060 smallbox1.example.com.
_sip._tcp.example.com. 86400 IN SRV 10 20 5060 smallbox2.example.com.
_sip._tcp.example.com. 86400 IN SRV 20 0 5060 backupbox.example.com.