1. Add DNS to the Host
1.1 CentOS
The first method: manage DNS with /etc/resolv.conf
- Disable
NetworkManager
If you do not disable NetworkManager, the DNS records you add directly to /etc/resolv.conf are lost after you restart the NetworkManager component.
1
2
3
4
| vim /etc/NetworkManager/NetworkManager.conf
[main]
dns=none
|
Add dns=none to the [main] section.
- Now restarting
NetworkManager has no effect on the records already added to /etc/resolv.conf
1
| systemctl restart network
|
The second method: let NetworkManager manage DNS
- List the local networks
1
2
3
4
5
6
| nmcli connection show
NAME UUID TYPE DEVICE
ens192 03da7500-2101-c722-2438-d0d006c28c73 ethernet ens192
br-006fb59057ed 07e61d55-0c2e-4d63-bba9-52854cf9ad75 bridge br-006fb59057ed
virbr0 ff8cf6fe-0613-4ba8-ac32-0afd2c6044b6 bridge virbr0
|
- Edit the NetworkManager NIC configuration file
Once you have the local NIC name ens192, you can edit that NIC’s configuration file and add DNS.
1
2
3
4
5
| vim /etc/sysconfig/network-scripts/ifcfg-ens192
#add
DNS1=119.29.29.29
DNS2=2114.114.114.114
|
- Restart NetworkManager to generate the configuration file
Note that the DNS records in /etc/resolv.conf are cleared at this point, so be sure to back them up.
1
| cp /etc/resolv.conf /etc/resolv.conf.backup-$(date +%Y%m%d-%H%M%S)
|
1
| systemctl restart network
|
- Check the generated
/etc/resolv.conf file
1
2
3
4
5
| cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 119.29.29.29
nameserver 114.114.114.114
|
1.2 Ubuntu
Since resolv.conf is generated automatically, you have to change resolved.conf instead.
1
2
3
4
5
| vim /etc/systemd/resolved.conf
[Resolve]
DNS=114.114.114.114
DNS=8.8.8.8
|
Then restart the resolve service.
1
| systemctl restart systemd-resolved.service
|
Finally, you can also confirm that the configuration took effect.
1
| systemd-resolve --status
|
2. Restart Nodelocaldns
When a Pod makes an external request, the resolution logic is nodelocaldns -> the DNS configured on the node -> return the IP.
1
| kubectl -n kube-system rollout restart ds nodelocaldns
|
3. References