Today's article is fairly easy - show your network interface devices...

KGIII

Super Moderator
Staff member
Gold Supporter
Joined
Jul 23, 2020
Messages
11,789
Reaction score
10,354
Credits
97,524
Today, we use the terminal to show your network interfaces. We've touched on that in a variety of other articles, but this article is dedicated to just that - showing you a couple of ways to do so, one of which should work with most any current distro and one that's still in use but deprecated.


It won't take long to read and learn. So, enjoy and feedback is awesome.
 


KGIII wrote at linux.tips:
If you're using a distro with more current tools, you will likely find that ifconfig has been deprecated, that is no longer current and in use. For you folks, you'll need a slightly longer command:
ip link show

That ip command will certainly achieve the intended purpose of showing the network interfaces.

It was the "slightly longer" expression that caught my eye. There's a shorter ip command that provides more info, in particular the ip addresses, as follows:
Code:
[ben@fen ~]$ 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: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether xx:yy:ee:tt:uu:oo brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.6/24 brd 192.168.0.255 scope global dynamic enp2s0
       valid_lft 75063sec preferred_lft 75063sec
    inet6 2222:5555:4444:6666:7777:666:9999:4444/64 scope global dynamic mngtmpaddr
       valid_lft 4688sec preferred_lft 4688sec
    inet6 5555::1e1b:dff:fe65:3434/64 scope link
       valid_lft forever preferred_lft forever
3: enp4s0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 33:44:66:77:88:33 brd ff:ff:ff:ff:ff:ff

compared to:

Code:
[ben@fen ~]$ ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether xx:yy:ee:tt:uu:oo brd ff:ff:ff:ff:ff:ff
3: enp4s0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 33:44:66:77:88:33 brd ff:ff:ff:ff:ff:ff
 
That ip command will certainly achieve the intended purpose of showing the network interfaces.

It's the 'ifconfig' that's deprecated. The 'ip' command won't work on older versions of Linux, 'cause it hadn't been invented yet. If you really want ifcofig, you can probably still install 'net-tools'.

And, yeah, I suppose that is shorter. I am not sure why I use 'ip link show', but that's how it's stamped into my memory. When the switch was made, I probably latched onto it then. I dunno why, but it does work. So, it's all good. I might have latched onto it do make it different in my memory, instead of 'ifconfig -a'? I don't really know.

This being Linux, there's all sorts of ways to get this sort of information. (Which is pretty awesome.)
 
Just some chicken scratchin':

ifconfig | grep inet
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
inet 172.20.10.5 netmask 255.255.255.240 broadcast 172.20.10.15
inet6 fe80::8106:5324:c0eb:5afe prefixlen 64 scopeid 0x20<link>
inet6 2600:380:5e5d:afb4:4c4:e722:12d5:3324 prefixlen 64 scopeid 0x0<global>

If you only concerned with V4
ifconfig | grep -w inet
inet 127.0.0.1 netmask 255.0.0.0
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
inet 172.20.10.5 netmask 255.255.255.240 broadcast 172.20.10.15

If you just want the minimalist view:
ifconfig | grep -w inet | grep inet | awk '{print $1,$2}'
inet 127.0.0.1
inet 192.168.122.1
inet 172.20.10.5

Or...
ifconfig | grep -w inet | grep inet | awk '{print $1,$2,$4}'
inet 127.0.0.1 255.0.0.0
inet 192.168.122.1 255.255.255.0
inet 172.20.10.5 255.255.255.240

Then... the obvious V6
ifconfig | grep -w inet6
 
Just some chicken scratchin':

You might as well learn to do those with the 'ip' command. Well, then again, you might be able to keep 'net-tools' going for quite a while. The new and improved iproute2util is probably in your future.
 

Members online


Top