Add a new network interface in Ubuntu

Introduction

It is advisable to know how to use sed , uuidgen , unset

In brief

cd /etc/sysconfig/network-scripts/
cp ifcfg-enp0s3 ifcfg-enp0s8
MYUID=$(uuidgen enp0s8)
sed -i s/UUID=*/UUID=$MYUID/ /etc/sysconfig/network-scripts/ifcfg-enp0s8
sed -i s/NAME=*/NAME=enp0s8/ /etc/sysconfig/network-scripts/ifcfg-enp0s8
sed -i s/DEVICE=*/DEVICE=enp0s8/ /etc/sysconfig/network-scripts/ifcfg-enp0s8
ifup enp0s8
unset MYUID

Explanation

Suppose you have an interface enp0s3 and you need to create a new interface enp0s8

Go to the directory /etc/sysconfig/network-scripts/ , which holds the interface settings.

cd /etc/sysconfig/network-scripts/

Copy the file of the existing interface to a file with the desired name

cp ifcfg-enp0s3 ifcfg-enp0s8

Generate a new UID for the interface using uuidgen

MYUID=$(uuidgen enp0s8)

Replace the old names and UID with the new ones using sed

sed -i s/UUID=*/UUID=$MYUID/ /etc/sysconfig/network-scripts/ifcfg-enp0s8
sed -i s/NAME=*/NAME=enp0s8/ /etc/sysconfig/network-scripts/ifcfg-enp0s8
sed -i s/DEVICE=*/DEVICE=enp0s8/ /etc/sysconfig/network-scripts/ifcfg-enp0s8

After that, it is advisable to clear the contents of the variable using unset

unset MYUID

Article author: Andrei Olegovich