[lug] Udev Edits to Modify Ethernet Device Names

duboulder blug-mail at duboulder.com
Mon Jan 21 13:48:52 MST 2019


If you don't get a systemd specific way of doing it, adapting the open rc startup
script at the bottom for use with /etc/rc.local would be a way to rename specific interfaces.
IF_RENAME_LIST would be something like: eth2 eth3 eth1 eth2 eth0 eth1

‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Monday, January 21, 2019 11:28 AM, D. Stimits <stimits at comcast.net> wrote:

> I was asked a question which I know shouldn't be complicated, but it turns out perhaps it is. Many people have wanted to change the network device naming convention from the location specific modern naming (like "enp4s6") and put it back to the older "eth0" style naming. However, this question has a twist to it...the system is using systemd and udev, but is already using the "eth#" syntax...but the user wants to start numbering at "eth1" instead of "eth0" without naming a specific device.
>
> Is there a simple rule which can be written to increment all of the PCI based ethernet devices to start at "eth1" instead of "eth0"?

====================================================================================================
#!/sbin/openrc-run

depend() {
    before net
    after modules udev
}

rename_interfaces() {
    status=0
    while [ ! -z "$1" ]; do
        old_name="$1"; shift
        new_name="$1"; shift
        if [ -z "$new_name" ]; then
            eerror "  No new interface name given for $old_name"
            status=1
            continue
        fi

        old_exists=0
        new_exists=0
        if [ -d "/sys/class/net/$old_name/" ]; then
            old_exists=1
        fi
        if [ -d "/sys/class/net/$new_name/" ]; then
            new_exists=1
        fi

        if [[ $old_exists = 0 &&  $new_exists = 1 ]]; then
            # interface already renamed
            einfo "  $old_name already renamed to $new_name"
            continue
        fi

        if [ $old_exists = 0 ]; then
            eerror "  No interface with name $old_name found"
            status=1
            continue
        fi

        einfo "  Renaming $old_name to $new_name"
        msg=$(ip link set dev "$old_name" name "$new_name" 2>&1)
        if [ ! $? ]; then
            eerror "  Error renaming $old_name: $msg"
            status=1
        fi
    done

    eend $status
    return $status
}

start() {
    ebegin "Renaming network interfaces"
    rename_interfaces $IF_RENAME_LIST
    return $status
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20190121/c74da1a4/attachment.html>


More information about the LUG mailing list