Retrieving a second DNS server IP

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

Retrieving a second DNS server IP

Jump to solution
3,145 Views
panpwr
Contributor IV

Hello,

When I connect my laptop to the my office network, I receive 2 DNS addresses.

However, When I use my TWR-K60D100M, with the following code , I receive only one DNS address (I assume it should be stored automatically in the DNS list, once I get an IP using the DHCP client??):

/* Get IP address from DHCP server */

result = ipcfg_bind_dhcp_wait(BSP_DEFAULT_ENET_DEVICE, FALSE, NULL); //FALSE = don't bind static IP after failure

if (result == IPCFG_OK)

{

    is_successful = ipcfg_get_ip(BSP_DEFAULT_ENET_DEVICE, &ip_data);

    if (is_successful)

    {

        // Get DNS_1 server

        dns = ipcfg_get_dns_ip (BSP_DEFAULT_ENET_DEVICE, 0);

        if (dns != 0)

        {

          // THE FIRST DNS IS VALID!!!

        }

     

        // Get DNS_2 server

        dns = ipcfg_get_dns_ip (BSP_DEFAULT_ENET_DEVICE, 1); //<<=== This returns zero dns address, rather than the 2nd DNS which should  have been supplied by DHCP server.

    }

}

Labels (1)
Tags (3)
1 Solution
2,433 Views
karelm_
Contributor IV

Hi, after quick look at code of ipcfg_get_dns_ip function it seems, that if you use lightweight DNS resolver (which is default in MQX) only one DNS server IP is stored (in variable LWDNS_server_ipaddr) and this address is returned (zero is return value for any other DNS server index other than zero). If you want to have multiple DNS servers, than you have to use full DNS resolver by adding following configuration to file user_config.h:

#define RTCSCFG_ENABLE_LWDNS       0

#define RTCSCFG_ENABLE_DNS            1

#define RTCSCFG_ENABLE_LOOPBACK 1

Best Regards,

Karel

View solution in original post

9 Replies
2,433 Views
hfyuksel
Contributor I

I have 2 DNS servers. But one return to me. No solution proposal proposed before has solved this problem.
https://community.nxp.com/message/317385?commentID=317385#comment-317385
and
https://community.nxp.com/thread/301815
The version i use is 4.2.0.2

#define RTCSCFG_ENABLE_LWDNS 0
#define RTCSCFG_ENABLE_DNS 1
#define RTCSCFG_ENABLE_LOOPBACK 1
The above suggestions did not solve the problem.

Can you help me?

0 Kudos
2,433 Views
michris
Contributor III

Dear,

I tried to add a second and third DNS server address, but it seems not to work.

As understood in this thread, I can not use LWDNS, so I used DNS instead of LWDNS

(I use MQX3.8.1 on a K70 device)

   // User_config.h :

   // #define RTCSCFG_ENABLE_LWDNS       0

   // #define RTCSCFG_ENABLE_DNS            1

   // #define RTCSCFG_ENABLE_LOOPBACK 1

   _ip_address DNS_server_ipaddr;

   DNS_server_ipaddr = inet_addr("8.8.8.8");  // Open dns server1 

   if (ipcfg_add_dns_ip(ENET_DEVICE,DNS_server_ipaddr) == TRUE) {printf("DNS added ok");}

   DNS_server_ipaddr = inet_addr("208.67.222.222");  // Open dns server1 

   if (ipcfg_add_dns_ip(ENET_DEVICE,DNS_server_ipaddr) == TRUE) {printf("DNS added ok");}

   DNS_server_ipaddr = inet_addr("208.67.220.220");  // Open dns server2 

   if (ipcfg_add_dns_ip(ENET_DEVICE,DNS_server_ipaddr) == TRUE) {printf("DNS added ok");}

   printf("DNS0: %d.%d.%d.%d",IPBYTES(ipcfg_get_dns_ip(ENET_DEVICE,0)));
   printf("DNS1: %d.%d.%d.%d",IPBYTES(ipcfg_get_dns_ip(ENET_DEVICE,1)));
   printf("DNS2: %d.%d.%d.%d",IPBYTES(ipcfg_get_dns_ip(ENET_DEVICE,2)));

The result is that it seems to add the three dns servers => 3x DNS added ok

But when I print them out, I only have the last DNS IP at the first location. (so it seems the overwrite each other ???)

DNS0 : 208.67.220.200

DNS1 : 0.0.0.0

DNS2 : 0.0.0.0


Any idea's?

Thanks in advance.

Regards,

Michris





0 Kudos
2,433 Views
danielchai
Senior Contributor I

Hi Michris,

I am facing the same problem. After change the

   #define RTCSCFG_ENABLE_LWDNS       0

   #define RTCSCFG_ENABLE_DNS            1

   #define RTCSCFG_ENABLE_LOOPBACK 1

I still only get one DNS server IP.

Did you solve it?

Thank you.

-Daniel

0 Kudos
2,433 Views
michris
Contributor III

Hi Daniel,

I still have the same problem, even with the latest version of MQX.

Regards,

Michris

0 Kudos
2,434 Views
karelm_
Contributor IV

Hi, after quick look at code of ipcfg_get_dns_ip function it seems, that if you use lightweight DNS resolver (which is default in MQX) only one DNS server IP is stored (in variable LWDNS_server_ipaddr) and this address is returned (zero is return value for any other DNS server index other than zero). If you want to have multiple DNS servers, than you have to use full DNS resolver by adding following configuration to file user_config.h:

#define RTCSCFG_ENABLE_LWDNS       0

#define RTCSCFG_ENABLE_DNS            1

#define RTCSCFG_ENABLE_LOOPBACK 1

Best Regards,

Karel

2,433 Views
panpwr
Contributor IV

I will try that, that you very much!

0 Kudos
2,433 Views
panpwr
Contributor IV

Can someone please pick this question up?

Thank you,

Lior.

0 Kudos
2,433 Views
c0170
Senior Contributor III

Hello Lior,

I am going to ask around :smileywink:

Regards,

MartinK

2,433 Views
panpwr
Contributor IV

Thanks!

0 Kudos