2017/03/03

Ways on adding DNS servers in Ubuntu

DNS stands for domain name system (Just in case you have no idea what DNS is). This is a system for mapping a hostname and IP address back and forth.
Here are ways for configuring DNS manually in Ubuntu
Background
  • OS: Ubuntu 16.04
1. Edit /etc/hosts
Manually define a static mapping between host and IP address. Although this is the simplest way to do the resolving work, in my opinion, try to avoid editing this file as this is the job of DNS.
For example, given following /etc/hosts
127.0.0.1 localhost
127.0.1.1 ubuntu-server
10.0.0.11 server1
You have added 3 hostnames. When you run command like ping you host is able to resolve the hostname properly.
--- PING localhost (127.0.0.1) 56(84) bytes of data. ---
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.027 ms
64 bytes from 127.0.0.1: icmp_seq=2 ttl=64 time=0.024 ms
64 bytes from 127.0.0.1: icmp_seq=3 ttl=64 time=0.029 ms
64 bytes from 127.0.0.1: icmp_seq=4 ttl=64 time=0.023 ms
2. Edit /etc/networks/interfaces
Please read my previous blog here. Devices defined here will not be managed by Network Manager below.
3. Network Manager (Recommend)
This is the recommended way for adding DNS in Ubuntu.
In GUI way, you can open network manager in your desktop’s top right hand corner.
Click Edit Connections.
Click Add if you would like to create a new profile. Otherwise, pick a profile and Click Edit
Click to IPV4 Settings tab and add DNS in Additional DNS servers
For example, 8.8.8.8 or multiple 8.8.8.8 8.8.4.4.
In terminal way, you can edit files in /etc/NetworkManager/system-connections.
root@mondwan-VirtualBox:/etc/NetworkManager/system-connections# cat a_custom_profile
[connection]
id=a_custom_profile
uuid=22e9568c-7a0d-3a88-a84d-1e2c0b1708b7
type=ethernet
autoconnect-priority=-999
permissions=
secondaries=
timestamp=1488624882

[ethernet]
duplex=full
mac-address=08:00:27:EB:EB:5B
mac-address-blacklist=

[ipv4]
dns=8.8.8.8;8.8.8.4;
dns-search=
method=auto

[ipv6]
addr-gen-mode=stable-privacy
dns-search=
ip6-privacy=0
method=auto
Above is a profile named as a_custom_profile and there is an entry ipv4.dns for your DNS.
References:

沒有留言:

張貼留言