Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Is there some command line function within FreeNAS (FreeBSD) derivative which could return my external address? Since that same address is synchronized with DynDns (via router), in C# I retrieved that via DNS query like this:

var hostEntry = Dns.GetHostEntry("myexternalname.dyndns.org");
foreach (var iAddress in hostEntry.AddressList) {
    if (iAddress.AddressFamily == AddressFamily.InterNetwork) {
        MessageBox.Show(iAddress);
    }
}
share|improve this question

3 Answers 3

Prerequisites

  • dig
  • gnu grep
  • gnu tr
  • gnu awk
  • sort
  • uniq

From a command line:

dig yourserver.dyndns.org | grep "IN" | grep "[0-9]" | awk '{print $5}' | sort | uniq

The good:

  • Very simple pipe sequence returns at a minimum one IP address.
  • Can handle multiple IP addresses for the same name.

The bad:

  • pumps out text as a result, which means you'll probably need a redirect to a file
  • I can think of at least one edge case where this script might fail, although it's "good enough"

The ugly:

  • Script is far from optimal. I just banged it out in a few minutes.
  • Too many command line dependencies.
  • While the commands are fairly generic, the tool chain is GNU-specific.
  • Better off written in perl or python as a monolithic script.
share|improve this answer
    
That command (dig) does not exist on FreeNAS. :( –  Josip Medved Aug 27 '09 at 18:46

here is my favorite command :

wget -q -O - checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'

simple. clear. and if you have curl :

curl -s checkip.dyndns.org|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'
share|improve this answer
    
That command (wget) does not exist on FreeNAS. :( –  Josip Medved Aug 27 '09 at 18:45
up vote 2 down vote accepted

I found command that works on FreeNAS.

# host myexternalname.dyndns.org

It returns

myexternalname.dyndns.org      A       89.172.197.320

From that I just use awk:

host myexternalname.dyndns.org | awk '{ print $3; }'

and that returns just IP:

89.172.197.320

P.S. I know that 89.172.197.320 is not real IP address. I wrote it like that in order not to share mine IP address (or IP address from someone else).

P.P.S. Thanks for help to Kronick and Avery Payne since their ideas pushed me in right direction.

share|improve this answer
    
Gotta love those cut-down distros. At least FreeNAS is a bit more flexible than Smoothwall (another cut-down distro), as it's based on FreeBSD you can copy the software you need via SCP if you're desperate... –  Mark Henderson Aug 27 '09 at 21:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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