How to retrieve the IP address under Linux ?
For private ip address
reference: 3 Easy Ways to Find IP address in Linux
To show the interfaces of the system :
ip address show
lo is the loopback address. In general, it’s 127.0.0.1/8.
To filter a device :
ip address show dev eth1
The IPv4 address is listed in the line starting with inet.
Retrieve the IP address can be done like that :
ip address show dev eth1 | grep "inet "| awk '{ print $2 }'
For public ip address
There are plenty websites that show you your public IP address when you visit them. The simplest way would be to just ask google.
These sites get the job done but when you want to constantly monitor your public ip it becomes tedious to keep visiting them. You need to have a browser running and the website itself takes 3-4 seconds to load.
There are some handy api services like ifconfig.io API. If you visit ifconfig.io, you'll get a plain text http response. This method is slightly faster than asking google due to the smaller response size. It's also handy as you can use it in creating scripts.
curl ifconfig.io