This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Static IP with automatic or DHCP DNS entry?

Hello,

I am currently configuring a TM4C1294 with either a static IP or to use DHCP on boot. The code works fine but when I specify a static IP, I also have to specify a DNS. Part of my code requires resolving a domain name using getaddrinfo().

I'm not a network expert but I wanted to know if there is a way to get the DNS addresses from the network automatically and only require the configuration of the static IP and default gateway.

Currently using TIRTOS 2.14.04.31.
Running test code on a TM4C1294XL eval board.

Thank you,
Subhash

  • Subhash,

    I'll have to get back to you on the DNS configuration details. In the meantime, maybe these forum threads might help.



    ~Ramsey

  • Subhash,

    It seems that the DNS address is obtained from the DHCP server. Even if you configure your target to use a static IP address, you would still use the DHCP server for the DNS address. If you don't have a DHCP server on your network, then you will have to manually configure the DNS address into your program.

    ~Ramsey

  • Subhash,

    Here is a way to configure the DNS server address (used by the NDK) from your application configuration script.

    var Dns = xdc.useModule('ti.ndk.config.Dns');
    Dns.externDnsServIp = "123.456.789.123";

    If adding this causes some linker errors (with undefined references), then you will need to rebuild the NDK product using Make. Look in the NDK Release Notes for instructions. This comes about because TI-RTOS ships a subset of the NDK libraries. For the full set of libraries, you need to rebuild the NDK product yourself.

    ~Ramsey

  • Hi Ramsey,

    Thank you for the replies.

    I did see both those links but they didn't answer my question.

    To be clear, I have both DHCP and STATIC IP configurations working correctly and I can switch between them without any issues.
    The ONLY question I have is if it's possible to configure a STATIC IP, MASK and ROUTE but somehow let DHCP handle identification of a DNS server. It seems that this is common practice on any computer (you can explicitly set a DNS server but it's most often not required).

    I don't think I fully understand your reply. Are you saying I can set the "DNS Server IP" to be the same as the default gateway/route and typically that will work?

    "Even if you configure your target to use a static IP address, you would still use the DHCP server for the DNS address."

    I will test this out and let you know what I find.

    Regards,
    Subhash
  • Hi Ramsey,

    I tested it out and it seems like setting the DNS server to the same as the default gateway works on my particular network setup. That's all I really need to know.

    Thanks for the help! Marking the above comment as answered.

    Regards,
    Subhash
  • Subhash,

    Sorry for the confusion. I was trying to explain that when using a static IP address for your device, you would still query the DHCP server for the IP address of the DNS servers. This would require you to write the code to perform this query. Our NDK stack does not perform this action by itself. Once you have acquired the DNS server IP address, you would configure the NDK stack at runtime.

    We don't have any example on how to do this. You will have to search network resources for this information.

    One final note. I think you are getting lucky when configuring the DNS server with your gateway IP address. I believe the gateway has cached the hostname to IP address in its local table. So, when you are asking the gateway to translate the hostname to IP address, it responds with a non-authoritative answer. But the entry will be flushed after 48 hours. At that point, the gateway will no longer be able to handle the request.

    In a typical scenario, when asking to translate a hostname to IP address, the request is passed to each router until an answer has been found. If none of the routers has an answer, the request finally reaches the DNS server which responds with an authoritative answer. This answer is cached by each router until the entry expires.

    ~Ramsey

  • Hi Ramsey,

    Thank you for the details, I really don't know much about the network details and you helped to clarify what I needed. I don't think I'll be able to implement custom code to do the query, but it's not really a required feature for me. It would just be for convenience. I think specifying an actual DNS server when configuring the device to have a static IP address won't be much of an issue.

    Regards,
    Subhash