Cant get connected to arduino from internet (portforwarded or not)

Ok my project needs to recive tcp data on a port.
I´m using a arduino mega 2560 R3 with a ethernet shield R3.
So i first tried with the webserver example.
And it works great on my lan no problem at all.
But when i´m trying to connect it from online/internet it wont work.
I have a portforwad for the outside port to my local ip and port but it doesnt work.
And i have alot of other portforwarding that works great so i dont understand why there should be any problems.
At one point i even tried putting the arduino directly into the dsl modem and i saw that by dhcp it got the right ip adress,gateway and subnet.
I have also tried the webserver example and that to work on my lan but not from internet.
Pinging also works great on lan but not on internet.
All my connections by using the internet adress is tried from another server with another ip as i know i vcant reach my own http adress from my lan.
And the arduino can access internet if i use the webclient.
So it´s only inbound traffic.
My portforwarding is all others like this

iptables -t nat -A PREROUTING -p tcp --dport 10023 -i $EXTIF -j DNAT --to 192.168.1.45:23000

i´m using 1.0.5
The code i´m using is this

#include <SPI.h>
#include <Dhcp.h>
#include <Dns.h>
#include <Ethernet.h>
#include <EthernetClient.h>
#include <EthernetServer.h>
#include <EthernetUdp.h>
#include <util.h>

byte mac[] = {
  0x90, 0xA2, 0xDA, 0x0E, 0xB9, 0x38 };
byte ip[] = {
  192, 168, 1, 45 };
byte gateway[] = {
  192, 168, 1, 1 };

byte subnet[] = {
  255, 255, 255, 0 };

EthernetServer server(23000);

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }
  /// disabeling the SD card
  pinMode(4, OUTPUT);
  digitalWrite(4, HIGH);

  // start the Ethernet connection and the server:
  Ethernet.begin(mac);
  Serial.println("DHCP running");
  Ethernet.maintain();
  //start the Ethernet connection:
  if (Ethernet.begin(mac) == 0)
  {

    Serial.println("Failed DHCP");//-

    // no point in carrying on, so do nothing forevermore:
    for (;;)
      ;
  }
  Ethernet.maintain();

  delay(2000);


  Serial.println();

  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
  // Serial.print("DNS ");
  // Serial.println(Ethernet.dnsIP());
  Serial.print("Gateway ");
  Serial.println(Ethernet.gatewayIP());

  Serial.print("Subnet ");
  Serial.println(Ethernet.subnetMask());
  server.begin();
}


void loop() {

  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
            int sensorReading = analogRead(analogChannel);
            client.print("analog input ");
            client.print(analogChannel);
            client.print(" is ");
            client.print(sensorReading);
            client.println("
");
          }
          client.println("</html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        }
        else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disonnected");
  }
}

I have aslo tried webserver on my arduino uno with a ethernet shield but with the same result.

So i think i need some help.
Hope i have been clear with what i want and have been testing.

But when i´m trying to connect it from online/internet it wont work.

An example of how you (try to) connect to it from the same network and from a different network would be useful. The same IP address won't work for both cases.

If you are port forwarding that port only, ping won't work from the internet. Only tcp port 10023. It will be forwarded to port 23000 on the localnet.

If you are using this, you are not assigning that ip to the w5100. The dhcp server is assigning an ip, and probably not the ip you think.

// don't use this on the localnet
// Ethernet.begin(mac);
// use this instead
Ethernet.begin(mac, ip , gateway, gateway, subnet);

This should be moved into the loop() if you are using dhcp, but for a server, I use a static assignment.

  Ethernet.maintain();

edit: PaulS is correct. You should use the public ip assigned to your router from the internet.
http://xx.xx.xx.xx:10023

Well i simply use the local ip 192.168.1.45:23000 when trying on local network
When i´m on my other server i use our internet ip 85.225.11.155:10023.

I try both these in chrome i have also tried the chatserver with telnet from local wich works but neever from outside.
As i say i can connect to several other portforwarded cameras,z-wave controller etc.

The dhcp is asigning 192.168.1.45 becouse i have hardcoded it to the mac adress .
I didn´t change it after i connected it directly to the dsl modem.
and it will always show me the ip it has in the terminal becouse

 Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
  // Serial.print("DNS ");
  // Serial.println(Ethernet.dnsIP());
  Serial.print("Gateway ");
  Serial.println(Ethernet.gatewayIP());

  Serial.print("Subnet ");
  Serial.println(Ethernet.subnetMask());
  server.begin();

Then your port forwarding is not working. Without port forwarding, it will never work. Why are you using one port on the public ip, and another on your localnet?

edit: ...and you did open the firewall for that port, correct? That is the main problem people have with port forwarding.

