Last active
August 30, 2021 15:47
-
-
Save mjf/a6a719a48eb496c97ae7 to your computer and use it in GitHub Desktop.
Simple shell scripts to create sysconfig ifcfg files and udev rules files for PCI interfaces
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# Generate /etc/sysconfig/network-scripts/ifcfg-* | |
# Copyright (C) 2014 Matous J. Fialka, <http://mjf.cz/> | |
# Released under the terms of The MIT License | |
# | |
# Environment variables | |
# --------------------- | |
# | |
# IPADDR[<n>]=... | |
# IPv4 address in case BOOTPROTO[<n>]="none" (i.e. "10.0.0.1") | |
# | |
# PREFIX[<n>]=... | |
# IPv4 prefix length in bits (i.e. "24") | |
# | |
# GATEWAY[<n>]=... | |
# IPv4 default route for 0.0.0.0/0 (i.e. "10.0.0.254") | |
ifindx=0 | |
for ifdir in /sys/devices/pci*/*/net/* | |
do | |
ifindx=$(expr $ifindx + 1) | |
ifname=${ifdir##*/} | |
ifaddr=$(< $ifdir/address) | |
ifuuid=$(< /proc/sys/kernel/random/uuid) | |
cat <<- EOT | |
#<pre id="$ifindx" class="ifcfg"> | |
# cat '/etc/sysconfig/network-scripts/ifcfg-$ifname' <<- '#</pre>' | |
DEVICE=$ifname | |
NAME=$ifname | |
ONBOOT=yes | |
TYPE=Ethernet | |
HWADDR=$ifaddr | |
UUID=$ifuuid | |
BOOTPROTO=none | |
IPADDR=${IPADDR[$ifindx]} | |
PREFIX${PREFIX[$ifindx]} | |
GATEWAY=${GATEWAY[$ifindx]} | |
#DNS1= | |
#DNS2= | |
#</pre> | |
EOT | |
unset ifuuid | |
unset ifaddr | |
unset ifname | |
done | |
unset ifindx |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/sh | |
# Generate /etc/udev/rules.d/60-persistent-net-*.rules | |
# Copyright (C) 2014 Matous J. Fialka, <http://mjf.cz/> | |
# Released under the terms of The MIT License | |
ifindx=0 | |
for ifdir in /sys/devices/pci*/*/net/* | |
do | |
ifindx=$(expr $ifindx + 1) | |
ifname=${ifdir##*/} | |
ifaddr=$(< $ifdir/address) | |
ifuuid=$(< /proc/sys/kernel/random/uuid) | |
cat <<- EOT | |
#<pre id="$ifindx" class="udev-net-rules"> | |
# cat > /etc/udev/rules.d/70-persistent-net-${ifname}.rules <<- '#</pre>' | |
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="$ifaddr", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="$ifname" | |
#</pre> | |
EOT | |
unset ifuuid | |
unset ifaddr | |
unset ifname | |
done | |
unset ifindx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment