DHCP *AND* DNS with Ethernet Shield Library

DHCP AND DNS with Ethernet Shield Library

Referring to the Repeating Web Client sketch example provided with the Arduino IDE 1.0.1

I've made this work using a static IP address and DNS Server, as in the example sketch.

Is it possible to use DHCP to get a DYNAMIC IP address, while still using a DNS server to resolve a web address ?

The synatax is Ethernet.begin(mac, ip, myDns) for static IP with DNS funtionality.
Just plain Ethernet.begin(mac) for dynamic IP with NO DNS functionality.
I tried Ethernet.begin(mac, , myDNS), but that didn't work.

What I'm trying to do is to get a DYNAMIC IP address yet retain DNS funtionality.

Thank you for helping me.

Bob W

Yes. I use it. Call the Ethernet.begin(mac) function. The dhcp server will issue the dns server.

edit: If you want to see what was issued, add this after the Ethernet.begin(mac) call.

Serial.print("ip = ");
Serial.println(Ethernet.localIP());
Serial.print("subnet mask = ");
Serial.println(Ethernet.subnetMask());
Serial.print("gateway = ");
Serial.println(Ethernet.gatewayIP());
Serial.print("dns = ");
Serial.println(Ethernet.dnsServerIP());

SurferTim:
Yes. I use it. Call the Ethernet.begin(mac) function. The dhcp server will issue the dns server.

Tim:

Thank you so much!
That was shockingly easy !
Works great !

How did you know this ?
It was hiding in plain sight.
I never thought to try it.

Bob W

Hi Bob. Every time a new IDE version is released, I dig through the ethernet library to see what they have added. Just a bit of "code mining". :smiley: