Arduino can't connect to the Internet


i just build a device to measure my pool temperatures and send these temperatures to my local(!!) apache webserver.
The Arduino works as Server and Client. This worked fine.

Now i want my website to be on an external webserver, so my computer doesn’t have to run all day long.

But long story short, thats my problem:
My Arduino CAN’T connect (as client) to any server outside of my local network.
Even though,

  • I can access to my arduino (acting as server) from the internet.
  • My Arduino can connect to my local webserver (acting as client) and send temperature data.

I just don’t understand why the arduino can receive commands from the internet (server mode), but can’t send commands by itself (client mode).

My sketch is veery long, so here are the important parts:

   #include <SPI.h>
    #include <Ethernet.h>
      byte ip[] = { 192, 168, 178, 16 };   //ip address to assign the arduino
      byte gateway[] = { 192, 168, 178, 1 };    // the router's gateway address
      byte subnet[] = { 255, 255, 255, 0 };
      byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xEA, 0xC9 };

      byte bridge_server[] = {192, 168, 178, 21}; // LOCAL SERVER, WORKS!

//     char bridge_server[] = ""; // WEBSERVER'S DOMAIN, DOESN'T WORK
//     byte bridge_server[] = {88, 84, xxx, xxx}; // WEBSERVER'S IP, DOESN'T WORK
//     byte bridge_server[] = {74, 125, 224, 72}; //GOOGLE'S IP, DOESN'T WORK

    EthernetServer server = EthernetServer(80); // LISTEN ON PORT 80, 
   // MY NETWORK (tested with iphone and wlan off)
void setup()
      Ethernet.begin(mac, ip, gateway, subnet); // initialize the ethernet device
     server.begin(); // start listening for clients

void loop()
    EthernetClient client;
    if (client.connect(bridge_server, 80)) // HERE IT STUCKS, client.connect returns false (exception: local webserver
      Serial.println("CONNECTION OK!");
      ... do stuff ...
      Serial.println("CANT CONNECT!");

      EthernetClient client = server.available();
      if (client) 
          while (client.connected()) 
            if (client.available()) 
              .... do something and answer to the connected client, works fine.

Does anyone have a solution for my problem??

Some client test code:

//zoomkat 2-13-12
//DNS and DHCP-based web client test code
//for use with IDE 1.0
//open serial monitor and send an e to test
//and to see test result
//for use with W5100 based ethernet shields
//browser equivelant URL: 
//note that the below bug fix may be required

#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
char serverName[] = ""; // zoomkat's test web page server
EthernetClient client;


void setup(){
  Serial.println("DNS and DHCP-based web client test 2/13/12"); // so I can keep track of what is loaded
  Serial.println("Send an e in serial monitor to test"); // what to do to test
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
  // print your local IP address:
  Serial.print("Arduino IP address: ");
  for (byte thisByte = 0; thisByte < 4; thisByte++) {
    // print the value of each byte of the IP address:
    Serial.print(Ethernet.localIP()[thisByte], DEC);

void loop(){
  // check for serial input
  if (Serial.available() > 0) //if something in serial buffer
    byte inChar; // sets inChar as a byte
    inChar =; //gets byte from buffer
    if(inChar == 'e') // checks to see byte is an e
      sendGET(); // call sendGET function below when byte is an e


void sendGET() //client function to send/receive GET request data.
  if (client.connect(serverName, 80)) {  //starts client connection, checks for connection
    client.println("GET /~shb/arduino.txt HTTP/1.0"); //download text
    client.println(); //end of get request
  else {
    Serial.println("connection failed"); //error message if no client connect

  while(client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() || client.available()) { //connected or data available
    char c =; //gets byte from ethernet buffer
    Serial.print(c); //prints byte to serial monitor 

  client.stop(); //stop client



i figured out what went wrong.

The problem must have been related to my router (dhcp-server), when i only use mac and ip in Ethernet.begin() it works.

From IDE version 1.0 there was an update to the Ethernet library which meant that the parameters for the .begin() method are different.

The updated documentation:

You now need to specify the IP address of the DNS server (most times this would be the same as your router/gateway):

Ethernet.begin(mac, ip, dns, gateway, subnet);

By using the old parameter order with the new library, you would have been setting the gateway IP address to the subnet.

Hope that helps!