lost and found ( for me ? )

Showing posts with label TCP fallback. Show all posts
Showing posts with label TCP fallback. Show all posts

build dnstcpbench on ubuntu 12.04

about dnstcpbench

dnstcpbench can generate TCP fallback queries, which is developed by Netherlabs.

build dnstcpbench on Ubuntu12.04
# tail -1 /etc/lsb-release
DISTRIB_DESCRIPTION="Ubuntu 12.04.2 LTS"

# uname -ri
3.2.0-49-generic x86_64

before building dnstcpbench, install packages which are required to build dnsttcpbench.
# apt-get install autoconf automake bison flex g++ libboost-all-dev libtool make pkg-config ragel zlib1g-dev git

build dnstcpbench
# cd pdns/
# ./bootstrap
# ./configure --with-modules="" --without-lua
# cd pdns/   ( <- move to pdns/pdns directory )
# make dnstcpbench

# ./dnstcpbench --help
Allowed options:
 -h [ --help ]            produce help message
 -v [ --verbose ]         be verbose
 -u [ --udp-first ]       try UDP first
 -f [ --file ] arg        source file - if not specified, defaults to stdin
 --tcp-no-delay arg (=1)  use TCP_NODELAY socket option
 --timeout-msec arg (=10) wait for this amount of milliseconds for an answer
 --workers arg (=100)     number of parallel workers

TCP tuning on the dnstcpbench box.
# echo 1 > /proc/sys/net/ipv4/tcp_tw_recycle
# ulimit -n 102400

create a query list file
# cat query_list.txt
www2.foo.bar A
It seems that we need to define query types with capital letter.

run dnstcpbench
When specifying “--udp-first” option, dnstcpbench will send queries over UDP at first. And then if dnstcpbench receives responses are truncated, dnstcpbench will send queries over TCP.
# ./dnstcpbench --udp-first --file=query_list.txt 192.168.11.200 53
Average qps: 1, median qps: 0
Average UDP latency: 928usec, median: 0usec
Average TCP latency: 2540usec, median: 0usec
OK: 1, network errors: 0, other errors: 0
Timeouts: 0
Truncateds: 1, auth answers: 1

dnstcpbench : 192.168.11.100
BIND: 192.168.11.200

capture data which was collected on the dnstcpbench box.
# tshark -r aa.pcap
 1   0.000000 192.168.11.100 -> 192.168.11.200 DNS 72 Standard query A www2.foo.bar
 2   0.000358 192.168.11.200 -> 192.168.11.100 DNS 552 Standard query response A
 3   0.000943 192.168.11.100 -> 192.168.11.200 TCP 74 57192 > domain [SYN] Seq=0 Win=14480 Len=0 MSS=1460 SACK_PERM=1 TSval=327321 TSecr=318733 WS=8
 4   0.000978 192.168.11.200 -> 192.168.11.100 TCP 74 domain > 57192 [SYN, ACK] Seq=0 Ack=1 Win=14480 Len=0 MSS=1460 SACK_PERM=1 TSval=324122 TSecr=327321 WS=16
 5   0.001484 192.168.11.100 -> 192.168.11.200 TCP 66 57192 > domain [ACK] Seq=1 Ack=1 Win=14480 Len=0 TSval=327321 TSecr=324122

dnstcpbench supports multi threads
# ./dnstcpbench --udp-first --file=query_list.txt 192.168.11.200 53
Average qps: 943.396, median qps: 1008.31
Average UDP latency: 1190.06usec, median: 1106.41usec
Average TCP latency: 62321.8usec, median: 2659.29usec
OK: 48229, network errors: 0, other errors: 0
Timeouts: 1771
Truncateds: 50000, auth answers: 48229

# top -b -n 1 | grep dnstcp
4666 root      20   0 2821m  31m 1584 S  187  6.3   0:25.74 dnstcpbench

