Shell Command for Getting IP Address?

Solution 1:

/sbin/ifconfig -a

Solution 2:

You can use:

/bin/ip addr

Solution 3:

If you have an internal address in use, checking

curl http://myip.dnsomatic.com

might be a good idea on unix shells.
Or, just plonk that URL into your browser.


If you get a different answer from the "ifconfig -a" result,
the ifconfig gave your internal address -- which will probably not work from outside.


Even if all seems fine, you could have a firewall in place that will disallow incoming ssh connections.
At which time you should try the port of interest from a browser on the machine at,

http://www.canyouseeme.org/

That will confirm connectivity through,

  • external IP address (showing it to you on that page)
  • NAT, Port Forwards
  • Firewalls

Solution 4:

/bin/hostname -i


Solution 5:

 curl icanhazip.com

tee hee!

From http://www.commandlinefu.com/commands/view/2966/return-external-ip