dig [-h]
dig [global-queryopt...] [query...]
dig +
dig (domain information groper) is a flexible tool for interrogating DNS name servers. It performs DNS lookups and displays the answers that are returned from the name server(s) that - were queried. Most DNS administrators use dig to + were queried. Most DNS administrators use dig to troubleshoot DNS problems because of its flexibility, ease of use and clarity of output. Other lookup tools tend to have less functionality - than dig. + than dig.
- Although dig is normally used with
+ Although dig is normally used with
command-line
arguments, it also has a batch mode of operation for reading lookup
requests from a file. A brief summary of its command-line arguments
and options is printed when the -h option is given.
Unlike earlier versions, the BIND 9 implementation of
- dig allows multiple lookups to be issued
+ dig allows multiple lookups to be issued
from the
command line.
Unless it is told to query a specific name server,
- dig will try each of the servers listed in
+ dig will try each of the servers listed in
/etc/resolv.conf. If no usable server addreses
- are found, dig will send the query to the local
+ are found, dig will send the query to the local
host.
When no command line arguments or options are given, - dig will perform an NS query for "." (the root). + dig will perform an NS query for "." (the root).
- It is possible to set per-user defaults for dig via
+ It is possible to set per-user defaults for dig via
${HOME}/.digrc. This file is read and
any options in it
are applied before the command line arguments.
@@ -80,17 +80,17 @@
use "IN." and "CH." when looking up these top level domains.
- A typical invocation of dig looks like: + A typical invocation of dig looks like:
dig @server name type
where:
-server
@@ -98,19 +98,19 @@
can be an IPv4 address in dotted-decimal notation or an IPv6
address in colon-delimited notation. When the supplied
server argument is a hostname,
- dig resolves that name before querying
+ dig resolves that name before querying
that name server.
If no server argument is
- provided, dig consults
+ provided, dig consults
/etc/resolv.conf; if an
address is found there, it queries the name server at
that address. If either of the -4 or
-6 options are in use, then
only addresses for the corresponding transport
will be tried. If no usable addresses are found,
- dig will send the query to the
+ dig will send the query to the
local host. The reply from the name server that
responds is displayed.
type can be any valid query
type. If no
type argument is supplied,
- dig will perform a lookup for an
+ dig will perform a lookup for an
A record.
The -b option sets the source IP address of the query
to address. This must be a valid
@@ -150,14 +150,14 @@
class, such as HS for Hesiod records or CH for Chaosnet records.
- The -f option makes dig
+ The -f option makes dig
operate
in batch mode by reading a list of lookup requests to process from the
file filename. The file contains a
number of
queries, one per line. Each entry in the file should be organized in
the same way they would be presented as queries to
- dig using the command-line interface.
+ dig using the command-line interface.
The -m option enables memory usage debugging.
@@ -166,17 +166,17 @@
If a non-standard port number is to be queried, the
-p option is used. port# is
- the port number that dig will send its
+ the port number that dig will send its
queries
instead of the standard DNS port number 53. This option would be used
to test a name server that has been configured to listen for queries
on a non-standard port number.
- The -4 option forces dig
+ The -4 option forces dig
to only
use IPv4 query transport. The -6 option forces
- dig to only use IPv6 query transport.
+ dig to only use IPv6 query transport.
The -t option sets the query type to
@@ -203,7 +203,7 @@
address in dotted-decimal notation, or a colon-delimited IPv6 address.
When this option is used, there is no need to provide the
name, class and
- type arguments. dig
+ type arguments. dig
automatically performs a lookup for a name like
11.12.13.10.in-addr.arpa and sets the
query type and
@@ -214,7 +214,7 @@
are now experimental and are not attempted.
- To sign the DNS queries sent by dig and
+ To sign the DNS queries sent by dig and
their
responses using transaction signatures (TSIG), specify a TSIG key file
using the -k option. You can also specify the TSIG
@@ -230,16 +230,16 @@
multi-user systems as the key can be visible in the output from
ps(1)
or in the shell's history file. When
- using TSIG authentication with dig, the name
+ using TSIG authentication with dig, the name
server that is queried needs to know the key and algorithm that is
being used. In BIND, this is done by providing appropriate
- key and server statements in
+ key and server statements in
named.conf.
dig +
dig provides a number of query options which affect the way in which lookups are made and the results displayed. Some of these set or reset flag bits in the query header, some determine which @@ -257,7 +257,7 @@ The query options are:
-+[no]tcp
Use [do not use] TCP when querying name servers. The default
@@ -283,7 +283,7 @@
Set the search list to contain the single domain
somename, as if specified in
a
- domain directive in
+ domain directive in
/etc/resolv.conf, and enable
search list
processing as if the +search
@@ -345,14 +345,14 @@
Toggle the setting of the RD (recursion desired) bit
in the query. This bit is set by default, which means
- dig normally sends recursive
+ dig normally sends recursive
queries. Recursion is automatically disabled when
the +nssearch or
+trace query options are used.
+[no]nssearch- When this option is set, dig + When this option is set, dig attempts to find the authoritative name servers for the zone containing the name being @@ -366,13 +366,13 @@ Toggle tracing of the delegation path from the root name servers for the name being looked up. Tracing is disabled by default. When tracing is enabled, - dig makes iterative queries to + dig makes iterative queries to resolve the name being looked up. It will follow referrals from the root servers, showing the answer from each server that was used to resolve the lookup.
- +dnssec is also set when +trace is + +dnssec is also set when +trace is set to better emulate the default queries from a nameserver.
Toggles the printing of the initial comment in the output identifying - the version of dig and the query + the version of dig and the query options that have been applied. This comment is printed by default.
+[no]onesoa@@ -575,7 +575,7 @@ on its own line.
- If not specified, dig will look for
+ If not specified, dig will look for
/etc/trusted-key.key then
trusted-key.key in the current directory.
Include an EDNS name server ID request when sending a query.
+[no]keepopen
+ Keep the TCP socket open between queries and reuse it rather
+ than creating a new TCP socket for each lookup. The default
+ is +nokeepopen.
+
- The BIND 9 implementation of dig
+ The BIND 9 implementation of dig
supports
specifying multiple queries on the command line (in addition to
supporting the -f batch file option). Each of those
@@ -628,7 +634,7 @@
dig +qr www.isc.org any -x 127.0.0.1 isc.org ns +noqr
- shows how dig could be used from the
+ shows how dig could be used from the
command line
to make three lookups: an ANY query for www.isc.org, a
reverse lookup of 127.0.0.1 and a query for the NS records of
@@ -636,45 +642,45 @@ dig +qr www.isc.org any -x 127.0.0.1 isc.org ns +noqr
A global query option of +qr is
applied, so
- that dig shows the initial query it made
+ that dig shows the initial query it made
for each
lookup. The final query has a local query option of
- +noqr which means that dig
+ +noqr which means that dig
will not print the initial query when it looks up the NS records for
isc.org.
- If dig has been built with IDN (internationalized
+ If dig has been built with IDN (internationalized
domain name) support, it can accept and display non-ASCII domain names.
- dig appropriately converts character encoding of
+ dig appropriately converts character encoding of
domain name before sending a request to DNS server or displaying a
reply from the server.
If you'd like to turn off the IDN support for some reason, defines
the IDN_DISABLE environment variable.
The IDN support is disabled if the variable is set when
- dig runs.
+ dig runs.
There are probably too many query options.
diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index aa1f70e951..b6db463735 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -125,7 +125,8 @@ isc_boolean_t usesearch = ISC_FALSE, showsearch = ISC_FALSE, qr = ISC_FALSE, - is_dst_up = ISC_FALSE; + is_dst_up = ISC_FALSE, + keep_open = ISC_FALSE; in_port_t port = 53; unsigned int timeout = 0; unsigned int extrabytes; @@ -157,6 +158,9 @@ static void idn_check_result(idn_result_t r, const char *msg); int idnoptions = 0; #endif +isc_socket_t *keep = NULL; +isc_sockaddr_t keepaddr; + /*% * Exit Codes: * @@ -2530,6 +2534,15 @@ send_tcp_connect(dig_query_t *query) { } INSIST(query->sock == NULL); + + if (keep != NULL && isc_sockaddr_equal(&keepaddr, &query->sockaddr)) { + sockcount++; + isc_socket_attach(keep, &query->sock); + query->waiting_connect = ISC_FALSE; + launch_next_query(query, ISC_TRUE); + goto search; + } + result = isc_socket_create(socketmgr, isc_sockaddr_pf(&query->sockaddr), isc_sockettype_tcp, &query->sock); @@ -2552,6 +2565,7 @@ send_tcp_connect(dig_query_t *query) { result = isc_socket_connect(query->sock, &query->sockaddr, global_task, connect_done, query); check_result(result, "isc_socket_connect"); + search: /* * If we're at the endgame of a nameserver search, we need to * immediately bring up all the queries. Do it here. @@ -2937,6 +2951,12 @@ connect_done(isc_task_t *task, isc_event_t *event) { UNLOCK_LOOKUP; return; } + if (keep_open) { + if (keep != NULL) + isc_socket_detach(&keep); + isc_socket_attach(query->sock, &keep); + keepaddr = query->sockaddr; + } launch_next_query(query, ISC_TRUE); isc_event_free(&event); UNLOCK_LOOKUP; @@ -3753,6 +3773,8 @@ destroy_libs(void) { isc_result_t result; #endif + if (keep != NULL) + isc_socket_detach(&keep); debug("destroy_libs()"); if (global_task != NULL) { debug("freeing task"); diff --git a/bin/dig/include/dig/dig.h b/bin/dig/include/dig/dig.h index 7f8e90cdda..0046639146 100644 --- a/bin/dig/include/dig/dig.h +++ b/bin/dig/include/dig/dig.h @@ -276,6 +276,7 @@ extern isc_taskmgr_t *taskmgr; extern isc_task_t *global_task; extern isc_boolean_t free_now; extern isc_boolean_t debugging, debugtiming, memdebugging; +extern isc_boolean_t keep_open; extern char *progname; extern int tries; diff --git a/bin/tests/system/cacheclean/tests.sh b/bin/tests/system/cacheclean/tests.sh index 6eaee3d785..577c8e1810 100644 --- a/bin/tests/system/cacheclean/tests.sh +++ b/bin/tests/system/cacheclean/tests.sh @@ -85,11 +85,16 @@ in_cache () { } echo "I:check correctness of routine cache cleaning" -$DIG $DIGOPTS -f dig.batch > dig.out.ns2 || status=1 +$DIG $DIGOPTS +tcp +keepopen -b 10.53.0.7 -f dig.batch > dig.out.ns2 || status=1 grep ";" dig.out.ns2 $PERL ../digcomp.pl --lc dig.out.ns2 knowngood.dig.out || status=1 +echo "I:only one tcp socket was used" +tcpclients=`grep "client 10.53.0.7#[0-9]*:" ns2/named.run | awk '{print $4}' | sort | uniq -c | wc -l` + +test $tcpclients -eq 1 || { status=1; echo "I:failed"; } + echo "I:reset and check that records are correctly cached initially" ret=0 load_cache