Hacker News new | ask | show | jobs
by gnosek 2287 days ago

    ifconfig enp2s0:1 192.168.1.42
Now try

    ip addr add dev enp2s0 192.168.42.1/24
and observe how ifconfig ignores the second IP on the same interface. enp2s0:1 is an alias to enp2s0, not enp2s0 itself. To replicate your ifconfig command, you'd use

    ip addr add dev enp2s0 192.168.1.42/32 label enp2s0:1
and then it shows up in ifconfig as well.
2 comments

You're right, it's not exactly the same thing and both approaches (with an alias and without) have their uses. ifconfig forcing you to come up with a unique label can be annoying when you want some script to add a new address to an interface without having to go handle the error case of "but what if <iface>:1 is already used?".

Meanwhile having an explicit label can be nice in other situations if you want to replace an address instead of merely adding a new one.

I also seem to recall running into issues dealing with IPv6 with ifconfig that I worked around by switching to ip. I don't remember the specifics however.

Overall I wish ifconfig had been updated, I still find it a lot more user friendly that iproute. In particular the default output of a plain "ifconfig" is vastly more readable IMO: https://svkt.org/~simias/up/20200319-165513_ip.png

In general these days I use ip in scripts and ifconfig (when available) interactively. I don't love having to remember two ways of doing the same thing but I can't rely on ifconfig being available in scripts anymore and I just waste too much time parsing ip's bad output when I'm messing with networking interactively.

Understood, thanks, I'm so used to ifconfig that always tried to avoid using ip. Time to learn it I guess.
I spend a lot of times dealing with new devices. Plug it into the same VLAN as my desktop and then in a term:

# ip a a 192.168.1.32/24 dev eth0

Then put 192.168.1.1 into browser etc. Do job. Back to term. Up arrow to get last command, change the second a to d (for delete) and the extra address is gone.