Ales Nosek - The Software Practitioner

Helping you navigate the world of Kubernetes.

Sep 28, 2015 - Comments - devops cloud

Network Configuration with os-net-config

Os-net-config is a simple tool to configure networking of Linux hosts. Combined with Cloud-init, it’s suitable for network configuration of virtual machines when booting in the cloud. Let’s take a closer look at os-net-config.

Os-net-config is developed as a part of the OpenStack TripleO project. Its modus operandi is simple: based on the YAML/JSON configuration file, the os-net-config configures the network interfaces of the machine. Currently, the tool supports configuration of Debian based distributions using /etc/network/interfaces and configuration of distributions using scripts in /etc/sysconfig/network directory, e.g. Red Hat. Os-net-config allows the user to:

  1. Assign IP addresses to interfaces
  2. Define static routes
  3. Create VLAN subinterfaces
  4. Create OVS bridges
  5. Create OVS bonds (not implemented on Debian)

Using os-net-config on Red Hat

In the following examples we’ll use RHEL7 and os-net-config version 0.1.4. By default, os-net-config reads the configuration file at /etc/os-net-config/config.yaml. However, you can specify a different location using the -c parameter. The first example shows a configuration of machine with two network interfaces. The first interface is dynamically configured using DHCP. The second interface has been assigned an IP address and netmask statically:

example1.yaml
1
2
3
4
5
6
7
8
9
network_config:
  - type: interface
    name: nic1
    use_dhcp: true

  - type: interface
    name: nic2
    addresses:
      - ip_netmask: 192.168.1.1/24

To apply the above network configuration to your machine you can run:

1
$ os-net-config -c example1.yaml

On my machine, os-net-config created four configuration files in the /etc/sysconfig/network-scripts directory:

/etc/sysconfig/network-scripts/ifcfg-eth0
1
2
3
4
5
6
# This file is autogenerated by os-net-config
DEVICE=eth0
ONBOOT=yes
HOTPLUG=no
NM_CONTROLLED=no
BOOTPROTO=dhcp
/etc/sysconfig/network-scripts/ifcfg-eth1
1
2
3
4
5
6
7
8
# This file is autogenerated by os-net-config
DEVICE=eth1
ONBOOT=yes
HOTPLUG=no
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=192.168.1.1
NETMASK=255.255.255.0

In addition to the above interface configuration files, two empty files route-eth0 and route-eth1 have been created. These files would be populated in the case that I would define some static routes in my network configuration.

In the second example, we’ll bond two network interfaces and plug this bond into an OVS bridge. The os-net-config YAML configuration looks like this:

example2.yaml
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
network_config:
  - type: ovs_bridge
    name: bridge1
    use_dhcp: true
    members:
       - type: ovs_bond
         name: bond1
         members:
           - type: interface
             name: nic1
           - type: interface
             name: nic2

And here is the listing of the network configuration files generated by os-net-config based on the above input:

/etc/sysconfig/network-scripts/ifcfg-eth0
1
2
3
4
5
6
# This file is autogenerated by os-net-config
DEVICE=eth0
ONBOOT=yes
HOTPLUG=no
NM_CONTROLLED=no
BOOTPROTO=none
/etc/sysconfig/network-scripts/ifcfg-eth1
1
2
3
4
5
6
# This file is autogenerated by os-net-config
DEVICE=eth1
ONBOOT=yes
HOTPLUG=no
NM_CONTROLLED=no
BOOTPROTO=none
/etc/sysconfig/network-scripts/ifcfg-bond1
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# This file is autogenerated by os-net-config
DEVICE=bond1
ONBOOT=yes
HOTPLUG=no
NM_CONTROLLED=no
DEVICETYPE=ovs
TYPE=OVSPort
OVS_BRIDGE=bridge1
DEVICETYPE=ovs
TYPE=OVSBond
BOND_IFACES="eth0 eth1"
/etc/sysconfig/network-scripts/ifcfg-bridge1
1
2
3
4
5
6
7
8
9
# This file is autogenerated by os-net-config
DEVICE=bridge1
ONBOOT=yes
HOTPLUG=no
NM_CONTROLLED=no
DEVICETYPE=ovs
TYPE=OVSBridge
OVSBOOTPROTO=dhcp
OVSDHCPINTERFACES="bond1"

Activating the network configuration

When activating the network configuration, os-net-config executes several steps in the following order:

  1. Ifdown interfaces
  2. Ifdown bridges
  3. Generate/modify the configuration files in /etc/sysconfig/network-scripts directory
  4. Ifup bridges
  5. Ifup interfaces

Os-net-config executes the aforementioned steps only on interfaces/bridges whose configuration has been updated. If the interface/bridge configuration hasn’t changed os-net-config will not touch the respective configuration files in the /etc/sysconfig/network-scripts directory and will not restart the respective interface/bridge. This way, os-net-config minimizes the number of changes done to your system.

Network interface names

The names of the network interfaces are platform dependent. In the os-net-config configuration file, you can refer to your interfaces using symbolic names nic1, nic2, nic3, … Os-net-config will automatically associate these symbolic names with the real network interfaces like em, eth, eno.

Conclusion

Os-net-config is a useful configuration tool you might want to include on your virtual machine images.

Bridging VLAN Trunk to the Guest Installing Openstack Liberty on RHEL7

comments powered by Disqus