I would thik that also but all my other portforwarding is working.
And yes the port is also open in the firewall.
I have tried the portforwardinng i changed the row to my computer ip adress and my port 80 wich is showing my blue iris web server(camera app).
And that worked so the portfowarding is working but somehow the arduino cant respond to connection i´m thiking im maybe having something todo with the gateway.
As all my local connections and pings worked but when i tried it directly into the modem i saw i got a internet ip,gateway and subnet but could not ping or tcp to that ip.

and why i use diffrent ports.
I have tested with diffrent ports both on outside and in the arduino.

As all my local connections and pings worked but when i tried it directly into the modem i saw i got a internet ip,gateway and subnet but could not ping or tcp to that ip.

Check your network settings. If the gateway (or subnet mask) is not correct, you will have problems. You did mention that the ethernet client example worked to the internet? That should use the same settings you need for this.

Your server is responding. Check those network settings. This is the resonse I got:

Forbidden

You don't have permission to access / on this server.

Apache/2.2.22 (Ubuntu) Server at 85.225.11.155 Port 80

Check your network settings. If the gateway (or subnet mask) is not correct, you will have problems. You did mention that the ethernet client example worked to the internet? That should use the same settings you need for this.

Well when i connected it directly to the dsl modem i used dhcp so my internet provider was giving me the adresses and subnet and it semmed legit.

Your server is responding. Check those network settings. This is the resonse I got:

Yeah thats my server responding to port 80 .
The arduino is on port 10023 and that is not responding online only local.

My arduino can reach the internet it can fetch pages but when i´m trying to access it from another computer,mobile online it wont work
Even though i have confirmed the portforwarding to work when changed to my computer that sits on another ip on my lan.

I can't connect to port 10023 with your ip. ??

Just as a test, can you port forward port 10023 to your Apache webserver also?

Now i have set the portforwarding of port 10023 to my blue iris camera app but it gives a 404 .
But that doesnt matter it hows that the portforwarding works fine
iptables -t nat -A PREROUTING -p tcp --dport 10023 -i $EXTIF -j DNAT --to 192.168.1.30:80

The server shows ok. I don't know what to tell you now.

edit: Except that was not the same page I got from port 80, and it should have been. ??

This is what i get when i surf to the arduino localy

edit: Except that was not the same page I got from port 80, and it should have been. ??

No there not the same
the port 80 on my internet ip is going to my server 192.168.1.1
The page you got when going to ip:10023 is my computer at 192.168.1.30
So two diffrent pages but it shows that the portforwarding works.

The only thing i can think of is i the arduino somhow dont manage the gateway right.
So it cant respond.
i see the rx light blinking but not much tx.
Is those lights only for the ethernet?

Thanks for helping out anyway

Then why is this page different? It should have looked exactly as the page above on port 80.

The page cannot be displayed
The page you requested could not be accessed for some reason. It may be a temporary error on the other end, or you may have asked for an invalid page. The error message below may help you diagnose the problem.

Error Information:

Error Code: 404
Error Message: The file requested was not found on this server

It should have looked just like this:

Forbidden

You don't have permission to access / on this server.

Apache/2.2.22 (Ubuntu) Server at 85.225.11.155 Port 80

And also as i mentioned i have a uno with a ethernet shield 3 and it works the same.
And on that i have a project that opens a php page and read the results.
It´s a nfc door look opener.
So they do have access to the internet and can get responses.

I could program the mega to use the same tactic but i dont really want to.
The project for mega is supposed to be a drink bot that reciives a tcp connection from my phppage and tells the arduino what to pour.
But instead of triggering from the php page i could trigger when someone places a glass by the tap and then load the php page and get response.

Then why is this page different? It should have looked exactly as the page above on port 80.
Quote
The page cannot be displayed
The page you requested could not be accessed for some reason. It may be a temporary error on the other end, or you may have asked for an invalid page. The error message below may help you diagnose the problem.

Error Information:

Error Code: 404
Error Message: The file requested was not found on this server
It should have looked just like this:
Quote
Forbidden

You don't have permission to access / on this server.

Apache/2.2.22 (Ubuntu) Server at 85.225.11.155 Port 80

No they are diffrent pages the first is on my servers apache local ip 192.168.1.1
The other one is my desktop computer (not the server) with local ip 192.168.1.30
And the second page is only my Cammera app Blue iris that gives the 404.

I checked my server code...
http://playground.arduino.cc/Code/WebServerST
...on my router, port forwarded, and it worked fine from the internet.

Oh, what the heck...here is my server ip:port
http://68.99.58.119:8088
Can you get that?

Ok i dont know what did it.
But i copied the same project as you and then i changed to ports just for simplyfing it set it to port 80 local and as you did 8088
And now it works!?!

it most have been something strange with the port becouse when i try with 10023 it wont work even though it is portforwarded to port 80

But what the heck now i can at least start programming dont really care what port.
The starnge thing is i have tried diffrent port before .

But thanks alot for sticking with me.