Another day, another command line tutorial. Today, let’s talk about a vital networking command in Linux, ip. This command is handy to fish out network parameters of the Linux computer.
It works on all Linux distributions including Ubuntu, Arch Linux, Debian, Fedora, etc..
ip command
ip command is a highly powerful command that replaced the now-depreciated ifconfig command which was a part of the net-tools package. The general syntax of the command is as follows:
ip xx
Where xx must be replaced with one of the following to get the desired output.
-V to display ip utility version
-s to display more information about the command
Finding the IP address of the Linux System
Launch ‘Terminal’ and enter the following command to list all the IP address.
ip route list
It should display all available IP address including device names. If you are only interested in the default IP address that connects to the internet, use a grep parameter to list that one.
ip route list | grep default
Alternatively, you can also use device name in particular too, but you should know the names of network devices for that. Use ip addr show command:
ip addr show
Sample Output:
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: enp1s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000 link/ether xxxxxxxxxxxxxxxxxxxx 3: wlp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether yyyyyyyyyyyyyyyyyyyy inet 12121212121/24 brd 192.168.1.255 scope global dynamic wlp2s0 valid_lft 61791sec preferred_lft 61791sec inet6 AB:AD:AK:AI/64 scope global temporary dynamic valid_lft 548176sec preferred_lft 61403sec inet6 1:2:00:33:333/64 scope global mngtmpaddr noprefixroute dynamic valid_lft 548176sec preferred_lft 548176sec inet6 3:22:33:333/64 scope link valid_lft forever preferred_lft forever
Typically, eth0 is for Ethernet connection, and wlp2s0 for Wireless connection.
For example, use eth0 :
ip addr show eth0
Finding the MAC Address of the Linux System
MAC address is another critical parameter of a network device, including your PC’s hardware or a server. Every PC’s network device should have a unique MAC address.
Launch Terminal and enter the ip link command:
ip link show
Example Output:
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: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000 link/ether XXXXXXXXXXXX brd ff:ff:ff:ff:ff:ff 3: wlp2s0: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN mode DEFAULT group default qlen 1000 link/ether YYYYYYYYYYYY brd ff:ff:ff:ff:ff:ff
The ip utility should list several parameters of the device. For each device, two lines should summarize the link state and characteristics. The first line summarizes the current name of the device, the flags set on the device, the maximum transmission unit (MTU) and so on.
The second line should always indicate the type of link layer in use and the current hardware address (MAC Address). In the above example, XXXXXXXXXXXX and YYYYYYYYYYY are the MAC Address of the two LAN connections in use.
3 comments
Thanks! Very helpful
2020: ifconfig is removed. “ip addr show” doesn’t show the address, idiocracy is a real thing.
Hey it was useful