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:
- Assign IP addresses to interfaces
- Define static routes
- Create VLAN subinterfaces
- Create OVS bridges
- 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:
|
|
To apply the above network configuration to your machine you can run:
|
|
On my machine, os-net-config created four configuration files in the /etc/sysconfig/network-scripts
directory:
|
|
|
|
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:
|
|
And here is the listing of the network configuration files generated by os-net-config based on the above input:
|
|
|
|
|
|
|
|
Activating the network configuration
When activating the network configuration, os-net-config executes several steps in the following order:
- Ifdown interfaces
- Ifdown bridges
- Generate/modify the configuration files in
/etc/sysconfig/network-scripts
directory - Ifup bridges
- 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.