How do you script the new network interface names?

General support questions
Locked
nbritton
Posts: 38
Joined: 2014/07/09 23:38:46

How do you script the new network interface names?

Post by nbritton » 2014/07/12 02:05:29

I wanted to do sed -i 's/ONBOOT=no/ONBOOT=yes/' /etc/sysconfig/network-scripts/ifcfg-eth0 but with the new network interface names they're basically randomly assigned now. For example, this is my config on my system:

[root@localhost network-scripts]# ll /etc/sysconfig/network-scripts/ifcfg-e*
-rw-r--r--. 1 root root 290 Jul 9 13:50 /etc/sysconfig/network-scripts/ifcfg-enp8s0f0
-rw-r--r--. 1 root root 290 Jul 9 13:50 /etc/sysconfig/network-scripts/ifcfg-enp8s0f1

What methods can you use to script with the new network interface names? Secondly, is there a paper that describes the new naming standard?

gerald_clark
Posts: 10642
Joined: 2005/08/05 15:19:54
Location: Northern Illinois, USA

Re: How do you script the new network interface names?

Post by gerald_clark » 2014/07/12 02:26:49

Use ifconfig -a or look at the filenames in /etc/sysconfig/network-scripts.

nbritton
Posts: 38
Joined: 2014/07/09 23:38:46

Re: How do you script the new network interface names?

Post by nbritton » 2014/07/12 02:54:46

Could you symbolically link the network interface to eth0, eth1, eth2, ...

[root@localhost network-scripts]# ll ifcfg-e*
-rw-r--r--. 1 root root 291 Jul 11 22:24 ifcfg-enp8s0f0
-rw-r--r--. 1 root root 290 Jul 9 13:50 ifcfg-enp8s0f1
lrwxrwxrwx. 1 root root 14 Jul 11 22:54 ifcfg-eth0 -> ifcfg-enp8s0f0
lrwxrwxrwx. 1 root root 14 Jul 11 22:54 ifcfg-eth1 -> ifcfg-enp8s0f1

Would the network startup scripts try to setup the device twice? Could you configure the actual device interface to alias to ethX?

gerald_clark
Posts: 10642
Joined: 2005/08/05 15:19:54
Location: Northern Illinois, USA

Re: How do you script the new network interface names?

Post by gerald_clark » 2014/07/12 03:48:30

Please read the FAQ and release notes.
http://wiki.centos.org/FAQ/CentOS7

slwelch33
Posts: 10
Joined: 2013/08/12 08:00:19

Re: How do you script the new network interface names?

Post by slwelch33 » 2014/07/13 10:05:05

The network interface names are not 'randomly' assigned now, they are assigned based on their hardware location and while the new naming convention introduces some difficulty in determining their names, get used to it, because the convention is here to stay, read the FAQ posted by gerald_clark for more details.

Here is a (relatively) simple way to get the name of the network interface, assuming that only one NW Interface card is installed and/or active:
The first line gets the NW name from ifconfig:
ethDev=`ifconfig | grep flags | grep -v LOOPBACK | awk -F':' '{print $1}'`
(note that 'flags' would return 2 lines, excluding the 'LOOPBACK' entry narrows it down to 1)
The next line builds a pointer to the appropriate file:
nwFile=`echo "/etc/sysconfig/network-scripts/ifcfg-${ethDev}"`
And finally, you can get or manipulate the IP address, or other information stored there:
ipAddr=`cat "${nwFile}" | grep "IPADDR" | grep -v grep | awk -F'=' '{print $2}'`

The best way to approach this is to issue the 'ifconfig' command and inspect the results, determine which line you need to extract, determine what field is "unique" to that line, which term or word you want to use to 'exclude' lines and which field and the delimiter to isolate the field you want.

sbungay
Posts: 5
Joined: 2011/02/05 13:44:02

Re: How do you script the new network interface names?

Post by sbungay » 2014/07/13 15:21:02

In servers we need stability and cautious progress, things like this and systemd are neither, CentOS 7 will not be deployed until we can easily control it, or we fork it. FreeBSD is looking better and better as I see the penguins being trapped on an a chunk of ice that is rapidly being surrounded by Orca. I do not like where LINUX is heading.

gerald_clark
Posts: 10642
Joined: 2005/08/05 15:19:54
Location: Northern Illinois, USA

Re: How do you script the new network interface names?

Post by gerald_clark » 2014/07/13 15:51:26

This is not new with CentOS 7. CentOS 6 does the same thing.
The link I gave you shows you how to turn this feature off.

scottro
Forum Moderator
Posts: 2414
Joined: 2007/09/03 21:18:09
Location: NYC
Contact:

Re: How do you script the new network interface names?

Post by scottro » 2014/07/13 16:41:12

