IP and MAC Address

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

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:

ip xx

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

ip command usage in Ubuntu 17.10
ip command usage in Ubuntu 17.10

Finding IP address of Linux System

Launch ‘Terminal’ and enter following command to list all the IP address.

ip route list
ip route list command usage in Ubuntu 17.10
ip route list command usage in Ubuntu 17.10

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

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 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

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 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.

Previous articleHow to install GNOME Shell Extensions in Ubuntu 17.10
Next articleHow to move the window titlebar buttons to left in Ubuntu 17.10
Hi there! I'm Kiran Kumar, founder of FOSSLinux.com. I'm an avid Linux lover, and enjoys hands-on with new promising distros. Currently, I'm using Ubuntu as a daily driver and run several other distros such as Fedora, Solus, Manjaro, Debian, and some new ones on my test PC and virtual machines. I have a day job as an Engineer, and this website is one of my favorite past time activities especially during Winter ;). When I'm not writing for FOSSLinux, I'm seen biking and hiking on scenic trails. Hope you enjoy using this website as much as I do writing for it. Feedback from readers is something that inspires me to do more, and spread Linux love!. If you find time, drop me an email or feedback from 'Contact' page. Or simply leave a comment below if you found this article useful. Have a good day!

Leave a Reply

Be the First to Comment!

avatar
  Subscribe  
Notify of