Get Server IP Address with Ifconfig and IP in Bash

Posted on June 1, 2020 at 5:51 pm

Here is a one-line command to get server remote IP address:

Using “ifconfig” checking for “inet”:

/usr/sbin/ifconfig  | grep "inet " | cut -d: -f2 | awk '{ print $2}' | head -n 1

Using “ifconfig” checking for “Bcast”:

/usr/sbin/ifconfig | grep "Bcast:" | cut -d: -f2 | awk '{ print $1}'

Using “ip” checking for “inet”:

ip addr | grep "inet " | cut -d: -f2 | awk '{ print $2}' | tail -n 1 | sed 's/\/.*//'

Receive updates via email

Other Posts

Updated Posts