0

Is there a mechanism built-in to CentOS 7 to configure network interfaces with the classic network scripts, while allowing for wildcards in the device name?

Something along the lines of:

/etc/sysconfig/network-scripts/ifcfg-*

... would apply to every detected device.

The use case here is that I'm building a CentOS 7 image which will be used on various hardware. Some hardware has multiple NICs, others a single NIC. Therefore, when the image boots for the first time, any pre-configured scripts in /etc/sysconfig/network-scripts/ don't necessarily match the current device names.

The actual ifcfg script and network isn't exotic, it's a simple IPv4/DHCP network.

A couple things I'm trying to avoid (if possible):

  • NetworkManager.
  • Changing the default interface names from udev.

Pre-configuration is the main goal here. Thanks!

0

I don't think there's any wildcard method of doing it but potentially you could have a init script or systemd unit that runs before network initialization that looks in /sys/class//net (or does an ip link) and for each interface found could create (if missing) the necessary ifcfg- file.

Something like

#!/bin/bash

create_dev()
{
  dev=$1

  echo IPV6INIT=yes
  echo IPV6_AUTOCONF=yes
  echo BOOTPROTO=dhcp
  echo DEVICE=$dev
  echo ONBOOT=yes
}

for dev in *
do
  CFG=/etc/sysconfig/network-scripts/ifcfg-$dev

  if [ ! -e $CFG ]
  then
    create_dev $dev > $CFG
  fi
done

might be sufficient for the wrapper. You just then need to create the necessary unit or init script to ensure it runs early enough in the boot process.

0

While Stephen Harris' answer is a decent work around, it's purposely avoiding Network Manager which is the norm on traditional Linux distros now. While the traditional initscripts will still work for network devices at this present time, the support for them is being phased out in favor of Network Manager. This is why it's the default.

I highly recommend getting used to Network Manager, because the traditional initscripts will go away in the future (in almost all common distros). In a situation like this, you can easily use it to your advantage.

Network Manager will attempt to bring up new interfaces (by default, normally) with a default DHCP setup. They get listed under nmcli con show right away. Network Manager will generate the ifcfg-* files automatically for you. If you're using DHCP in your environment, this won't be an issue. If you're using static, you'll need to do a bit more work.

See man nmcli-examples.

  • Hi Sokel, thanks for your answer. Although I can't make the jump to NetworkManager for this project, I did test out some basic NM usage on these servers and NM was able to detect/configure IP properly when multiple NICs were present. The nmcli-examples page is handy. – Andy Aug 18 '16 at 20:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.