Recently, I discussed a linux box that was missing a network script for one of its interfaces. Now I have a similar situation. Somehow, an interface eth1 was installed onto a CentOS box without an IP address. It shows up in ifconfig eth1 as this:
# ifconfig eth1
eth1: flags=4098<BROADCAST,MULTICAST> mtu 1500
ether 00:50:56:a9:cd:2e txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
I can fix this programmatically by iterating over the interfaces. I prefer to use ip -o for scripting purposes because the -o flag says to put everything on one line. Sadly, ip -o skips over any interface without an IP, even if I ask specifically for the non-addressed interface:
# ip -o addr show dev eth1
# ip addr show dev eth1
4: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 00:50:56:a9:cd:2e brd ff:ff:ff:ff:ff:ff
# ip -o addr show dev eth0
[snip reasonable output]
# echo $?
0
# ip -o addr show dev eth1
# echo $?
0
How would you best solve this? I can use a Perl module but I'd prefer using generic shell commands.