Skip to content

Hostname not sent via DHCP request #2537

Closed
@adydeac

Description

@adydeac

Hardware:

Board: ESP32 Dev Module
Core Installation version: 1.0.1
IDE name: Arduino IDE
Flash Frequency: 80Mhz
PSRAM enabled: no
Upload Speed: 115200
Computer OS: Debian

Description:

Hi,
I've noticed that somehow (I guess recently?) the hostname is not sent when making DHCP calls:

tcpdump -Anev -s 1024 -i br-lan port 67 or port 68 or port 69

tcpdump: listening on br-lan, link-type EN10MB (Ethernet), capture size 1024 bytes
01:22:43.011475 30:ae:a4:14:3f:e0 > ff:ff:ff:ff:ff:ff, ethertype IPv4 (0x0800), length 350: (tos 0x0, ttl 255, id 0, offset 0, flags [none], proto UDP (17), length 336)
0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 30:ae:a4:14:3f:e0, length 308, xid 0xaedfb4c4, Flags [none]
Client-Ethernet-Address 30:ae:a4:14:3f:e0
Vendor-rfc1048 Extensions
Magic Cookie 0x63825363
DHCP-Message Option 53, length 1: Request
MSZ Option 57, length 2: 576
Requested-IP Option 50, length 4: 172.16.0.195
Parameter-Request Option 55, length 12:
Subnet-Mask, Default-Gateway, BR, Domain-Name-Server
Domain-Name, Netbios-Name-Server, Netbios-Node, Netbios-Scope
Router-Discovery, Static-Route, Classless-Static-Route, Vendor-Option
E..P.................D.C.<.}............................0...?...........................................................................................................................................................................................................c.Sc5..9..@2.....7......,./.!y+.........................................
01:22:43.014082 e8:de:27:6d:29:35 > 30:ae:a4:14:3f:e0, ethertype IPv4 (0x0800), length 342: (tos 0x0, ttl 64, id 7494, offset 0, flags [none], proto UDP (17), length 328)
172.16.0.1.67 > 172.16.0.195.68: BOOTP/DHCP, Reply, length 300, xid 0xaedfb4c4, Flags [none]
Your-IP 172.16.0.195
Server-IP 172.16.0.2
Client-Ethernet-Address 30:ae:a4:14:3f:e0
sname "tftp"
file "pxelinux.0"
Vendor-rfc1048 Extensions
Magic Cookie 0x63825363
DHCP-Message Option 53, length 1: ACK
Server-ID Option 54, length 4: 172.16.0.1
Lease-Time Option 51, length 4: 259200
RN Option 58, length 4: 129600
RB Option 59, length 4: 226800
Subnet-Mask Option 1, length 4: 255.255.255.0
BR Option 28, length 4: 172.16.0.255
Default-Gateway Option 3, length 4: 172.16.0.1
Domain-Name-Server Option 6, length 4: 172.16.0.1
Domain-Name Option 15, length 3: "lan"
E..H.F..@..{.........C.D.4Z*............................0...?...........tftp............................................................pxelinux.0......................................................................................................................c.Sc5..6.....3.....:....@;...u...........................lan....

This is the on the same router, but with an request from an android phone:

I am using the ESP-WROOM-32 chipset and Arduino IDE on Linux.

The code snippet is:

Sketch: (leave the backquotes for code formatting)

//Change the code below by your sketch
#include <Arduino.h>

void setup() {
  WiFi.begin(wifiSSID, wifiPass);
  nodeName = "shower-" + WiFi.macAddress();
  nodeName.replace(":", "");
  char _nodeName[20]; nodeName.toCharArray(_nodeName, 20);
  WiFi.setHostname(_nodeName);
  WiFi.mode(WIFI_STA);
}

void loop() {
}

Activity

luisgcu

luisgcu commented on Mar 7, 2019

@luisgcu

@adydeac we have detected the same issue in project where we use a web server application, I think we detected the problem because we have several ESP32 in the same wifi network , we can't access the esp32's web-server application and we can't ping them on the network until they are connected for some time on the network(3-5minutes) and we believe that is caused because the esp32 exposes all the same host name "espressif" .. Anyone that can guide us on how to properly set the ESP32 host names ?

lbernstone

lbernstone commented on Mar 7, 2019

@lbernstone
Contributor

This probably should be looked at upstream. https://github.com/espressif/esp-idf/blob/master/components/lwip/port/esp32/netif/wlanif.c#L205. If you add this file into your sketch folder, you could write some code to give each machine a unique name.

beegee-tokyo

beegee-tokyo commented on Mar 7, 2019

@beegee-tokyo
Contributor

@luisgcu
Not a 100% sure if that is what you are looking for, but I give my ESP32's different names with

char _hostname[20];
uint8_t mac[6];
WiFi.macAddress(mac);
sprintf(_hostname, "esp32-%02x%02x%02x%02x%02x%02x", 
          mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
MDNS.begin(_hostname);
atanisoft

atanisoft commented on Mar 7, 2019

@atanisoft
Collaborator

You can set the hostname before calling wifi.begin(). You just need to set the mode first. Then you should get a unique hostname.

atanisoft

atanisoft commented on Mar 7, 2019

@atanisoft
Collaborator

@beegee-tokyo that only sets the mDNS advertised hostname and not the wifi hostname that shows up on the router. But that is good practice to set a unique hostname.

adydeac

adydeac commented on Mar 7, 2019

@adydeac
Author

As you can see from the tcpdump on the router (running openwrt, the gateway, the only DHCP server in the network), there is no hostname sent. Please see tha ascii dump as well. No "espressif" or anything. Something has changed maybe in the latest code? Or we need to enable the hostname sending?

asetyde

asetyde commented on Mar 7, 2019

@asetyde

also with 1.0.2 RC1 ?

adydeac

adydeac commented on Mar 7, 2019

@adydeac
Author

Same.

[before update]
Thu Mar 7 11:07:45 2019 daemon.info hostapd: wlan0: STA 30:ae:a4:14:3f:e0 IEEE 802.11: authenticated
Thu Mar 7 11:07:45 2019 daemon.info hostapd: wlan0: STA 30:ae:a4:14:3f:e0 IEEE 802.11: associated (aid 2)
Thu Mar 7 11:07:45 2019 daemon.info hostapd: wlan0: STA 30:ae:a4:14:3f:e0 WPA: pairwise key handshake completed (RSN)
Thu Mar 7 11:07:45 2019 daemon.info dnsmasq-dhcp[21458]: DHCPREQUEST(br-lan) 172.16.0.195 30:ae:a4:14:3f:e0
Thu Mar 7 11:07:45 2019 daemon.info dnsmasq-dhcp[21458]: DHCPACK(br-lan) 172.16.0.195 30:ae:a4:14:3f:e0
Thu Mar 7 11:08:01 2019 cron.info crond[893]: crond: USER root pid 22271 cmd /scripts/check_snmpd

[after update]
Thu Mar 7 11:09:29 2019 daemon.info hostapd: wlan0: STA 30:ae:a4:14:3f:e0 IEEE 802.11: authenticated
Thu Mar 7 11:09:29 2019 daemon.info hostapd: wlan0: STA 30:ae:a4:14:3f:e0 IEEE 802.11: associated (aid 2)
Thu Mar 7 11:09:29 2019 daemon.info hostapd: wlan0: STA 30:ae:a4:14:3f:e0 WPA: pairwise key handshake completed (RSN)
Thu Mar 7 11:09:29 2019 daemon.info dnsmasq-dhcp[21458]: DHCPREQUEST(br-lan) 172.16.0.195 30:ae:a4:14:3f:e0
Thu Mar 7 11:09:29 2019 daemon.info dnsmasq-dhcp[21458]: DHCPACK(br-lan) 172.16.0.195 30:ae:a4:14:3f:e0

The code:
void startWiFi() {
WiFi.begin(wifiSSID, wifiPass);
nodeName = "shower-" + WiFi.macAddress();
nodeName.replace(":", "");
char _nodeName[20]; nodeName.toCharArray(_nodeName, 20);
#ifdef DEBUG
Serial.print("WiFi: MAC: "); Serial.println(WiFi.macAddress());
Serial.print("WiFi: setting hostname "); Serial.print(nodeName); Serial.println("...");
#endif
WiFi.setHostname(_nodeName);
tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA, _nodeName);
WiFi.mode(WIFI_STA);
}

Debug messages:
WiFi: MAC: 30:AE:A4:14:3F:E0
WiFi: setting hostname shower-30AEA4143FE0...

atanisoft

atanisoft commented on Mar 7, 2019

@atanisoft
Collaborator

Move wifi.mode and wifi.sethostname before WiFi.begin. the call to tcpip adapter shouldn't be necessary as that is done inside the wifi library

adydeac

adydeac commented on Mar 8, 2019

@adydeac
Author

WiFi.mode(WIFI_STA);
nodeName = "shower-" + WiFi.macAddress();
nodeName.replace(":", "");
char _nodeName[20]; nodeName.toCharArray(_nodeName, 20);
#ifdef DEBUG
Serial.print("WiFi: MAC: "); Serial.println(WiFi.macAddress());
Serial.print("WiFi: setting hostname "); Serial.print(nodeName); Serial.println("...");
#endif
WiFi.setHostname(_nodeName);
//tcpip_adapter_set_hostname(TCPIP_ADAPTER_IF_STA, _nodeName);
WiFi.begin(wifiSSID, wifiPass);

Same:
Fri Mar 8 09:37:31 2019 daemon.info hostapd: wlan0: STA 30:ae:a4:14:3f:e0 IEEE 802.11: authenticated
Fri Mar 8 09:37:31 2019 daemon.info hostapd: wlan0: STA 30:ae:a4:14:3f:e0 IEEE 802.11: associated (aid 2)
Fri Mar 8 09:37:31 2019 daemon.info hostapd: wlan0: STA 30:ae:a4:14:3f:e0 WPA: pairwise key handshake completed (RSN)
Fri Mar 8 09:37:31 2019 daemon.info dnsmasq-dhcp[21458]: DHCPREQUEST(br-lan) 172.16.0.195 30:ae:a4:14:3f:e0
Fri Mar 8 09:37:31 2019 daemon.info dnsmasq-dhcp[21458]: DHCPACK(br-lan) 172.16.0.195 30:ae:a4:14:3f:e0

Probably you have noticed that not even the default "espressif" hostname is sent...

lbernstone

lbernstone commented on Mar 8, 2019

@lbernstone
Contributor

I don't know if toCharArray is mangling it somehow,but I have definitely seen invalid names (non-printable chars) come through while watching a tcpdump on the router. This is working for me:

  Serial.begin(115200);
  char hname[19]; // 5+12+1 - don't forget the \0
  snprintf(hname, 19, "ESP32-%012llX", ESP.getEfuseMac());  
  Serial.println(hname);
  WiFi.disconnect();
  WiFi.mode(WIFI_STA);
  WiFi.setHostname(hname);
  WiFi.begin("ssid","passwd");
  WiFi.waitForConnectResult();
  Serial.print("IP Address: ");
  Serial.println(WiFi.localIP());
adydeac

adydeac commented on Mar 10, 2019

@adydeac
Author

Same result:
rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1100
load:0x40078000,len:10312
load:0x40080400,len:6460
entry 0x400806a4
ESP32-E03F14A4AE30
IP Address: 172.16.0.195

tcpdump -Anev -s 1024 -i br-lan port 67 or port 68 or port 69

10:15:57.942822 30:ae:a4:14:3f:e0 > ff:ff:ff:ff:ff:ff, ethertype IPv4 (0x0800), length 350: (tos 0x0, ttl 255, id 0, offset 0, flags [none], proto UDP (17), length 336)
0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 30:ae:a4:14:3f:e0, length 308, xid 0x31888ad2, Flags [none]
Client-Ethernet-Address 30:ae:a4:14:3f:e0
Vendor-rfc1048 Extensions
Magic Cookie 0x63825363
DHCP-Message Option 53, length 1: Request
MSZ Option 57, length 2: 576
Requested-IP Option 50, length 4: 172.16.0.195
Parameter-Request Option 55, length 12:
Subnet-Mask, Default-Gateway, BR, Domain-Name-Server
Domain-Name, Netbios-Name-Server, Netbios-Node, Netbios-Scope
Router-Discovery, Static-Route, Classless-Static-Route, Vendor-Option
E..P.................D.C.<].....1.......................0...?...........................................................................................................................................................................................................c.Sc5..9..@2.....7......,./.!y+.........................................
10:15:57.945361 e8:de:27:6d:29:35 > 30:ae:a4:14:3f:e0, ethertype IPv4 (0x0800), length 342: (tos 0x0, ttl 64, id 7492, offset 0, flags [none], proto UDP (17), length 328)
172.16.0.1.67 > 172.16.0.195.68: BOOTP/DHCP, Reply, length 300, xid 0x31888ad2, Flags [none]
Your-IP 172.16.0.195
Server-IP 172.16.0.2
Client-Ethernet-Address 30:ae:a4:14:3f:e0
sname "tftp"
file "pxelinux.0"
Vendor-rfc1048 Extensions
Magic Cookie 0x63825363
DHCP-Message Option 53, length 1: ACK
Server-ID Option 54, length 4: 172.16.0.1
Lease-Time Option 51, length 4: 259200
RN Option 58, length 4: 129600
RB Option 59, length 4: 226800
Subnet-Mask Option 1, length 4: 255.255.255.0
BR Option 28, length 4: 172.16.0.255
Default-Gateway Option 3, length 4: 172.16.0.1
Domain-Name-Server Option 6, length 4: 172.16.0.1
Domain-Name Option 15, length 3: "lan"
E..H.D..@..}.........C.D.4Z*....1.......................0...?...........tftp............................................................pxelinux.0......................................................................................................................c.Sc5..6.....3.....:....@;...u...........................lan....

