User Tools

Site Tools


linux:bash:get-public-ip

Bash: get public IP

If you are behind a router you can't use ifconfig to find the public IP, but the problem can be solved easily beacause the IP can be obtained from remote servers such as

http://ifconfig.me/ip http://icanhazip.com http://ipecho.net/plain

You only have to choose that with quicker response time. You could even create your own webpage using PHP and

echo $_SERVER['REMOTE_ADDR']

This way you can avoid third party services.

At this point, in the linux shell or bash script you can use curl or a more common wget that's preinstalled on basically every distro of the planet. E.g.

wget -qO- icanhazip.com

or

curl icanhazip.com

This can be useful in many ways… e.g., to make a bash script for dynamic DNS update.

linux/bash/get-public-ip.txt · Last modified: 2020/06/04 20:52 by rik