Show Local IP

2023-12-23 87 words 1 min read

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

author

Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it