Hostname Configuration

Overview

A networked device might need a hostname, for example, if the device is configured to be a mDNS responder (see DNS Resolve for details) and needs to respond to <hostname>.local DNS queries.

The CONFIG_NET_HOSTNAME_ENABLE must be set in order to store the hostname and enable the relevant APIs. If the option is enabled, then the default hostname is set to be zephyr by CONFIG_NET_HOSTNAME option.

If the same firmware image is used to flash multiple boards, then it is not practical to use the same hostname in all of the boards. In that case, one can enable CONFIG_NET_HOSTNAME_UNIQUE which will add a unique postfix to the hostname. By default the link local address of the first network interface is used as a postfix. In Ethernet networks, the link local address refers to MAC address. For example, if the link local address is 01:02:03:04:05:06, then the unique hostname could be zephyr010203040506. If you want to set the prefix yourself, then call net_hostname_set_postfix() before the network interfaces are created. For example for the Ethernet networks, the initialization priority is set by CONFIG_ETH_INIT_PRIORITY so you would need to set the postfix before that. The postfix can be set only once.

API Reference

Network Hostname Library