I cannot get the subnet to change on a Ethernet card

Please could someone tell me how to actaully change the subnet mask? I have done lots of googling but everything says the same thing. I do not get any errors but it will just not change.

The code below is a good example of the ‘example’ code provided on this site (slightly modified to actually get it working) but the subnet just stays at the default 255,255,255,0.

Basically I am developing a project where I need to talk across multiple subnets (ie not just from talking to, but to I know a little about networking and I know that by changing the subnet to 255,255,254,0 it will let me do this.

It is not just a case that it is returning me a default value (ie 255,255,255,0) as in my large sketch I am unable to actually talk between devices if the 3rd octets do not match. By the way when I put both devices on the same subnet they can talk.

Can someone tell me if this should actually work because even the code in the reference section of this site does not appear to work.

#include <SPI.h>                 // needed for Arduino versions later than 0018
#include <Ethernet.h>

// network configuration.  gateway and subnet are optional.

 // the media access control (ethernet hardware) address for the shield:
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };  
// the router's gateway address:
byte gateway[] = { 10, 0, 0, 1 };
// the subnet:
byte subnet[] = { 255, 255, 254, 0 };

//the IP address is dependent on your network
IPAddress ip(192,168,1,1);

void setup()
  // initialize the ethernet device
  Ethernet.begin(mac, ip, gateway, subnet);


void loop()
  //print out the IP address and subnetMask

This is the Serial output:

Many thanks

Looks like you reading back what you entered. Do you expect anything different?

 byte subnet[] = { 255, 255, 254, 0 }
IPAddress ip(192,168,1,1);
This is the Serial output:

What I am trying to set it to is 255, 255, 254 , 0 (note the 254 in the 3rd octet) what I am getting back is 255,255,255,0 (ie not 254 in the 3rd BUT 255)

You are missing a parameter in the begin call. It needs a dns server. Below I use the gateway (router) ip for that.

// change this
  Ethernet.begin(mac, ip, gateway, subnet);
// to this
  Ethernet.begin(mac, ip, gateway, gateway, subnet);


Many thanks, I will try this later.

I had just been following the code in the below reference which doesnt include this. Maybe the site administrators could correct the examples shown on this site!


I did not notice that error. It has been reported to the webmaster. http://forum.arduino.cc//index.php?topic=192939.0

It has been corrected.