Here is how you can change Netos 7.X IP address on the fly:
- get the DHCP configuration from NVRAM
iamStatus = customizeIamGetDhcpConfig("eth0", &myIamDhcpParams);
myIamDhcpParams.isEnabled = FALSE;
- write the DHCP configuration back to NVRAM
iamStatus = customizeIamSetDhcpConfig("eth0", &myIamDhcpParams);
- get the static configuration from NVRAM
iamStatus = customizeIamGetStaticConfig("eth0", &myIamStaticParams);
myIamStaticParams.isEnabled = TRUE;
- set up the IP address, subnet mask and gateway
myIamStaticParams.ipAddress.addr.ipv4.sin_addr.s_addr = 0xA34217C; // 10.52.33.124
myIamStaticParams.subnetMask = 0xfffff80; //255.255.248.0
myIamStaticParams.gateway.addr.ipv4.sin_addr.s_addr = 0xA342001; //10.52.32.1
- write the static configuration back to NVRAM
iamStatus = customizeIamSetStaticConfig("eth0", &myIamStaticParams);
- retrieve the address acquisition method last used
theIamStatus = naIamGetCurrentMethod("eth0", &myMethod);
theIamStatus = naIamDisable("eth0", myMethod);
theIamStatus = naIamEnable("eth0", NA_IAM_METHOD_STATIC);
- if you have a serial line connected to a terminal emulator, you will see the IAM messages announcing the loss of the DHCP address and the acquisition of the static address
- get the DHCP configuration from NVRAM
iamStatus = customizeIamGetDhcpConfig("eth0", &myIamDhcpParams);
myIamDhcpParams.isEnabled = TRUE;
- write the DHCP configuration to NVRAM
iamStatus = customizeIamSetDhcpConfig("eth0", &myIamDhcpParams);
- get the static configuration from NVRAM
iamStatus = customizeIamGetStaticConfig("eth0", &myIamStaticParams);
- zero out all static address fields
myIamStaticParams.ipAddress.addr.ipv4.sin_addr.s_addr = 0x00000000;
myIamStaticParams.subnetMask = 0x00000000;
myIamStaticParams.gateway.addr.ipv4.sin_addr.s_addr = 0x00000000;
myIamStaticParams.isEnabled = FALSE;
- write the static configuration back to NVRAM
iamStatus = customizeIamSetStaticConfig("eth0", &myIamStaticParams);
theIamStatus = naIamDisable("eth0", NA_IAM_METHOD_STATIC);
theIamStatus = naIamEnable("eth0", NA_IAM_METHOD_DHCP);
- If you have a serial line connected to a terminal emulator, you will see the IAM messages announcing the loss of the static address and the acquisition of the DHCP address.
Last updated:
Oct 14, 2024