module – Configures DNS lookup on Windows hosts


This module is part of the collection (version 2.4.0).

You might already have this collection installed if you are using the ansible package. It is not included in ansible-core. To check whether it is installed, run ansible-galaxy collection list.

To install it, use: ansible-galaxy collection install

To use it in a playbook, specify:






list / elements=string / required

Adapter name or list of adapter names for which to manage DNS settings (’*’ is supported as a wildcard value).

The adapter name used is the connection caption in the Network Control Panel or the InterfaceAlias of Get-DnsClientServerAddress.


aliases: ipv4_addresses, ip_addresses, addresses

list / elements=string / required

Single or ordered list of DNS servers (IPv4 and IPv6 addresses) to configure for lookup.

An empty list will configure the adapter to use the DHCP-assigned values on connections where DHCP is enabled, or disable DNS lookup on statically-configured connections.

IPv6 DNS servers can only be set on Windows Server 2012 or newer, older hosts can only set IPv4 addresses.


- name: Set a single address on the adapter named Ethernet
    adapter_names: Ethernet

- name: Set multiple lookup addresses on all visible adapters (usually physical adapters that are in the Up state), with debug logging to a file
    adapter_names: '*'
    log_path: C:\dns_log.txt

- name: Set IPv6 DNS servers on the adapter named Ethernet
    adapter_names: Ethernet
      - '2001:db8::2'
      - '2001:db8::3'

- name: Configure all adapters whose names begin with Ethernet to use DHCP-assigned DNS values
    adapter_names: 'Ethernet*'
    dns_servers: []


  • Matt Davis (@nitzmahone)

  • Brian Scholer (@briantist)