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

23,647FansLike
360FollowersFollow
16SubscribersSubscribe

LATEST ARTICLES

How to install CMake on Ubuntu

CMake is a cross-platform free and open-source software tool designed to build, test, and package the software. CMake uses a simple platform and compiler-independent configuration files to control the software compilation process.

How to install Lightworks on Ubuntu

Even though Linux may not get a native installer of video editing software like Adobe Premiere or Final Cut Pro, that doesn't mean there are no industry standards tools available. Lightworks is non-linear editing (NLE) video mastering app for Windows, Linux, and macOS. Installing it on Ubuntu is simple due to deb package availability.

How to install DaVinci Resolve on Fedora

Davinci Resolve is a professional application used for color correction, video editing, visual effects, and motion graphics. It is one of the extensively used software by movie industries located in Hollywood.

The 10 Best Programming Languages for Hacking

One of the significant entities we have in Cyber Security is Ethical Hacking (ETH). It is the process of detecting and finding flaws or vulnerabilities in a system that a hacker would exploit.

5 Ways to Open a Terminal in Ubuntu

Even though Ubuntu supports many applications with amazing Graphical User Interfaces (GUI), there are always reasons why users prefer using the Terminal to perform different tasks.

How to install Wine on Fedora Workstation

Linux distributions are becoming more and more popular every day, and Fedora Workstation is not left behind. This popularity brings forth the need to run Windows applications on Linux distros like Fedora. Windows has quite some excellent Software that is not available for Linux.

MUST READ

Linux is growing faster than ever. As per the latest report, there is a drop in the Windows 10 market share for the first time, and Linux's market share has improved to 2.87% this month. Most of the features in the list were rolled out in the Pop OS 20.04. Let's a detailed look into the new features, how to upgrade, and a ride through video.
Elementary OS 5.1 Hera has received a point release with a handful of new features and bug fixes, and we will be reviewing the significant changes in this article. For those new to elementary OS, this Ubuntu-based Linux distribution uses their inhouse built Pantheon desktop environment and AppCenter.

5 Best ways to encrypt files in Linux

Privacy is something that almost all of us have concerns about. Many people switch over to Linux because of its better privacy features. In this time, where many people believe (quite rightly so) that privacy doesn't exist anymore, Linux provides a ray of hope. Distributions like Tails OS are specifically designed for that purpose.

5 Best Download Managers for Linux

We often need to download large files that can go corrupt due to various reasons such as slow internet or interrupted download. Using a broken downloaded file is not something one wants. Download managers make sure that the downloaded file maintains its integrity and also presents you with the ability to pause and resume downloads, provided the server supports it. When you are downloading a massive file, it's recommended to use a download manager.

Ubuntu 19.10 (Eoan Ermine) Beta Installation and 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.

6 Best Linux Distros for Laptops

Whether buying a Linux pre-installed laptop or selecting a Linux distro for your existing laptop, there are many things to consider. Let's take you through some of the best Linux distros that are optimized for Laptops in this 2019 edition of the article. Read on.