Configuring static IP address and virtual interfaces in Webmin

Configuring static IP address and virtual interfaces in Webmin

When assigning multiple IP addresses to a single server (by using virtual interfaces on the same single main interface) it is necessary to switch to a static IP configuration, otherwise the network interface may randomly end up with any of the allocated IPs at each lease renew (as the virtual interfaces don’t have distinct MAC addresses).

Doing network configuration remotely is a bit risky (and it is best to always have a backup plan – like local access or a remote hardware console) but by doing things in the correct order it is possible to switch from DHCP to static IP without any downtime.

Configuring Static IP

In the Webmin interface navigate to Networking » Network Configuration. Here note the two sub-sections: Network Interfaces and Routing and Gateways, as we’ll work with both of them.

Note: Don’t press any of the buttons indicating Apply until the last step as an incomplete configuration will get you locked out of any remote sessions.

Start under Network Interfaces and identify the correct network adapter (it can be named in may ways, including eth0, enp0s1, ig0 and so on, and your system may have more than one adapter). Most likely it is currently set to DHCP as in the image below. Click on the interface name to move to the next screen.

If your system already uses a static IP address then you can skip directly to the Virtual Interfaces section below.

Select Static Configuration and enter the correct IP address and netmask (and broadcast if desired). Note the Add virtual interface link, we’ll use it later on.

Click the Save button (NOT the Save and Apply button) and we’ll return to the main screen.

Now go to Routing and Gateways, select the previously configured interface name from the dropdown and enter the correct Gateway IP address in the appropriate field.

Click Save here as well and we’ll be back one again on the main screen.

You can double-check if all the entered numbers are correct and when that’s done click the Apply Configuration button. If all goes well the connection will be briefly interrupted and then will return to normal. You can use ifconfig to check the status of the network interfaces.

Once the settings have been applied and everything is working properly, we can move on. If the system’s connection goes dark scroll to the end of the article.

Adding Virtual Interfaces

We’ll work with the same two settings sections as above. Start under Network Interfaces and click on the same main interface name. This time use the Add virtual interface link (indicated by the green arrow in the image above).

We’ll be presented with a similar interface settings screen, however note that this now refers to the virtual :1 interface. Configure its desired IP address and Netmask.

If the IP addresses used on the virtual interfaces are from a different subnet than the main IP, you’ll need to define the correct gateway IP for that interface as well. That can be done from the Routing and Gateways screen:

All the configured interfaces should be properly listed on the interfaces list.

Click Apply Configuration on the previous screen one more time when you’re done adding all the virtual interfaces and then check their connectivity.

Failsafe

If anything’s goes wrong and the network goes down and becomes unavailable, log in locally (or through the recovery console) and edit the corresponding main network script (/etc/sysconfig/network-scripts/ifcfg-eth0in RedHat-like) to restore its DHCP functionality:

TYPE="Ethernet"
BOOTPROTO="dhcp"
DEFROUTE="yes"
PEERDNS="no"
PEERROUTES="yes"
IPV4_FAILURE_FATAL="no"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_PEERDNS="yes"
IPV6_PEERROUTES="yes"
IPV6_FAILURE_FATAL="no"
NAME="eth0"
UUID="123456789-0abc-def1-2345-67890abcdef1"
DEVICE="eth0"
ONBOOT="yes"

Replace with the correct network interface name and with the correct UUID value your system already uses.

Leave a Reply