# Choisir ses DNS avec configuration de Network-Manager, dnsmasq et dhcp-client

**URL:** <https://www.debian-fr.org/t/choisir-ses-dns-avec-configuration-de-network-manager-dnsmasq-et-dhcp-client/75073>\
**Category:** Trucs et Astuces\
**Tags:** réseau\
**Created:** [Novembre 13, 2017, 10:42 UTC](https://www.debian-fr.org/t/choisir-ses-dns-avec-configuration-de-network-manager-dnsmasq-et-dhcp-client/75073 "2017-11-13T10:42:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![grandtoubab](https://www.debian-fr.org/user_avatar/www.debian-fr.org/grandtoubab/32/4505_2.png) [@grandtoubab](https://www.debian-fr.org/u/grandtoubab)\
**Post date:** [Novembre 13, 2017, 10:42 UTC](https://www.debian-fr.org/t/choisir-ses-dns-avec-configuration-de-network-manager-dnsmasq-et-dhcp-client/75073/1 "2017-11-13T10:42:29Z")

</div>

Salut  
Un petit mémo sur ma configuration pour choisir mes DNS en utilisant Network-Manager, dnsmasq et dhcp-client  
Je ne prétends pas que c’est la meilleure solution mais elle fonctionne  
Les dns choisis sont décrits dans dhcp-client.  
dnsmasq est utilisé pour sa fonction cache  
network-manager connecte au réseau en prenant en compte ces données

- Paquets installés:  
network-manager, isc-dhcp-client, dnsmasq

- Configuration

- network-manager

```auto
cat /etc/NetworkManager/NetworkManager.conf
[main]
plugins=ifupdown,keyfile
dns=dnsmasq

[ifupdown]
managed=false

```

- dhcp-client

dans /etc/dhcp/dhclient.conf

```auto
supersede domain-name-servers 64.6.64.6,80.67.188.188;
prepend domain-name-servers 127.0.0.1;

```

- dnsmasq  
dans /etc/dnsmasq.conf

```auto
# conf perso
port=0
listen-address=127.0.0.1
no-hosts
log-queries

```

- Vérification

cat /etc/resolv.conf

```auto
# Generated by NetworkManager
nameserver 127.0.0.1

```

journalctl -xb | grep dns

```auto

-- Subject: L'unité (unit) pppd-dns.service a commencé à démarrer
-- L'unité (unit) pppd-dns.service a commencé à démarrer.
-- Subject: L'unité (unit) pppd-dns.service a terminé son démarrage
-- L'unité (unit) pppd-dns.service a terminé son démarrage, avec le résultat RESULT.
nov. 13 11:08:13 debian NetworkManager[604]: <info> [1510567693.0842] dns-mgr[0x5589b02a0950]: init: dns=dnsmasq, rc-manager=resolvconf, plugin=dnsmasq
nov. 13 11:08:13 debian systemd[1]: Starting dnsmasq - A lightweight DHCP and caching DNS server...
-- Subject: L'unité (unit) dnsmasq.service a commencé à démarrer
-- L'unité (unit) dnsmasq.service a commencé à démarrer.
nov. 13 11:08:14 debian dnsmasq[726]: dnsmasq: vérification de syntaxe OK.
nov. 13 11:08:16 debian dnsmasq[770]: démarrage avec le DNS désactivé (version 2.78)
nov. 13 11:08:16 debian dnsmasq[770]: options à la compilation : IPv6 GNU-getopt DBus i18n IDN DHCP DHCPv6 no-Lua TFTP conntrack ipset auth DNSSEC loop-detect inotify
nov. 13 11:08:16 debian systemd[1]: Started dnsmasq - A lightweight DHCP and caching DNS server.
-- Subject: L'unité (unit) dnsmasq.service a terminé son démarrage
-- L'unité (unit) dnsmasq.service a terminé son démarrage, avec le résultat RESULT.
nov. 13 11:08:25 debian NetworkManager[604]: <info> [1510567705.8516] dns-plugin[0x5589b028a4a0]: starting dnsmasq...
nov. 13 11:08:25 debian dnsmasq[834]: demarré, version 2.78 (taille de cache 400)
nov. 13 11:08:25 debian dnsmasq[834]: options à la compilation : IPv6 GNU-getopt DBus i18n IDN DHCP DHCPv6 no-Lua TFTP conntrack ipset auth DNSSEC loop-detect inotify
nov. 13 11:08:25 debian dnsmasq[834]: Support DBus autorisé : connecté au bus système
nov. 13 11:08:25 debian dnsmasq[834]: attention : aucun serveur amont n'est configuré
nov. 13 11:08:25 debian dnsmasq[834]: cache vidé
nov. 13 11:08:25 debian NetworkManager[604]: <info> [1510567705.8841] dnsmasq[0x5589b028a4a0]: dnsmasq appeared as :1.24
nov. 13 11:08:25 debian dnsmasq[834]: configuration des serveurs amonts à partir de DBus
nov. 13 11:08:25 debian dnsmasq[834]: ignore le serveur de nom 127.0.0.1 - interface locale
nov. 13 11:08:25 debian dnsmasq[834]: utilise le serveur de nom 64.6.64.6#53 (via wlp3s0b1)
nov. 13 11:08:25 debian dnsmasq[834]: utilise le serveur de nom 80.67.188.188#53 (via wlp3s0b1)
nov. 13 11:08:25 debian dnsmasq[834]: cache vidé

```

```auto
root@debian:/# dig debian.org

; <<>> DiG 9.10.6-Debian <<>> debian.org
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 31655
;; flags: qr rd ra ad; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;debian.org. IN	A

;; ANSWER SECTION:
debian.org. 300	IN	A	130.89.148.14
debian.org. 300	IN	A	128.31.0.62
debian.org. 300	IN	A	5.153.231.4
debian.org. 300	IN	A	149.20.4.15

;; Query time: 28 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Mon Nov 13 12:01:51 CET 2017
;; MSG SIZE rcvd: 103

root@debian:/# dig debian.org

; <<>> DiG 9.10.6-Debian <<>> debian.org
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 9996
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;debian.org. IN	A

;; ANSWER SECTION:
debian.org. 295	IN	A	149.20.4.15
debian.org. 295	IN	A	5.153.231.4
debian.org. 295	IN	A	128.31.0.62
debian.org. 295	IN	A	130.89.148.14

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Mon Nov 13 12:01:56 CET 2017
;; MSG SIZE rcvd: 103

```

La première fois la réponse vient du dns verisign en 28 ms , la deuxième fois elle est prise dans le cache en 0 ms

On retrouve toutes les infos utilisées par Network-Manager dans

```auto
ls -alrt /var/lib/NetworkManager

```
