In the Internet system architecture, DNS, as the core protocol for domain name resolution, undertakes the key task of converting human-readable URLs into machine-readable IP addresses. Whether it is website access, email transmission or API communication, DNS plays a vital role. For data nodes deployed overseas, especially Hong Kong servers, configuring the correct DNS address not only affects the website access speed, but also directly affects the resolution stability, system security and cross-border network performance.
How to add DNS addresses in different systems?
The method of adding DNS addresses depends on the operating system used by the server. Common operating systems for Hong Kong servers include Ubuntu/Debian, CentOS/RHEL, and Windows Server. The following explains their DNS configuration methods respectively.
1. Add DNS addresses in Ubuntu/Debian systems
Applicable versions: Ubuntu 18.04/20.04/22.04, Debian 10/11
Method 1: Modify the /etc/netplan configuration (Ubuntu uses Netplan)
sudo nano /etc/netplan/01-netcfg.yaml
Add or modify the following:
ethernets:
ens3:
dhcp4: no
addresses: [192.168.1.100/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 1.1.1.1]
Save and execute:
sudo netplan apply
Method 2: Traditional /etc/resolv.conf configuration (some old versions)
sudo nano /etc/resolv.conf
Add the following content:
nameserver 8.8.8.8
nameserver 1.1.1.1
Note: This file may be overwritten by the DHCP service. It is recommended to disable automatic generation or use Netplan management instead.
2. Add DNS address in CentOS / RHEL system
Applicable versions: CentOS 7 / 8, RockyLinux, AlmaLinux, etc.
Method 1: Modify /etc/sysconfig/network-scripts/ifcfg-eth0
sudo nano /etc/sysconfig/network-scripts/ifcfg-eth0
Add the following content:
DNS1=8.8.8.8
DNS2=1.1.1.1
After saving, restart the network service:
sudo systemctl restart network
Method 2: Edit /etc/resolv.conf directly (temporary effect)
echo "nameserver 8.8.8.8" >> /etc/resolv.conf
echo "nameserver 1.1.1.1" >> /etc/resolv.conf
It is recommended to use the chattr command to prevent it from being overwritten by NetworkManager:
chattr +i /etc/resolv.conf
3. Add DNS address in Windows Server
Applicable version: Windows Server 2016 / 2019 / 2022
Steps are as follows:
①Open "Control Panel" → "Network and Sharing Center";
②Click "Change Adapter Settings", right-click your network card and select "Properties";
③Double-click "Internet Protocol Version 4 (TCP/IPv4)";
④Select "Use the following DNS server address" and fill in:
Preferred DNS server:8.8.8.8
Alternative DNS Servers:1.1.1.1
⑤Confirm → Apply.
You can also use PowerShell commands to set:
Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ServerAddresses ("8.8.8.8", "1.1.1.1")
Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ServerAddresses ("8.8.8.8", "1.1.1.1")
Test whether the DNS configuration is effective
After completing the DNS address configuration, be sure to verify whether the resolution function is normal. You can use the following command to test:
Linux/Unix environment:
nslookup www.google.com
dig www.google.com
ping www.baidu.com
Windows Environment:
nslookup www.google.com
If the normal IP address is returned, it means that the DNS configuration is successful.
Hong Kong server DNS configuration suggestions and precautions
In order to obtain better performance and stability, the following are practical suggestions for configuring DNS in Hong Kong servers:
1. Give priority to using local or international DNS, and avoid using unstable or unregistered DNS services;
2. For sites targeting users in mainland China, it is better to use Alibaba DNS + Cloudflare or Google DNS;
3. Dual DNS addresses should be configured in the production environment, and the primary and standby switching automatically handles exceptions;
4. When configuring DNS, be careful to prevent /etc/resolv.conf from being overwritten by DHCP or Cloud-init;
5. You can use third-party services such as DNSPerf and Cloudflare Radar to regularly detect DNS response speed;
6. For high-availability architecture, it is recommended to deploy local DNS cache (such as dnsmasq, unbound) to speed up resolution efficiency;
7. If the server is used as a mail system host, it is necessary to ensure that DNS resolution can correctly return SPF, MX and other records.
Whether it is building a website, running an API, deploying a database or processing emails, DNS configuration is one of the basic steps for a Hong Kong server to enter the production environment. Through the methods in this article, administrators can quickly and securely add DNS addresses in different operating systems to ensure the stability and high performance of server resolution capabilities.