Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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("");
foreach (var iAddress in hostEntry.AddressList) {
    if (iAddress.AddressFamily == AddressFamily.InterNetwork) {
share|improve this question


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

From a command line:

dig | 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 -|sed -e 's/.*Current IP Address: //' -e 's/<.*$//'

simple. clear. and if you have curl :

curl -s|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

It returns      A

From that I just use awk:

host | awk '{ print $3; }'

and that returns just IP:

P.S. I know that 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


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.