User Tools

Site Tools


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

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


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-



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 18:52 by rik