User Tools

Site Tools


Sidebar

Index

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 http://myip.dtdns.com/

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: 2014/11/24 10:39 by rik