1.. zephyr:code-sample:: dns-resolve 2 :name: DNS resolve 3 :relevant-api: dns_resolve net_mgmt 4 5 Resolve an IP address for a given hostname. 6 7Overview 8******** 9 10This application will setup IP address for the device, and then 11try to resolve various hostnames according to how the user has 12configured the system. 13 14- If IPv4 is enabled, then A record for ``www.zephyrproject.org`` is 15 resolved. 16- If IPv6 is enabled, then AAAA record for ``www.zephyrproject.org`` is 17 resolved. 18- If mDNS is enabled, then ``zephyr.local`` name is resolved. 19 20Requirements 21************ 22 23- :ref:`networking_with_host` 24 25- screen terminal emulator or equivalent. 26 27- For most boards without ethernet, the ENC28J60 Ethernet module is required. 28 29- dnsmasq application. The dnsmasq version used in this sample is: 30 31.. code-block:: console 32 33 dnsmasq -v 34 Dnsmasq version 2.76 Copyright (c) 2000-2016 Simon Kelley 35 36Building and Running 37******************** 38 39Network Configuration 40===================== 41 42Open the project configuration file for your platform, for example: 43:file:`prj_frdm_k64f.conf` is the configuration file for the 44:zephyr:board:`frdm_k64f` board. 45 46In this sample application, both static or DHCPv4 IP addresses are supported. 47Static IP addresses are specified in the project configuration file, 48for example: 49 50.. code-block:: cfg 51 52 CONFIG_NET_CONFIG_MY_IPV6_ADDR="2001:db8::1" 53 CONFIG_NET_CONFIG_PEER_IPV6_ADDR="2001:db8::2" 54 55are the IPv6 addresses for the DNS client running Zephyr and the DNS server, 56respectively. 57 58DNS server 59========== 60 61The dnsmasq tool may be used for testing purposes. On a Zephyr project default 62installation, the sample dnsmasq start script can be found in the `net-tools`_ 63project or downloaded from https://github.com/zephyrproject-rtos/net-tools. 64 65Open a terminal window and type: 66 67.. code-block:: console 68 69 $ cd net-tools 70 $ sudo ./dnsmasq.sh 71 72The default project configurations settings for this sample uses the public 73Google DNS servers. In order to use the local dnsmasq server, please edit 74the appropriate 'prj.conf' file and update the DNS server addresses. For 75instance, if using the usual IP addresses assigned to testing, update them 76to the following values: 77 78.. code-block:: cfg 79 80 CONFIG_DNS_SERVER1="192.0.2.2:5353" 81 CONFIG_DNS_SERVER2="[2001:db8::2]:5353" 82 83.. note:: 84 DNS uses port 53 by default, but the dnsmasq.conf file provided by 85 net-tools uses port 5353 to allow executing the daemon without 86 superuser privileges. 87 88If dnsmasq fails to start with an error like this: 89 90.. code-block:: console 91 92 dnsmasq: failed to create listening socket for port 5353: Address already in use 93 94Open a terminal window and type: 95 96.. code-block:: console 97 98 $ killall -s KILL dnsmasq 99 100Try to launch the dnsmasq application again. 101 102For testing mDNS, use Avahi script in net-tools project: 103 104.. code-block:: console 105 106 $ cd net-tools 107 $ ./avahi-daemon.sh 108 109.. _`net-tools`: https://github.com/zephyrproject-rtos/net-tools 110 111LLMNR Responder 112=============== 113 114If you want Zephyr to respond to a LLMNR DNS request that Windows host is 115sending, then following config options could be set: 116 117.. code-block:: cfg 118 119 CONFIG_NET_HOSTNAME_ENABLE=y 120 CONFIG_NET_HOSTNAME="zephyr-device" 121 CONFIG_DNS_RESOLVER=y 122 CONFIG_LLMNR_RESPONDER=y 123 124A Zephyr host needs a hostname assigned to it so that it can respond to a DNS 125query. Note that the hostname should not have any dots in it. 126 127 128QEMU x86 129======== 130 131To use QEMU for testing, follow the :ref:`networking_with_qemu` guide. 132 133 134FRDM K64F 135========= 136 137Open a terminal window and type: 138 139.. zephyr-app-commands:: 140 :zephyr-app: samples/net/dns_resolve 141 :board: frdm_k64f 142 :goals: build flash 143 :compact: 144 145See :zephyr:board:`Freedom-K64F board documentation <frdm_k64f>` for more information 146about this board. 147 148Open a terminal window and type: 149 150.. code-block:: console 151 152 $ screen /dev/ttyACM0 115200 153 154 155Use 'dmesg' to find the right USB device. 156 157Once the binary is loaded into the FRDM board, press the RESET button. 158 159Wi-Fi 160===== 161 162The IPv4 Wi-Fi support can be enabled in the sample with 163:ref:`Wi-Fi snippet <snippet-wifi-ipv4>`. 164