Show Local IP

2023-12-23 1 min read Linux Networking

Show local IP

You can see the local IP of the machine with the command - ip a. However if you have to use the address in some variable in a scrit. It becomes little tricky, something like

  • Show the interfaces in one line with ‘-o’
  • Show only IPv4 address’s with ‘-4’

and the command looks like

1
ip -4 -o a show dev eth0|awk '{gsub(/\/.*/,"",$4);print $4}'

Replace eth0 with then correct interface name.

However there is one more command that you can try

1
hostname -I
comments powered by Disqus