find IP address in linux

Опубликовано: 22 Октябрь 2024
на канале: Quite Simple
1,981
58

To find the IP address of a Linux system in a short line, you can use the following command:

ip addr show | grep 'inet ' | awk '{print $2}' | cut -f1 -d'/'

Here's what each part of the command does:

ip addr show : displays information about network interfaces on the system.
grep 'inet ' filters the output of the previous command to show only lines containing the string 'inet ', which indicates an IPv4 or IPv6 address.
awk '{print $2}' extracts the second field (the IP address) from the filtered output.
cut -f1 -d'/' removes the subnet mask from the IP address by using the '/' character as the delimiter and printing only the first field.