---
title: DNS Configuration Guide
slug: routing/dns-configuration-guide
description: DNS Configuration Guide
createdAt: 2025-12-03T02:28:42.969Z
---

## <font color="#1d50a2">Introduction</font>

The Domain Name System (DNS) is one of the core services of the internet. It functions as a distributed database that maps domain names to IP addresses, enabling users to access the internet more conveniently. Through its hierarchical naming architecture, DNS achieves unified management and resolution of global domain names, providing users with an intuitive and easy-to-remember method for accessing websites.

The advantages of DNS include an efficient domain name resolution mechanism, a distributed system architecture, robust caching capabilities, and reliable redundancy backups. Compared to traditional host file-based resolution methods, DNS is more efficient, reliable, and scalable, delivering a seamless internet access experience for users.

## <font color="#1d50a2">DNS Configuration</font>

### <font color="#1d50a2">Enable DNS relay function</font>

| **Operation**                       | **Command**            | **Description** |
| ----------------------------------- | ---------------------- | --------------- |
| Enter the system configuration view | **configure terminal** | -               |
| Enable DNS relay function           | **dns relay enable**   | -               |

### <font color="#1d50a2">Configuring DNS Domain Name Server</font>

| **Operation**                       | **Command**              | **Description**                      |
| ----------------------------------- | ------------------------ | ------------------------------------ |
| Enter the system configuration view | **configure terminal**   | -                                    |
| Configure DNS Domain Name Server    | **dns server** *A.B.C.D* | Configure server IP, such as 8.8.8.8 |

### <font color="#1d50a2">Configuring DNS Request List</font>

| **Operation**                                      | **Command**                   | **Description**                                          |
| -------------------------------------------------- | ----------------------------- | -------------------------------------------------------- |
| Enter the system configuration view                | **configure terminal**        |                                                          |
| Enter DNS query group configuration view           | **dns query-group \<string>** | String: Configure DNS request list name                  |
| Configure the domain name that needs to be queried | **query \<hostname>**         | Hostname: Configure domain name, maximum length 64 bytes |

### <font color="#1d50a2">Configuring DNS ACL</font>

| **Operation**                                   | **Command**                                              | **Description**                                                                                                                                 |
| ----------------------------------------------- | -------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| Enter the system configuration view             | **configure terminal**                                   |                                                                                                                                                 |
| Enter ACL configuration view                    | **access-list \{L3\|L3V6} \<string> \{ingress\|egress}** | Enter ACL configuration view                                                                                                                    |
| Configure corresponding DNS ACL matching fields | **\{src-dns-group\|dst-dns-group} \<string>**            | string：Configure the DNS request list names to match, note that src dns group \| dst dns group cannot be matched with src ip \| dst ip together |

## <font color="#1d50a2">Display and Maintenance</font>

| **Operation**      | **Command**         |
| ------------------ | ------------------- |
| Display DNS server | **show dns server** |

## <font color="#1d50a2">Example of DNS ACL Configuration</font>

**Network Requirements**

Enterprise networking hopes to set firewall rules through devices, such as prohibiting all traffic originating from a certain domain group from entering and accessing the intranet from the device. In order to ensure that firewall rules can be correctly configured and effective, DNS ACL rules need to be configured as follows:

::Image[]{src="https://app.archbee.com/api/optimize/zl-MD6bX0o2Ab3p8w66u1/lYItUOfxr48fm64l0SuEC-20251203-063158.png" size="70" width="577" height="368" position="center" showCaption="false"}

**Procedure**

```plaintext
sonic(config)# dns relay enable
sonic(config)# dns server 114.114.114.114
sonic(config)# dns query-group test
sonic(config-dns-query-group-test)# query www.baidu.com
sonic(config-dns-query-group-test)# query www.taobao.com
sonic(config-dns-query-group-test)# exit
sonic(config)# access-list L3 test1 ingress
sonic(config-L3-acl-test1)# rule 1 src-dns-group test packet-action deny
sonic(config-L3-acl-test1)# exit
sonic(config)# interface ethernet 3
sonic(config-if-3)# acl test1
sonic(config-if-3)# exit
```

