Another day, another command line tutorial. Today, let’s talk about an important networking command in Linux, ip. This command is very useful to fish out network parameters of the Linux computer. It works on all Linux distributions including Ubuntu, Arch Linux, Debian, Fedora, and etc..
ip command is highly powerful command that replaced the now-depreciated ifconfig command which was a part of net-tools package. The general syntax of the command is as follows:
Where xx must be replaced with one of following to get desired output.
-V to display ip utility version
-s to display more information about the command
Finding IP address of Linux System
Launch ‘Terminal’ and enter following command to list all the IP address.
ip route list
It will display all available IP address including device names. If you are only interested in the default IP address that connects to internet, use a grep parameter to just list that one.
ip route list | grep default
Alternatively, you can also use device name in particular too, but you should know what are the names of network devices for that. Use ip addr show command:
ip addr show
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 important parameter of a network device, including your PC’s hardware or a server. Every PC’s network device will have a unique MAC address.
Launch Terminal and enter the ip link command:
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: 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 will list several parameters of the device. For each device, two lines will summarize the link state and characteristics. First line summarizes the current name of the device, the flags set on the device, the maximum transmission unit (MTU), etc..
The second line will 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.