How to find my Internal and External IP Address from Linux command-line

Linux external ip in linux internal ip in linux 146 times1 answer1 follower
0
Mel Khamlichi 103 Rep. Avishek Kumar edited question

How to find Internal and External IP address on my Linux box in command-line?
What are the various tools to list both the address in Linux Console.

♥ Spread the love ♥
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
0
Avishek Kumar 449 Rep. Avishek Kumar edited answer

To get server external IP address aka public IP address,

Recommended way to query own public IP address

The preferred way to get own public IP address in Linux terminal includes the use of command-line utility ‘host’ and ‘dig’. Command host and dig are a simple and flexible DNS lookup utility.

  1. Use DNS request in place of HTTP request
  2. The dns server resolver1.opendns.com resolves myip.opendns.com to the IP address of the Linux Box.

    Sample Output

  3. Using Linux command-line utility dig with OPENDNS as resolver
  4. Sample Output

  5. Using Linux command-line utility dig with the Google server to query the public IP address
  6. Sample Output

    52.66.112.32

    Non-recommended way to Query public IP address

    Since the below method of getting the public IP address involves third-party server, which risk the user’s privacy and hence not recommended. Though it will also output the result, do it on your own risk.

    You have been Warned

  7. $ lynx -dump checkip.dyndns.org | cut -d: -f2
  8. Sample Output

  9. $ lynx -source ipinfo.io/ip
  10. Sample Output

  11. $. wget -q -O – checkip.dyndns.org|sed -e ‘s/.*Current IP Address: //’ -e ‘s/<.*$//'
  12. Sample Output

  13. $ curl -s checkip.dyndns.org|sed -e ‘s/.*Current IP Address: //’ -e ‘s/<.*$//'
  14. Sample Output

  15. $ wget -qO- http://ipecho.net/plain
  16. Sample Output

  17. $ curl http://ipecho.net/plain
  18. Sample Output

  19. $ wget -qO- ipinfo.io/ip
  20. Sample Output

  21. $ curl ipinfo.io/ip
  22. Sample Output

  23. $ curl bot.whatismyipaddress.com
  24. Sample Output

  25. $ curl ident.me
  26. Sample Output

  27. $ curl icanhazip.com
  28. Sample Output

  29. $ curl -s checkip.dyndns.org | sed ‘s/.*IP Address: \([0-9\.]*\).*/\1/g’
  30. Sample Output

  31. $ curl ip.appspot.com
  32. Sample Output

  33. $ curl myip.dnsomatic.com
  34. Sample Output

  35. $ curl whatismyip.akamai.com
  36. Sample Output

  37. $ curl icanhazip.com
  38. Sample Output

  39. $ curl ipecho.net/plain
  40. Sample Output

  41. $ curl ifconfig.co
  42. Sample Output

To get server internal IP address aka private IP address

  1. $ hostname -I
  2. Sample Output

  3. $ ip addr show | grep -i inet | grep -v inet6 | grep -v 127.0.0.1 | awk ‘{print $2}’ | cut -d/ -f1
  4. Sample Output

  5. # ifconfig | grep -i inet | grep -v inet6 | grep -v 127.0.0.1 | awk ‘{print $2}’

Add the below lines to your .bashrc and get internalip/externalip without the need of remembering long script.

  1. Open /home/$USER/.bashrc for editing as user and not root
  2. Add the below lines at the end. save and exit
  3. Source your .bashrc
  4. To get internal ip, all you need to run in terminal
  5. Sample Output

  6. To get external IP, you need to run
  7. Sample Output

    ♥ Spread the love ♥
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
×

Login