Configure static IPv4 address in OpenShift 4.x CoreOS server

You can download this article in PDF format via the link below to support us.
Download the guide in PDF formatturn off

You have just finished setting up an OpenShift 4.x or OKD 4.x cluster and want to configure static IP addresses on the nodes? This is a common requirement for OpenShift UPI clusters deployed internally, for example, the cluster is installed in a VMware, RHEV or Baremetal server where the DHCP server is not very reliable.In this article, we will use nmcli Network management tool used to configure static IPv4 addresses on OpenShift 4.x servers (Infra, Masters and Worker computers).

Since the process used in this guide is manual, this means that you need to access the server to be configured with a static IP address via ssh. In our example, a DHCP server is used to assign an IPv4 address to the computer during the boot process. The following is an example of DHCP configuration for a working computer.

....
subnet 172.22.100.0 netmask 255.255.255.0 {
        pool {
            range 172.22.100.1 172.22.100.100;
    	    option routers 172.22.100.254;
            option subnet-mask 255.255.255.0;
            option broadcast-address 172.22.100.255;
            option domain-name-servers 172.22.100.254,8.8.8.8;
            option domain-name "ocp.example.net";

            # Worker Machines
            host worker1 {
                hardware ethernet 00:50:56:bf:c0:f7;
                fixed-address 172.22.100.10;
                option host-name "worker1.ocp.example.net";
            }
            host worker2 {
                hardware ethernet 00:50:56:bf:07:5a;
                fixed-address 172.22.100.11;
                option host-name "worker2.ocp.example.net";
            }
            host worker3 {
                hardware ethernet 00:50:56:bf:b2:a6;
                fixed-address 172.22.100.12;
                option host-name "worker3.ocp.example.net";
            }
....

I will log in to one of the worker nodes – Worker 1 , The IP address assigned by the DHCP server is 172.22.100.10.

$ ssh [email protected]
Red Hat Enterprise Linux CoreOS 44.81.202007010318-0
  Part of OpenShift 4.4, RHCOS is a Kubernetes native operating system
  managed by the Machine Config Operator (`clusteroperator/machine-config`).

WARNING: Direct SSH access to machines is not recommended; instead,
make configuration changes via `machineconfig` objects:
  https://docs.openshift.com/container-platform/4.4/architecture/architecture-rhcos.html

---
Last login: Sat Oct 31 19:55:16 2020 from 172.22.100.200
[[email protected] ~]$ 

You can also use the oc debug command to get Shell access to the node.

$ oc debug node/<nodename>

Use NMCLI to configure a static IP address in Red Hat CoreOS / Fedora CoreOS

After logging in to the terminal, use nmcli to check the network configuration.

$ nmcli connection show 
NAME                UUID                                  TYPE      DEVICE 
Wired connection 1  1dbbec73-04b1-3726-9d04-458f9ba17ff6  ethernet  ens192 

You can get more detailed information about the connection:

$ nmcli con show 'Wired connection 1'

To configure the IPv4 address, the gateway and DNS use nmcli to update the network connection settings.

sudo nmcli connection mod 'Wired connection 1' 
ipv4.method manual 
connection.autoconnect yes 
ipv4.addresses 172.22.100.10/24 
ipv4.gateway 172.22.100.254 
ipv4.dns 172.22.100.254 
+ipv4.dns 8.8.8.8

In my settings, the settings used are:

  • 172.22.100.10 Is the IPv4 address of the server.
  • 172.22.100.254 Is the IPv4 address of the gateway and DNS server.
  • 8.8.8.8 Is the IPv4 address of the secondary DNS server.
  • connection.autoconnect is‘Set up the connection to start at system startup.
  • ipv4.method manualSwitch the connection from DHCP to static IPv4 address.
  • Wired connection 1‘Is the name of the connection to be modified.

After execution, a static network configuration script will be created.

$ ls /etc/sysconfig/network-scripts/
ifcfg-Wired_connection_1

Restart to confirm whether the IP address request is sent to the DHCP server or assigned manually.

sudo systemctl reboot

Use NMCLI to set hostname on Red Hat CoreOS / Fedora CoreOS

You can also use the NMCLI command line tool to configure the static hostname of the CoreOS server.

sudo nmcli general hostname worker1.ocp.example.net

Confirm the settings.

$ hostnamectl 
   Static hostname: worker1.ocp.example.net
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 93ba80b38e9948acbb6aa6346bb5312c
           Boot ID: d885cc0011c04ac08c4d3e3ef3441ed0
    Virtualization: vmware
  Operating System: Red Hat Enterprise Linux CoreOS 44.81.202007010318-0 (Ootpa)
            Kernel: Linux 4.18.0-147.20.1.el8_1.x86_64
      Architecture: x86-64

You can also choose /etc/hostname file.

$ cat /etc/hostname 
worker1.ocp.example.net

Now you have set a static IPv4 address in the Red Hat CoreOS and Fedora CoreOS servers. While checking other available guides, keep in touch for more OpenShift guides.

How to list and approve pending CSRs in OpenShift 4.x

Send OpenShift logs and events to Splunk

Grant users access to projects/namespaces in OpenShift

You can download this article in PDF format via the link below to support us.
Download the guide in PDF formatturn off

Sidebar