How to find IP and MAC Address by command line in Linux

ip command lets you find the IP address and MAC address of a network connection.

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

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

Finding the IP address of the Linux System

Launch ‘Terminal’ and enter the 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 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.

Kiran Kumar
Hi there! I'm Kiran Kumar, founder of FOSSLinux.com. I'm an avid Linux lover and enjoy 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 a time, drop me an email or feedback from the 'Contact' page. Or simply leave a comment below if you found this article useful. Have a good day!

LEAVE A REPLY

Please enter your comment!
Please enter your name here

STAY CONNECTED

24,264FansLike
192FollowersFollow

LATEST ARTICLES

Ubuntu 19.10 beta overview
It may be early, but I've been looking forward to the release of Ubuntu 19.10 for some time now. As an impatient person, and promised readers in the FOSSLinux article announcing the release of Eoan Ermine that we would provide you a review of Ubuntu 19.10 Eoan Ermine - Beta.  So, here it goes.
PDF EDITORS LINUX
In this article, we will take a look at 10 of the best PDF editors and tools out there in 2019 that are available for Linux platforms. The editors are going to be judged on the basis of their functionalities, portability, ease of installation, price, and convenience.
Test drive linux online
Enter DistroTest.net, a website that allows Linux users to test various distros online, without downloading the ISO or installing the distro. With DistroTest.net, you can check a distro with no muss, no fuss.