Setting server gateway, subnet interferes with ClientConnect?

Just curious about this When I set the gateway & subnet on my server...

IPAddress ip(192,168,1,177);
//setting subnet & gateway somehow interfers with calling external php script
IPAddress gateway(192,168,1,1); 
IPAddress subnet(255, 255, 255, 0);
Ethernet.begin(mac, ip, INADDR_NONE, gateway, subnet);

my code to connect to a client php script doesn't work

 //post
        client.println(F("POST /arduino_script/arduino_mail.php HTTP/1.1"));
        client.println(F("Host: www.host.com"));
        client.println(F("Connection: keep-alive"));
        client.println(F("Content-Type: application/x-www-form-urlencoded"));
        client.print(F("Content-Length: "));
        client.println(strlen(emailString));
        client.println();
        client.println(emailString);

But if I remove the gateway & subnet, it works.

Ethernet.begin(mac, ip);

Anybody knows why that is?

192,168,1,177 is port forward on the router btw.

my code to connect to a client php script doesn't work

In this case the Arduino is the client.

Anybody knows why that is?

Provide complete code, maybe we can find the bug there. We don't see how the connection to the server is established to give you an example of code missing.

192,168,1,177 is port forward on the router btw.

I don't see a reason why there should be a port forwarding on the router in this case.

Oh, that's a good point... It is a server but needs to make client calls to another server. My solution is to leave out the gateway & subnet so it works but not sure why that works.

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,177);
//setting subnet & gateway somehow interfers with calling external php script
//IPAddress gateway(192,168,1,1);   
//IPAddress subnet(255, 255, 255, 0);


// Initialize the Ethernet server library
// with the IP address and port you want to use 
// (port 80 is default for HTTP):
EthernetServer server(8080);

void setup(){
  Ethernet.begin(mac, ip);
}
EthernetClient client;
if (client.connect("www.host.com", 80)) {
        
        // Make a HTTP request:
        char emailString[200];
        char key[] = "greencontroller";
        sprintf(emailString, "to=%s&subject=%s&txt=%s&key=%s", WWWsettings::toEmail, in_subject, in_message, key);
    
         //post
        client.println(F("POST /arduino_script/arduino_mail.php HTTP/1.1"));
        client.println(F("Host: www.host.com"));
        client.println(F("Connection: keep-alive"));
        client.println(F("Content-Type: application/x-www-form-urlencoded"));
        client.print(F("Content-Length: "));
        client.println(strlen(emailString));
        client.println();
        client.println(emailString);

My solution is to leave out the gateway & subnet so it works but not sure why that works.

Because in your other code you disable the DNS server. If you don't specify it, the Arduino code just falls back to the default (IP 1 in your subnet) and it seems that your router does answer DNS requests (although it's probably just a repeater).

I guess with this code:

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

it works the same as with the above version.

BTW: What you posted is NOT complete code!

Sorry, I can't post the whole code because it's too large (thousands of lines) with libraries.

So I looked up Ethernet.cpp. It looks like gateway & DNS are the same when you don't define them.

void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip)
{
  // Assume the DNS server will be the machine on the same network as the local IP
  // but with last octet being '1'
  IPAddress dns_server = local_ip;
  dns_server[3] = 1;
  begin(mac_address, local_ip, dns_server);
}

void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server)
{
  // Assume the gateway will be the machine on the same network as the local IP
  // but with last octet being '1'
  IPAddress gateway = local_ip;
  gateway[3] = 1;
  begin(mac_address, local_ip, dns_server, gateway);
}

void EthernetClass::begin(uint8_t *mac_address, IPAddress local_ip, IPAddress dns_server, IPAddress gateway)
{
  IPAddress subnet(255, 255, 255, 0);
  begin(mac_address, local_ip, dns_server, gateway, subnet);
}

void EthernetClass::begin(uint8_t *mac, IPAddress local_ip, IPAddress dns_server, IPAddress gateway, IPAddress subnet)
{
  W5100.init();
  SPI.beginTransaction(SPI_ETHERNET_SETTINGS);
  W5100.setMACAddress(mac);
  W5100.setIPAddress(local_ip.raw_address());
  W5100.setGatewayIp(gateway.raw_address());
  W5100.setSubnetMask(subnet.raw_address());
  SPI.endTransaction();
  _dnsServerAddress = dns_server;
}

Try this.

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