Linux: How do you find out what your server’s outgoing ip is?

There are many times when I needed to find out my outgoing (or external) IP for the servers which are behind load balancers or firewalls.  I used to just login to another external server from the server in question and find out by looking at “who” what my external ip is.  Even though it works and I am so used to it, today I decided to figure out a more graceful way of finding my outgoing ip.  As most of us already know, is the quickest way to find out your outgoing ip from the browser.  So I decided to use the same way on the servers.  So I issued a wget:


Well that does the trick.  But being lazy as I am, I did not want to have to cat the output file to find out the ip (plus there is no point of creating extra files and doing extra work to remove them).  So if you are ssh’ed in, you can issue following command (I am sure there is another way of doing it, but this is the quickest way I could think of):

wget -q -O -

-O tells wget to redirect output to the following file (- being the standard out ).  So it basically echo’s output to our console.

-q makes wget run in  quiet mode so you do not see all of the connection/download/etc output.

That is it!  I am curious to know what other ways people use to get the same information.  Please share your way if possible.


DISCLAIMER: Please be smart and use code found on internet carefully. Make backups often. And yeah.. last but not least.. I am not responsible for any damage caused by this posting. Use at your own risk.

13 thoughts on “Linux: How do you find out what your server’s outgoing ip is?

  1. Sunny Walia Post author

    Because when you are behind firewall/load balancers, you tend to have private IPs. Most businesses with multiple servers will have it setup that way so they don’t have to buy/justify big blocks of IPs.

  2. Bob Jewell

    Though it’s basically the same thing, I have always used
    which defaults to having no extra verbosity while outputting to stdout.

  3. silvertip257

    I use the following code for my own external IP script (used with Torsmo/Conky).

    wget -q -O –
    # basically the automation page
    # that someone else mentioned in an earlier comment
    # saves bandwidth!

    For sometime, there was actually a complaint message posted on’s website … it linked to the automation page and requested that scripts have a reasonable hit frequency (NOT every two minutes or less … more like 30 minutes to an hour or more). I know for example my dynamic IP at home does not change for months and the DDNS script on my router does not try to update my IP on DynDNS all that often either.

    People need to think before they code (even pseudocode first) and test the code … and when networks are involved use tcpdump or Wireshark to verify how much network traffic you are creating!

  4. David Maas

    I used to use whatismyip, but the html gets annoying, so I created – it’s just a simple perl script:

    $ cat

    print “Content-type: text/plain; charset=iso-8859-1\n\n”;
    print “$ENV{‘REMOTE_ADDR’}”;
    print “\n\n”;

    It’s useful to have this script (or something similar) because then you can use the output in bash scripts without tons of sanitization/parsing

  5. pandora bracelet

    I wish to express my affection for your generosity giving support to men and women who really want help on your concept. Your personal commitment to passing the message along was really powerful and has really permitted women much like me to arrive at their endeavors. The insightful help means much to me and somewhat more to my colleagues. Best wishes; from each one of us.

  6. adidas ultra

    I would like to show some thanks to the writer for bailing me out of this type of difficulty. As a result of surfing around throughout the the net and coming across suggestions which are not powerful, I believed my life was over. Living without the solutions to the difficulties you have fixed as a result of your main post is a crucial case, as well as those which may have in a wrong way damaged my career if I had not come across your web page. Your main training and kindness in playing with almost everything was priceless. I am not sure what I would have done if I hadn’t discovered such a stuff like this. I can also at this moment look forward to my future. Thanks for your time very much for this impressive and results-oriented help. I will not be reluctant to endorse the website to any person who desires guide on this subject matter.

  7. kobe byrant shoes

    I’m also commenting to let you understand what a notable encounter my daughter obtained studying yuor web blog. She discovered some issues, which include how it is like to possess a wonderful giving mindset to let a number of people just learn several tortuous issues. You undoubtedly exceeded my desires. I appreciate you for coming up with those beneficial, dependable, informative and in addition unique thoughts on that topic to Jane.

Leave a Reply

Your email address will not be published. Required fields are marked *