[Solved] Can't change IP address?

I am working on adding Ethernet capability to my project and have added routines for setting and changing the IP address, gateway address and netmask, but have run into a problem in when I run the sketch it neither sets the IP address, nor can I change it. I can’t ping anything.

I tried the example from here which works perfectly:


I added a delay of 5 seconds after Ethernet.begin() to give me time to ping the interface before and after the change and I can ping both the old address before and then the new IP address after the change as expected. Clearly then, the setLocalIP() and other methods do work, but for some reason they don’t in my code. The only difference perhaps is that the functions are placed in a supplementary rather cpp than the main ino program and I am therefore calling them indirectly, but ultimately I am simply invoking the exact same methods. I have attached my code files.

Test-Ethernet.ino (4.72 KB)

My_Ethernet.h (853 Bytes)

My_Ethernet.cpp (2.42 KB)

My_Config.h (1.14 KB)

use Ethernet.begin with your static IP: Arduino - EthernetBegin
It will work.

I have solved it. The problem turned out to be my chosen mac address:

byte macAddr[] = {0x23,0x41,0x52,0x34,0x38,0x38};

I changed this for the one in the example linked in the previous post:

byte macAddr[] = {0xDE,0xAD,0xBE,0xEF,0xFE,0xED};

It then worked. I have since tried a handful of other random MAC addresses which seemed to work just fine as well so what was the chance of picking one in particular that doesn't work? Also, WHY does this particular MAC address not work? Are there certain byte values that cannot be used perhaps?

After as bit more digging it seems that there are certain rules to choosing MAC addresses and one can't just choose anything at random. The first 3 octets form something called the Organizationally Unique Identifier (OUI) which is essentially a manufacturers ID. One should therefore avoid using a sequence that is already used (and purchased by) a manufacturer.

In addition, the first octet has an additional significance. The first bit of the first byte, when set, signifies this is a broadcast address. Therefore a value should be chosen for this octet that leaves this bit unset. On the other hand, setting the second bit of the first octet flags the mac as a local address, a bit like the reserved RFC1918 private ranges for IP addresses. A value needs to be chosen for the first octet that sets this bit.

The second post in the following link shows the ranges that can be used:

These are shown as being:


The MAC address in the example starts with DE so falls into the last range.

I thought I would post this information as it might help someone else running into this problem.