I've heard similar sentiments on the mailing list. These days, I'm at a FreeBSD-centric place so we're not as worried about it as some.
Another change, by the way, is that ifconfig is being replaced by the ip command. I _think_ (not at a CentOS 7 install so can't test it) that the minimal CentOS-7 install doesn't include ifconfig, only ip.

I have a very superficial page on the ip command at http://srobb.net/ip.html
New users should check the FAQ and Read Me First pages

helpful
Posts: 1
Joined: 2015/08/28 11:46:14

Re: How do you script the new network interface names?

Post by helpful » 2015/08/28 12:55:36

You might try this to get a complete list of interfaces excluding the loopback interface 'lo'

[root@localhost system]# ip ntable | grep dev | sort | uniq | sed -e 's/^.*dev //;/^lo/d'
enp0s20u1u2c2
enp4s0
wlp5s0
[root@localhost system]#

I'm going to guess that you could select just one of these or you could collect info on them all
using a 'for do done' loop.
for interf in `ip ntable | grep dev | sort | uniq | sed -e 's/^.*dev //;/^lo/d'`
do
echo "interface $interf is configured"
....
done

wlp5s0 appears to be the WLAN interface - looking through the /var/log/messages file
localhost kernel: rtlwifi: wireless switch is on
localhost systemd-udevd[592]: renamed network interface wlan0 to wlp5s0
So UDEVD is renaming the interface - OK.
ditto I found this
localhost systemd-udevd[293]: renamed network interface eth0 to enp4s0
Later on The NetworkManager gets involved
localhost NetworkManager[997]: <info> (enp4s0): created default wired connection 'Wired connection 1'
based on the configuration files that NetworkManager uses.

localhost systemd-udevd[593]: renamed network interface eth0 to enp0s20u1u2c2
localhost NetworkManager[997]: <info> (enp0s20u1u2c2): link connected
localhost NetworkManager[997]: <info> (enp0s20u1u2c2): preparing device
localhost NetworkManager[997]: <info> read connection 'Wired connection 2'
localhost NetworkManager[997]: <info> (enp0s20u1u2c2): created default wired connection 'Wired connection 2'

My system is a MSI CX61 2QF
It has a built-in ethernet NIC: enp4s0
and a USB3 based ethernet NIC: enp0s20u1u2c2

When you run the following command
lspci -v | less
and search for 'net' you will notice the following
04:00.0 Ethernet controller: Qualcomm Atheros AR8161 Gigabit Ethernet (rev 10)
Subsystem: Micro-Star International Co., Ltd. [MSI] Device 10e9
Flags: bus master, fast devsel, latency 0, IRQ 50
Memory at f7900000 (64-bit, non-prefetchable)
I/O ports at d000
Capabilities: [40] Power Management version 3
Capabilities: [58] Express Endpoint, MSI 00
Capabilities: [c0] MSI: Enable+ Count=1/16 Maskable+ 64bit+
Capabilities: [d8] MSI-X: Enable- Count=16 Masked-
Capabilities: [100] Advanced Error Reporting
Capabilities: [180] Device Serial Number ff-7f-56-bb-d8-cb-8a-ff
Kernel driver in use: alx
The lspci -v provides
the PCI port number ... 4 and
the kernel device driver name ... 'alx'

Similarly ....
05:00.0 Network controller: Realtek Semiconductor Co., Ltd. RTL8723AE PCIe Wireless Network Adapter
Subsystem: AzureWave Device 2114
Flags: bus master, fast devsel, latency 0, IRQ 17
I/O ports at c000
Memory at f7800000 (64-bit, non-prefetchable)
Capabilities: [40] Power Management version 3
Capabilities: [50] MSI: Enable- Count=1/1 Maskable- 64bit+
Capabilities: [70] Express Endpoint, MSI 00
Capabilities: [100] Advanced Error Reporting
Capabilities: [140] Virtual Channel
Capabilities: [160] Device Serial Number 01-23-87-fe-ff-4c-e0-00
Kernel driver in use: rtl8723ae

The wireless device is a Realtek Semiconductor RTL8723AE driven by the 'rtl8723ae' kernel device driver.

When you run 'lsusb -v | less'

Bus 004 Device 003: ID 0bda:8153 Realtek Semiconductor Corp.
Device Descriptor:
bLength 18
bDescriptorType 1
bcdUSB 3.00
bDeviceClass 0 (Defined at Interface level)
bDeviceSubClass 0
bDeviceProtocol 0
bMaxPacketSize0 9
idVendor 0x0bda Realtek Semiconductor Corp.
idProduct 0x8153
bcdDevice 30.00
iManufacturer 1 Realtek
iProduct 2 USB 10/100/1000 LAN
iSerial 3 803F5D08FD57
bNumConfigurations 2
Configuration Descriptor:
bLength 9
bDescriptorType 2
wTotalLength 98
bNumInterfaces 2
bConfigurationValue 2
iConfiguration 0
bmAttributes 0xa0
(Bus Powered)
Remote Wakeup
MaxPower 36mA
Interface Descriptor:
bLength 9
bDescriptorType 4
bInterfaceNumber 0
bAlternateSetting 0
bNumEndpoints 1
bInterfaceClass 2 Communications
bInterfaceSubClass 6 Ethernet Networking
bInterfaceProtocol 0
iInterface 5 CDC Communications Control
CDC Header:
bcdCDC 1.10
CDC Union:
bMasterInterface 0
bSlaveInterface 1
CDC Ethernet:
iMacAddress 3 803F5D08FD57

The kernel device driver is not so easy to find ...
# lsmod | grep -i net
usbnet 43954 1 cdc_ether
mii 13934 1 usbnet
#

You need to check out the complete set of IP related information ... using ifconfig -a ... which is soon
to be dropped in favour of the the 'ip addr list' commands.

# ip addr list
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp4s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether d8:cb:8a:7f:56:bb brd ff:ff:ff:ff:ff:ff
3: enp0s20u1u2c2: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000
link/ether 80:3f:5d:08:fd:57 brd ff:ff:ff:ff:ff:ff
4: wlp5s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
link/ether dc:85:de:df:7e:b0 brd ff:ff:ff:ff:ff:ff
inet 10.1.1.4/24 brd 10.1.1.255 scope global dynamic wlp5s0
valid_lft 73831sec preferred_lft 73831sec
inet6 fe80::de85:deff:fedf:7eb0/64 scope link
valid_lft forever preferred_lft forever
#

Similarly 'netstat -r' should be translated to 'ip route list' or the equivalent 'ip route show'.
list and show are the same for this sort of command.

# ip route list
default via 10.1.1.1 dev wlp5s0 proto static metric 600
10.1.1.0/24 dev wlp5s0 proto kernel scope link src 10.1.1.4 metric 600
#

I hope this helps explain a few things.

Locked