【Linux】配置本地DNS

Posted by 西维蜀黍 on 2020-09-15, Last Modified on 2021-10-23

Linux

Under Linux / UNIX / BSD operating system, you need to edit the /etc/resolv.conf file and add the line:

nameserver {IP-OF-THE-DNS-1}
nameserver {IP-OF-THEISP-DNS-SERVER-2}

Login as the root, enter:

# vi /etc/resolv.conf

OR

$ sudo vi /etc/resolv.conf

Modify or enter nameserver as follows:

nameserver 208.67.222.222
nameserver 208.67.220.220

macOS

To change DNS settings from the command line, open up Terminal and run this to get a list of all the network interfaces:

networksetup listallnetworkservices

This will return a list similar to this:

An asterisk (*) denotes that a network service is disabled.
Bluetooth DUN
Ethernet
FireWire
Wi-Fi

Now you can configure DNS for the appropriate network interface. In my case, I want to update DNS for the “Wi-Fi” interface. To change to the DNS server settings to the local DNS server, do this:

sudo networksetup -setdnsservers Wi-Fi 192.168.1.254
sudo networksetup -setdnsservers Wi-Fi 8.8.8.8 8.8.4.4

You can put as many (or as few) DNS servers in the list; simply separate each with a space as shown in the second example above.

Reference