Configure a static network
Disable DHCP to configure a static network.
- To disable the DHCP service, set theDhcpEnabledvariable value toFalseand set the IP address and mask properties.foreach(var networkInterface in systemNode.NetworkInterfaces) { if (networkInterface.InterfaceName == "LAN") { networkInterface.DhcpEnabled = false; networkInterface.IPAddress = "10.10.0.1"; networkInterface.IPAddressVariable.Mask = "255.255.0.0"; } }
- To create additional IP addresses for the network, create a variable for each additional IP address and add them to theAdditionalIPAddressescollection.TIP: Setting the values for theDNS1,DNS2, andDefaultGatewayservers would have no effect in this case. You can only set theDNS1,DNS2, andDefaultGatewayproperties for the network.foreach (var networkInterface in systemNode.NetworkInterfaces) { if (networkInterface.InterfaceName == "LAN") { var additionalIPAddressVariable = InformationModel.MakeVariable<MaskedIPAddress>("MyAdditionalIP", OpcUa::DataTypes.String); additionalIPAddressVariable.SetValue(ipAddress); additionalIPAddressVariable.Mask = mask; networkInterface.AdditionalIPAddresses.Add(additionalIPAddressVariable); } }
- Explicitly set theDNS1,DNS2, andDefaultGatewayservers. For these parameters it is allowed not to enter any value.foreach(var networkInterface in systemNode.NetworkInterfaces) { if (networkInterface.InterfaceName == "WAN") { networkInterface.DhcpEnabled = false; networkInterface.IPAddress = "10.10.0.1"; networkInterface.IPAddressVariable.Mask = "255.255.0.0"; networkInterface.DNS1 = "1.1.1.1"; networkInterface.DNS2 = ""; networkInterface.DefaultGateway = "192.168.1.1"; } }
Provide Feedback