ip command strange behaviour

For discussions about programming, and for programming questions and advice


Moderator: Forum moderators

Post Reply
User avatar
BarryK
Posts: 2348
Joined: Tue Dec 24, 2019 1:04 pm
Has thanked: 101 times
Been thanked: 591 times

ip command strange behaviour

Post by BarryK »

The Network Wizard in many pups is very old code.
rerwin has worked on it; however, it is still very old.

It has a translation system that is not good, I have replaced with gettext. That seems to be working.

The code makes extensive use of 'ifconfig' and 'iwconfig', both deprecated.
In fact, 'wireless-tools', that has iwconfig, is no longer in the repository of some distributions.

ipconfig can be replaced by 'ip'. "ifconfig -a" can be replaced:

Code: Select all

# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    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: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
    link/ether a4:ae:11:16:23:58 brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN group default qlen 1000
    link/ether 00:0f:53:b0:17:2e brd ff:ff:ff:ff:ff:ff
    inet 192.168.43.115/24 brd 192.168.43.255 scope global dynamic noprefixroute wlan0
       valid_lft 1607sec preferred_lft 949sec
4: wlan1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
    link/ether 28:7f:cf:eb:43:66 brd ff:ff:ff:ff:ff:ff
    inet 192.168.43.204/24 brd 192.168.43.255 scope global dynamic noprefixroute wlan1
       valid_lft 2327sec preferred_lft 1877sec
    inet6 fe80::2a7f:cfff:feeb:4376/64 scope link 
       valid_lft forever preferred_lft forever

No problemo, I can parse that. However, the ip man page states the the "-o" or "-oneline" option will output on one line, to make parsing with grep easier:

Code: Select all

# ip -o a
1: lo    inet 127.0.0.1/8 scope host lo\       valid_lft forever preferred_lft forever
1: lo    inet6 ::1/128 scope host \       valid_lft forever preferred_lft forever
3: wlan0    inet 192.168.43.115/24 brd 192.168.43.255 scope global dynamic noprefixroute wlan0\       valid_lft 908sec preferred_lft 250sec
4: wlan1    inet 192.168.43.204/24 brd 192.168.43.255 scope global dynamic noprefixroute wlan1\       valid_lft 3428sec preferred_lft 2853sec
4: wlan1    inet6 fe80::2a7f:cfff:feeb:4376/64 scope link \       valid_lft forever preferred_lft forever

...huh??? that doesn't make any sense. What happened to eth0?

Do I have a buggy 'ip'?

Code: Select all

# ip -V
ip utility, iproute2-5.17.0
User avatar
BarryK
Posts: 2348
Joined: Tue Dec 24, 2019 1:04 pm
Has thanked: 101 times
Been thanked: 591 times

Re: ip command strange behaviour

Post by BarryK »

I stumbled upon a fix:

Code: Select all

# ip -f link -o a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000\    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000\    link/ether a4:ae:11:16:23:68 brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN group default qlen 1000\    link/ether 00:0f:53:b0:17:3e brd ff:ff:ff:ff:ff:ff
4: wlan1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000\    link/ether 28:7f:cf:eb:43:76 brd ff:ff:ff:ff:ff:ff
# 

...thought I don't understand why had to put in "-f link", when the "ip a" worked and all that "-o" is documented to do is organise output onto one line by replacing linefeeds with "\"
...well, the man page is wrong, or misleading anyway, "-o" does more than that.

Burunduk
Posts: 245
Joined: Thu Jun 16, 2022 6:16 pm
Has thanked: 6 times
Been thanked: 123 times

Re: ip command strange behaviour

Post by Burunduk »

This is probably because ifconfig -a is not an equivalent of ip a.

(The citations below are from the corresponding manpages.)

[ifconfig] -a
display all interfaces which are currently available, even if down

ip addr
Shows addresses assigned to all network interfaces.

The names of all objects may be written in full or abbreviated form, for example address can be abbreviated as [ip] addr or just [ip] a.

So the question is not why the record for an inactive interface is absent in the short form of the ip output (no address - no record), but why it is present in the full form.

Post Reply

Return to “Programming”