Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Hide

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:

Hide

News

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

Commands tagged dns from sorted by
Terminal - Commands tagged dns - 27 results
dig +short which.opendns.com txt @208.67.220.220
2014-02-09 19:24:33
User: dinorox
Functions: dig
Tags: dig dns
16

It's somewhat common ISPs to intercept DNS queries at port 53 and resolve them at their own.

To check if your ISP is intercepting your DNS queries just type this command in the terminal.

"#.abc" it's an OK answer.

But if you get something like "I am not an OpenDNS resolver.", yep, you are beign cheated by your ISP.

for i in `ip addr show dev eth1 | grep inet | awk '{print $2}' | cut -d/ -f1`; do echo -n $i; echo -en '\t'; host $i | awk '{print $5}'; done
dig +short -x <ip-address>
dscacheutil ?flushcache
wki () { dig +short txt "${*// /_}".wp.dg.cx | sed -e 's/^"\(.*\)"$/\1/' -e 's/\([^\]\)"[^\]*"/\1/g' -e 's/\\\(.\)/\1/g' }
2012-05-30 11:36:25
User: kovirobi
Functions: sed
0

This removes the enclosing quotation marks ("), and sticthes the different packets together, e.g. '

dig +noall +answer exsample.com
kill -SIGHUP `cat /var/run/mydns.pid`
2011-10-21 14:29:24
User: ironmarc
Functions: kill
1

Occasionally, to force zone updating, cache flush is necessary. This command is better than restart the mydns daemon.

rndc flush
2011-10-21 14:27:05
User: ironmarc
Functions: rndc
2

Occasionally, to force zone updating, cache flush is necessary. Use this command is better than restart the Bind9 process.

domain=google.com; for ns in $(whois $domain | awk -F: '/Name Server/{print $2}'); do echo ">>> Nameservers for $domain from $a <<<"; dig @$ns $domain ns +short; echo; done;
2011-05-08 04:46:34
User: laebshade
Functions: awk dig echo whois
2

Change the $domain variable to whichever domain you wish to query.

Works with the majority of whois info; for some that won't, you may have to compromise:

domain=google.com; for a in $(whois $domain | grep "Domain servers in listed order:" --after 3 | grep -v "Domain servers in listed order:"); do echo ">>> Nameservers for $domain from $a

Note that this doesn't work as well as the first one; if they have more than 3 nameservers, it won't hit them all.

As the summary states, this can be useful for making sure the whois nameservers for a domain match the nameserver records (NS records) from the nameservers themselves.

mwiki () { dig +short txt `echo $*|sed 's| *|_|g'`.wp.dg.cx; }
dig +trace google.com
2010-09-03 18:57:29
User: duxklr
Functions: dig
Tags: dig dns
4

Simple command to trace a DNS query from the root all the way to the authoritative servers.

nslookup -q=txt <topic>.wp.dg.cx
dig +short NS org.
curl icanhazip.com
dig +short myip.opendns.com @resolver1.opendns.com
2010-04-02 21:53:26
User: dooblem
Functions: dig
26

Instead of opening your browser, googling "whatismyip"...

Also useful for scripts.

dig can be found in the dnsutils package.

mwiki() { dig +short txt "$*".wp.dg.cx; }
sed -i 's/20[0-1][0-9]\{7\}/'`date +%Y%m%d%I`'/g' *.db
2010-03-24 07:28:58
User: alf
Functions: sed
6

Will edit *.db files in the same directory with todays date. Useful for doing a mass update to domains on a nameserver, adding spf records, etc.

Looks for a string starting with 200 or 201 followed by 7 numbers, and replaces with todays date. This won't overwrite Ip's but i would still do some double checking after running this.

Make sure your server's date is correct, otherwise insert your own serial number.

rndc reload

should usually follow this command.

mwiki () { blah=`echo $@ | sed -e 's/ /_/g'`; dig +short txt $blah.wp.dg.cx; }
dig +short myip.opendns.com @resolver1.opendns.com
nslookup {ip}
dig +short -x {ip}
2009-12-21 14:43:35
User: putnamhill
Functions: dig
Tags: IP reverse dig dns
7

The +short option should make dig less chatty.

dig -x {IP}
host {checkIp or hostname} [dns server]
2009-12-21 11:48:00
User: mccalni
Functions: host
Tags: IP reverse dns
3

I'm just a simple programmer. I find dig too verbose. host tells me alias(es) and IP address in a quick to grok format with nothing special to remember for input parameters.

With thanks to http://www.cyberciti.biz/faq/how-to-test-or-check-reverse-dns/

check_dns_no() { for i in $* ; do if `wget -O - -q http://www.norid.no/domenenavnbaser/whois/?query=$i.no | grep "no match" &>/dev/null` ; then echo $i.no "available" ; fi ; sleep 1 ;done }
2009-09-30 21:17:33
User: xeor
Functions: echo grep sleep
Tags: wget dig dns
0

Mostly for Norwegians, but easily adoptable to others. Very handy if you are brainstorming for a new domainname.

Will only display the available ones..

You can usually do this better with dig, but if you dont have dig, or the TLD only have an online service to check with, this will be usefull..

nmap -R -sL 209.85.229.99/27 | awk '{if($3=="not")print"("$2") no PTR";else print$3" is "$2}' | grep '('
2009-09-02 16:33:15
User: netsaint
Functions: awk grep
Tags: nmap dns
4

This command uses nmap to perform reverse DNS lookups on a subnet. It produces a list of IP addresses with the corresponding PTR record for a given subnet. You can enter the subnet in CDIR notation (i.e. /24 for a Class C)). You could add "--dns-servers x.x.x.x" after the "-sL" if you need the lookups to be performed on a specific DNS server.

On some installations nmap needs sudo I believe. Also I hope awk is standard on most distros.