on the BIND box
# netstat -an | grep 53
tcp        0      0 192.168.11.200:53       0.0.0.0:*               LISTEN
tcp        0      0 192.168.11.200:53       192.168.11.100:59067    SYN_RECV
tcp        0      0 192.168.11.200:53       192.168.11.100:57997    SYN_RECV
tcp        0      0 192.168.11.200:53       192.168.11.100:58066    SYN_RECV
tcp        0      0 192.168.11.200:53       192.168.11.100:58067    SYN_RECV
tcp        0      0 192.168.11.200:53       192.168.11.100:58994    SYN_RECV
tcp        0      0 192.168.11.200:53       192.168.11.100:58009    SYN_RECV
tcp        1      0 192.168.11.200:53       192.168.11.100:59143    CLOSE_WAIT
tcp        1      0 192.168.11.200:53       192.168.11.100:59145    CLOSE_WAIT
tcp        0      0 192.168.11.200:53       192.168.11.100:58064    ESTABLISHED
tcp        0      0 192.168.11.200:53       192.168.11.100:58008    ESTABLISHED
tcp        1      0 192.168.11.200:53       192.168.11.100:59141    CLOSE_WAIT
tcp        0      0 192.168.11.200:53       192.168.11.100:58068    ESTABLISHED
tcp        0      0 192.168.11.200:53       192.168.11.100:59023    ESTABLISHED
tcp        0      0 192.168.11.200:53       192.168.11.100:58059    ESTABLISHED
tcp       32      0 192.168.11.200:53       192.168.11.100:59147    ESTABLISHED

awesome tool!

send TCP fall back DNS queries with dnspython

Here’s how to send TCP fallback DNS queries with dnspython.
dnspython supports TCP fallback since version 1.10.

many thanks.

Looking into the code also helps me understand dns.resolver.Resolver.

install dnspython on ubuntu 13.04
# tail -1 /etc/lsb-release
DISTRIB_DESCRIPTION="Ubuntu 13.04"

# uname -ri
3.8.0-25-generic x86_64

# apt-get install python-dnspython –y

[ enable EDN0 ]

# cat enable_edns0.py -n
# cat -n enable_edns0.py
    1  #!/usr/bin/env python
    2
    3  import dns.resolver
    4
    5  myresolver = dns.resolver.Resolver(configure=False)
    6  myresolver.use_edns(0,0,4096)
    7  myresolver.nameservers = ['192.168.10.200']
    8  result = myresolver.query('www.foo.bar','a',source="192.168.10.100")
    9  for i in result:
   10          print i

use_edns(0,0,4096)

enable edns0 = 0 , disable edns0 =  -1 ,
edns version
payload size

capture data when dnspython sending a query to the DNS server.
   Queries
       www.foo.bar: type A, class IN
           Name: www.foo.bar
           Type: A (Host address)
           Class: IN (0x0001)
   Additional records
       <Root>: type OPT
           Name: <Root>
           Type: OPT (EDNS0 option)
           UDP payload size: 4096
           Higher bits in extended RCODE: 0x0
           EDNS0 version: 0
           Z: 0x0
           Data length: 0

[ disable EDNS0 ]

# cat disable_edns0.py -n
    1  #!/usr/bin/env python
    2
    3  import dns.resolver
    4
    5  myresolver = dns.resolver.Resolver(configure=False)
    6  myresolver.use_edns(-1,0,4096)
    7  myresolver.nameservers = ['192.168.10.200']
    8  result = myresolver.query('www.foo.bar','a',tcp=False,source="192.168.10.100",source_port=50000)
    9  for i in result:
   10          print i

or you can disable edns0 by just removing the line “use_edns ..” .

cap data (  dnspython to DNS server )
   Queries
       www.foo.bar: type A, class IN
           Name: www.foo.bar
           Type: A (Host address)
           Class: IN (0x0001)

[ send only TCP queries without sending UDP queries ]

# cat -n send_TCP_queries.py
    1  #!/usr/bin/env python
    2
    3  import dns.resolver
    4
    5  myresolver = dns.resolver.Resolver(configure=False)
    6  myresolver.use_edns(0,0,4096)
    7  myresolver.nameservers = ['192.168.10.200']
    8  result = myresolver.query('www.foo.bar','a',tcp=True,source="192.168.10.100")
    9  for i in result:
   10          print i

nice tool!