Linux Interface Information

From a networking perspective, some of the most basic information to know about a Linux box is the status of its network interface. In this blog post, I will describe how to get that information.

The command that gives you that information is called “ip,” which, according to its manual, shows and manipulates routing, devices, policy routing and tunnels. So, apart from giving interface information, it is also highly capable with routing and interface manipulation. In this post, we’ll focus on how to get the interface information; in a future blog post, we’ll focus on the manipulation part.

List All Interfaces

Let’s start with the first command: “ip address.” If you want to save some keystrokes you can type the abbreviated “ip addr,” and if you want to save some more just type “ip a.”

netbeez.net$ ip address
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,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether b8:27:eb:57:91:1c brd ff:ff:ff:ff:ff:ff
    inet 172.31.0.246/24 brd 172.31.0.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::ba27:ebff:fe57:911c/64 scope link
       valid_lft forever preferred_lft forever
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether b8:27:eb:02:c4:49 brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.28/24 brd 192.168.0.255 scope global wlan0
       valid_lft forever preferred_lft forever
    inet6 2600:1700:65a0:8fa0:ba27:ebff:fe02:c449/64 scope global mngtmpaddr dynamic
       valid_lft 3571sec preferred_lft 3571sec
    inet6 fe80::ba27:ebff:fe02:c449/64 scope link
       valid_lft forever preferred_lft forever

As you can see above, there are three interfaces on this host, the loopback “lo,” the ethernet “eth0,” and the WiFi “wlan0.”

Interface Information Breakdown

The previous output may look a bit wordy and difficult to read, but you can break it down by asking ip to only print the information of a specific interface as follows:

netbeez.net$ ip link show dev eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether b8:27:eb:57:91:1c brd ff:ff:ff:ff:ff:ff
    inet 172.31.0.246/24 brd 172.31.0.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::ba27:ebff:fe57:911c/64 scope link
       valid_lft forever preferred_lft forever

To break this down a bit, ip gives the following information:

eth0: name of the interface
BROADCAST: it’s a broadcast interface which means it has a valid broadcast address
MULTICAST: it supports multicast
UP: the interface has been enabled and running (drivers loaded and working)
LOWER_UP: there is signal activity at the physical layer (a cable is plugged in)
mtu 1500: the maximum  transfer unit is 1500
qdisc pfifo_fast: used for packet queueing
state UP: network interface is up
group default: interface group
qlen 1000: transmission queue length

inet 172.31.0.246/24: IPv4 address
brd 172.31.0.255: broadcast address
scope global eth0: valid everywhere
valid_lft forever: valid lifetime for IPv4 address
preferred_lft forever: preferred lifetime for IPv4 address
inet6 fe80::ba27:ebff:fe57:911c/64: IPv6 address
scope link: valid only on this device
valid_lft forever: valid lifetime for IPv6 address
preferred_lft forever: preferred lifetime for IPv6 address

Linux Interface Statistics

To get statistics on a specific interface, use the following commands. The output is self explanatory:

netbeez.net$ ip -s link show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether b8:27:eb:57:91:1c brd ff:ff:ff:ff:ff:ff
    RX: bytes  packets  errors  dropped overrun mcast
    164223     2018     0       0       0       0
    TX: bytes  packets  errors  dropped carrier collsns
    306234     1700     0       0       0       0

Routing Information

To get the routing information, use the following command:

netbeez.net$ ip route show
default via 172.31.0.1 dev eth0
172.31.0.0/24 dev eth0 proto kernel scope link src 172.31.0.246
192.168.0.0/24 dev wlan0 proto kernel scope link src 192.168.0.28

We can see that the default route goes through interface eth0 and there two more routes on the eth0 and wlan0 interfaces.

Manual Pages for Linux Interface Information

As per usual, you can look up all the command options on its manual page (“man ip”), but to make your lives easier, you can use the help option to get information on specific commands. For example, if you want to learn about the different options around the “address” set of commands you can type the following:

netbeez.net$ ip address help
Usage: ip address {add|change|replace} IFADDR dev IFNAME [ LIFETIME ]
                                                      [ CONFFLAG-LIST ]
       ip address del IFADDR dev IFNAME [mngtmpaddr]
       ip address {save|flush} [ dev IFNAME ] [ scope SCOPE-ID ]
                            [ to PREFIX ] [ FLAG-LIST ] [ label LABEL ] [up]
       ip address [ show [ dev IFNAME ] [ scope SCOPE-ID ] [ master DEVICE ]
                         [ type TYPE ] [ to PREFIX ] [ FLAG-LIST ]
                         [ label LABEL ] [up] [ vrf NAME ] ]
       ip address {showdump|restore}
IFADDR := PREFIX | ADDR peer PREFIX
          [ broadcast ADDR ] [ anycast ADDR ]
          [ label IFNAME ] [ scope SCOPE-ID ]
SCOPE-ID := [ host | link | global | NUMBER ]
FLAG-LIST := [ FLAG-LIST ] FLAG
FLAG  := [ permanent | dynamic | secondary | primary |
           [-]tentative | [-]deprecated | [-]dadfailed | temporary |
           CONFFLAG-LIST ]
CONFFLAG-LIST := [ CONFFLAG-LIST ] CONFFLAG
CONFFLAG  := [ home | nodad | mngtmpaddr | noprefixroute | autojoin ]
LIFETIME := [ valid_lft LFT ] [ preferred_lft LFT ]
LFT := forever | SECONDS
TYPE := { vlan | veth | vcan | dummy | ifb | macvlan | macvtap |
          bridge | bond | ipoib | ip6tnl | ipip | sit | vxlan | lowpan |
          gre | gretap | ip6gre | ip6gretap | vti | nlmon | can |
          bond_slave | ipvlan | geneve | bridge_slave | vrf | hsr | macsec }

If you already have some experience with Linux, you might know about the ifconfig command, which can give similar information. I still use ifconfig, but the problem is that it’s getting deprecated from several Linux distributions. If you are a new user, I’d suggest to use only the “ip” command. If you are already familiar with ifconfig, it’s okay to keep using it, but keep in mind that its end-of-life is coming soon.

decoration image

Get your free trial now

Monitor your network from the user perspective

You can share

Twitter Linkedin Facebook

Let's keep in touch

decoration image