I have set a static local ip on a raspberry pi and I can reach it on my lan by ssh [email protected].

I am also sure that the rpi has access to the internet because I am able to run wget command without error.

Now, I would like to make a script to email my public ip when it changes, but when running ifconfig command or ip address I can't find it. Only when doing things like curl ifconfig.me I am able to retrieve it. Do you have any idea why ?


  • What IP do you see with ifconfig or ip addr?
    – goldilocks
    Nov 28, 2013 at 12:39
  • @goldilocks I can see only my local ips nto external ones
    – dry
    Nov 28, 2013 at 13:12
  • Okay, that wasn't clear to me for some reason before.
    – goldilocks
    Nov 28, 2013 at 13:29

3 Answers 3


The reason you can't just get it from the pi is that the machine doesn't know what it is. It received the local IP from your router's DHCP service, and that's its IP on the network; internet requests are funneled through the router. The external IP is assigned to the router by your ISP and the pi never knows about or sees it. Requests from the pi have the IP address translated by the router, as do the replies -- these can also be sorted inside your LAN by MAC address.

A method to get it, though evidently you know this one already:

curl -s icanhazip.com

There are others sites like that one, but it seems to work best here. If curl isn't installed, apt-get install curl will do it.


You can just wget one of the many web sites that gives your public ip. Like this one:

wget -qO - http://what-is-my-ip.net/?text


As mentioned, use the following to get your ip. You can create a script to email you your most recent ip

wget -q0 - http://what-is-my-ip.net/?text

Dynamic DNS

Look into Dynamic DNS providers and scripts provided by them to update your ip address. Then you'll be able to access your machine through a domain name (ie: sub.domain.tld), which will be much easier to configure in your ~/.ssh/config.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.