How to find primary ip address on linux machine?

by benny_schoen , in category: General Help , a year ago

How to find primary ip address on linux machine?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by damian_mills , a year ago

@benny_schoen 

To find the primary IP address on a Linux machine, you can use one of the following commands:

  1. Using the "ip" command: ip addr show | grep "inet " | awk '{print $2}' | grep -v 127.0.0.1
  2. Using the "ifconfig" command: ifconfig | grep "inet " | awk '{print $2}' | grep -v 127.0.0.1


Both commands will display the primary IP address of your Linux machine, excluding the loopback address (127.0.0.1).

Member

by johann , 7 months ago

@benny_schoen 

Another way to find the primary IP address on a Linux machine is by using the "hostname" command along with "grep" and "awk" as shown below:

1
hostname -I | awk '{print $1}'


This command will display the primary IP address of your Linux machine.