SDK Lwip DNS - dns_gethostbyname(), how to let it work with static IP settings

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SDK Lwip DNS - dns_gethostbyname(), how to let it work with static IP settings

2,568 Views
ping1
Contributor V

Hi, all

Try to use the function to resolve IP address from domain names, it works fine when IP setting is configured as DHCP, however when it is configured as STATIC, it doesn't work. It seems use DHCP server as DNS server.

I run lwip on bare metal - not sure there is any alternative function.

Any suggestion?

Thanks!

Ping

Labels (1)
0 Kudos
3 Replies

2,550 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi @ping1 :

 

Under the DHCP mode, the DNS server is configured correctly by the DHCP server.

With static mode, you need to set the right DNS server by yourself. You should be very careful. Maybe that is the reason.

void  dns_setserver (u8_t numdns, const ip_addr_t *dnsserver)

 

 

Regards

Daniel

0 Kudos

2,539 Views
ping1
Contributor V

Hi, Daniel

Thanks for reply, you are right that DNS server is handled by DHCP server in DHCP mode.

I just wonder how to get it work in static situation, if it needs DNS server IP address , is there a way to tell the LWIP? will it still work? Any examples?

Thanks

Ping

 

0 Kudos

2,535 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi @ping1 :

First you need to know the right DNS server in your network, for example, 1.1.1.1

Please refer to below code.

#include "lwip/dns.h"

ip_addr_t dnsServerIp;
IP_ADDR4( &dnsServerIp, "1.1.1.1");
dns_setserver(0, &dnsServerIp);

 

 Regards

Daniel

0 Kudos