I am using the latest dev libraries.

Am I doing something wrong? Is my board broken in any way?

rpannekoek

rpannekoek commented on Mar 10, 2019

@rpannekoek

I'm having the same issue (using Wemos LOLIN D32 board). I have also tried every imaginable position of doing the setHostName call:

  • After Wifi.mode(WIFI_STA) but before WiFi.begin
  • After WiFi.begin
  • Using an event handler (WiFi.onEvent) which triggers on the STA_START event

Whatever I try, the DHCP request sent by the ESP32 never contains a Host Name (DHCP Option 12), unlike for other devices (including ESP8266 boards) which do properly set their hostname.

As a result, the router (FritzBox) lists the WiFi device as "espressif" instead of the desired hostname (it's not clear to me where this "espressif" name comes from, because I don't see that anywhere in the DHCP Request either) and the built-in DNS server does not create a record for the hostname.

rpannekoek

rpannekoek commented on Mar 10, 2019

@rpannekoek

Another (less important) issue: I'm creating libraries which work on both ESP8266 and ESP32. The API for setting hostname is currently different between ESP8266 and ESP32:

  • ESP8266: WiFi.hostname() should be called before WiFi.begin
  • ESP32: WiFi.setHostName() unclear where it should be called, but most reports mention after WiFi.begin (for example: Hostname and DNS #1259 )
atanisoft

atanisoft commented on Mar 10, 2019

@atanisoft
Collaborator

@adydeac this may need to be moved to https://github.com/espressif/esp-idf as the DHCP implementation is implemented there (in the lwip stack actually).

69 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @danielfaust@beegee-tokyo@vshymanskyy@jeroenst@stickbreaker

        Issue actions

          Hostname not sent via DHCP request · Issue #2537 · espressif/arduino-esp32