---
title: "Proper way to change an IP address (W5500)"
url: "https://maker.wiznet.io/forum/16107"
markdown_url: "https://maker.wiznet.io/forum/16107/md"
type: "Forum topic"
category: "IO Modules"
author: "allenhuffman"
created: "2026-06-25T22:40:08+09:00"
last_activity: "2026-06-26T08:45:40+09:00"
language: "en"
views: 2
replies: 1
source: "WIZnet Makers forum (https://maker.wiznet.io/forum/)"
---

# Proper way to change an IP address (W5500)

## Question

Asked by allenhuffman on 2026-06-25 in IO Modules.

We are using a W5500 chip and the ioLibrary:

<https://github.com/wiznet/iolibrary_driver>

I am trying to figure out the steps needed to change the IP address on a working device, without requiring a reboot.

My code is based on the Wiznet examples, with wrappers made to pull network values from our configuration EEPROM and apply them:

```plaintext
wizchip_setnetinfo (&S_netinfo);
```

We then have code for the http and snmp servers that initialize things and open listener sockets.

```plaintext
httpServer_init ((uint8_t *)tx_buf, (uint8_t *)rx_buf, MAX_HTTPSOCK, http_socklist);

for (uint8_t idx = 0; idx < MAX_HTTPSOCK; idx++)
{
    HTTPS_PRINTF ("socket (%u, %u, %u, %u)\r\n",
                    idx, Sn_MR_TCP, port, 0);

    socket (idx, Sn_MR_TCP, port, 0);  // Listen on port 80
    
    listen (idx);
}
```

That seems to work fine, though I have posted elsewhere about how it stops responding after some days just sitting in the while (1) loop servicing these servers. That is a separate issue.

When an IP address is changed, we update our S_netinfo structure with the new values then call our network apply function which does the wizchip_setnetinfo(). That did not seem to be enough.

Multiple AIs suggested basically the same code, so I assume there is an example of this somewhere:

Instead of applying the network change first, each server is told it is stopping, then in its handler it will close() each open socket:

```plaintext
void SNMPServer_handler (void)
{
    if (true == S_snmpStopRequested)
    {
        (void)close (S_snmpSockNum);
        (void)close (S_snmpTrapSockNum);

        SNMP_PRINTF ("[SNMP] Listener sockets closed\r\n");
        S_snmpStopped = true;
        S_snmpStopRequested = false;
    }
    ...
    
void TCPServer_handler (void)
{
    uint8_t buffer[TCP_BUFFER_SIZE];
    uint8_t current_state = getSn_SR (S_TCPServerSocket);

    if (true == S_tcpStopRequested)
    {
        close (S_TCPServerSocket);
        TCPS_PRINTF ("[TCP] Listener socket closed\r\n");
        S_tcpStopped = true;
        S_tcpStopRequested = false;
    }
    ...
   
HTTP:
    if (true == S_httpStopRequested)
    {
        for (uint8_t idx = 0; idx < MAX_HTTPSOCK; idx++)
        {
            (void)close (http_socklist[idx]);
        }

        HTTPS_PRINTF ("[HTTP] All listener sockets closed\r\n");
        S_httpStopped = true;
        S_httpStopRequested = false;
    }
```

Once they are all stopped (all sockets closed, all flags set to "true"), THEN network settings are applied and each server's start routine is called again.

When I change the IP, the device is no longer PINGable at the existing address, but it is also not PINGable at the new address. Sometimes it starts working after some time, other times it will still not be responding the next morning (after a PC reboot so the ARP table is clear, etc.).

Clearly I (and by that, I mean the AI suggested code) am missing a step.

Is there an example that shows how to properly do this? Thanks, much.

## Replies

### Reply 1 by TheoIm, 2026-06-26

Hi,

Changing the IP address on the W5500 without rebooting may require more than simply calling `wizchip_setnetinfo()`. A recommended sequence is to properly close all active sockets, wait until each socket reaches the `SOCK_CLOSED` state, apply the new network configuration using `wizchip_setnetinfo()`, and then reinitialize your server sockets.

If you are reopening a socket, do not immediately call `socket()`. First, verify that the previous socket has actually transitioned to the `SOCK_CLOSED` state by checking `getSn_SR()`.

WIZnet provides reference projects based on the RP2040 and RP2350 MCUs. Although these examples target Raspberry Pi MCUs, the initialization sequence and application flow are generally applicable to other platforms as well. I recommend referring to these projects to see how the network initialization and server startup sequence are implemented.

**https://github.com/WIZnet-ioNIC/WIZnet-PICO-C/tree/main/examples**

Thanks

---

Source: https://maker.wiznet.io/forum/16107
