tcpdump(1) DNS
Description
Objective
The objective of this assignment is for you to learn how to use tcpdump to observe and analyze network traffic. This reinforces lessons from our lecture on networking and prepares you for our lecture on the DNS.
In order to be able to observe DNS traffic flowing between your host and the DNS root servers as well as other DNS servers, you will need to set up and configure a simple caching name server, aka a resolver.
Note: you must use tcpdump. Graphical helper applications such as “wireshark” or similar tools are explicitly prohibited. You need to be able to read the flat text tcpdump output yourself and not rely on other tools to highlight things for you.
OS Instances
The exercises below can be done on any OS instance you like. You will need at least two OS instances, one for the DNS server and one for the “client”. Make sure that the firewall rules between the server and client allow for all the required traffic.
DNS server setup
Set up a caching only DNS server (a ``resolver’’) on your OS instance. You may consult any online documentation available, such as this document or any others you prefer. You may use bind or any other DNS server software you like. The only restriction is that in the end your host must be able to function as a caching DNS server.
Set up your client host to use your newly created DNS server for host lookups.
tcpdump exercises
Use the tcpdump utility to monitor the network traffic using the following scenarios:
on the DNS server, run the following commands:
$ telnet www.yahoo.com 80
GET / HTTP/1.1
Host: www.yahoo.com
Track down the packets in your tcpdump referring to the DNS query from your DNS server to one of the root servers, then to the various DNS servers before the DNS information is returned to your server by one of Yahoo’s authoritative DNS servers.
Identify the 3-way handshake that initiates the connection from your DNS server to port 80 on Yahoo’s webserver, the packets that are being sent back and forth and finally the closing of the connection.
on your client host, run the following commands:
$ telnet www.tumblr.com 80
GET / HTTP/1.0
On your client: Track down the packets in your tcpdump referring to the DNS query from your client host to your DNS server.
On your DNS server: Track down the packets in your tcpdump referring to the DNS query from your DNS server to one of the root servers, then to the various DNS servers before the DNS information is returned to your server by one of Tumblr’s authoritative DNS servers.
on the DNS server, perform a reverse host lookup (PTR) for a record not yet in your DNS server’s cache; track down in your tcpdump all relevant DNS queries required to retrieve the result. Clearly identify which name servers you are communicating with and who operates them.
Content
Set up a caching name server
I read some tutorials and decide to set uo my name server in Red Hats OS.
tutorals:
http://www.tecmint.com/install-configure-cache-only-dns-server-in-rhel-centos-7/
http://www.tldp.org/HOWTO/DNS-HOWTO-3.html
Create a instance of Red Hat.
1 | ➜ ~ git:(master) ✗ aws ec2 run-instances --image-id ami-b63769a1 --count 1 --instance-type t2.micro --key-name keypair3 --security-groups mysg |
Install package bind
, bind-utils
and caching-nameserver
.
Public DNS: ec2-54-91-19-43.compute-1.amazonaws.com
1 | ➜ Documents git:(master) ✗ ssh -i p.pem ec2-user@ec2-54-91-19-43.compute-1.amazonaws.com |
Modify the file ‘/etc/named.conf’
Then I look the file /etc/named.conf
:
This file has limit of permission. I use root as user.
1 | [ec2-user@ip-172-31-30-115 var]$ sudo su |
Modify:
1 | // |
Look the file ‘named.ca’:
1 | [root@ip-172-31-30-115 etc]# vi /var/named/named.ca |
1 | ; <<>> DiG 9.9.2-P1-RedHat-9.9.2-6.P1.fc18 <<>> +bufsize=1200 +norec @a.root-servers.net |
Modify the file ‘etc/resolv.conf’:
The nameserver' line specifies the address of nameserver. The
search` set the searching order of client request:
If a client tries to look up foo, then foo.subdomain.your-domain.edu is tried first, then foo.your-domain.edu, and finally foo. You may not want to put in too many domains in the search line, as it takes time to search them all.
1 | # Generated by NetworkManager |
Deploy the Cache-only DNS server within chroot environment
1 | # yum install bind-chroot -y |
Start the named server
1 | [root@ip-172-31-30-115 network-scripts]# systemctl restart named |
Configured the client
Create an instance as our client
1 | ➜ ~ git:(master) ✗ aws ec2 run-instances --image-id ami-b63769a1 --count 1 --instance-type t2.micro --key-name keypair3 --security-groups mysg |
According to the above, our named server “PublicIpAddress” is “54.91.19.43”.
Clinet Public Dns is “ec2-54-242-90-155.compute-1.amazonaws.com”.
SSH to the client and change to ‘root’ user.
1 | ➜ Documents git:(master) ✗ ssh -i p.pem ec2-user@ec2-54-242-90-155.compute-1.amazonaws.com |
Edit /etc/sysconfig/network-scripts/ifcfg-lo (add ‘DNS=54.91.19.43’ in the end):
1 | DEVICE=lo |
Edit /etc/resolv.conf:
1 | [ec2-user@ip-172-31-23-114 ~]$ vi /etc/resolv.conf |
First, I find I can’t visit my name server. After a few mins, I realized that I didn’t set inbound of my ec2 security group to allow UDP request. Then I added rule of inbound to allow ALL UDP from my client ip in this security group.
tcpdump exercises
First scenario
Install telnet and tcpdump
1 | [root@ip-172-31-30-115 ec2-user]# yum install tcpdump |
Set tcpdump to record package information
1 | [root@ip-172-31-30-115 ec2-user]# tcpdump -w tcpdump.out port not 22 & |
Track down the packets in your tcpdump referring to the DNS query from your DNS server to one of the root servers, then to the various DNS servers before the DNS information is returned to your server by one of Yahoo’s authoritative DNS servers.
1 | [root@ip-172-31-30-115 ec2-user]# tcpdump -t -n -r tcpdump.out udp port 53 |
Identify the 3-way handshake that initiates the connection from your DNS server to port 80 on Yahoo’s webserver, the packets that are being sent back and forth and finally the closing of the connection.
1 | [root@ip-172-31-30-115 ec2-user]# tcpdump -n -r tcpdump.out tcp port 80 |
This is the 3-way handshake that initiates the connection from your DNS server to port 80 on Yahoo’s webserver:
1 | 21:42:35.282439 IP 172.31.30.115.54256 > 98.139.180.149.http: Flags [S], seq 854216136, win 26883, options [mss 8961,sackOK,TS val 97995307 ecr 0,nop,wscale 7], length 0 |
The packets that are being sent back :
1 | 21:42:41.537040 IP 172.31.30.115.54256 > 98.139.180.149.http: Flags [P.], seq 1:17, ack 1, win 211, length 16 |
and forth:
1 | 21:42:51.053313 IP 98.139.180.149.http > 172.31.30.115.54256: Flags [P.], seq 1:600, ack 40, win 58, length 599 |
and finally the closing of the connection:
1 | 21:42:52.539662 IP 98.139.180.149.http > 172.31.30.115.54256: Flags [FP.], seq 3520:7066, ack 42, win 58, length 3546 |
Second scenarios
Install tcpdump and telnet on client (the same step as first scenarios.)
Set tcpdump to listen
On server:
1 | [root@ip-172-31-30-115 ~]# tcpdump -w tcpdump.out port not 22 & |
On client:
1 | [root@ip-172-31-23-114 ~]# tcpdump -w tcpdump.out port not 22 & |
Run telnet
1 | [root@ip-172-31-23-114 ~]# telnet www.tumblr.com 80 |
Track down the packets in tcpdump referring to the DNS query from your client host to DNS server.
On client:
1 | [root@ip-172-31-23-114 ~]# tcpdump -t -n -r tcpdump.out udp port 53 |
Track down the packets in your tcpdump referring to the DNS query from your DNS server to one of the root servers, then to the various DNS servers before the DNS information is returned to your server by one of Tumblr’s authoritative DNS servers.
On server:
1 | [root@ip-172-31-30-115 ~]# kill %1 |
I found before the ‘telnet’ running in the client, my client sent some PTR requests for ‘1.16.31.172.in-addr.arpa’ and ‘218.24.13.126.in-addr.arpa’. The former looks loke the AWS internal IP address(private address).And my client also ask address for ‘softbank126013024218.bbtec.net’. These behaviors make me feel puzzled.
My client sent request to server for ‘www.tumblr.com‘. Then server will search its CNAME and ip address, and return the result to my client.
Third scenarios
For example, I perform a reverse host look up for ‘104.244.42.193’ which not yet in my DNS server’s cache.
1 | [root@ip-172-31-30-115 t]# tcpdump -w tcpdump.out port not 22 & |
Result:
1 | [root@ip-172-31-30-115 t]# tcpdump -t -n -r tcpdump.out udp port 53 |
1 | [root@ip-172-31-30-115 t]# tcpdump -t -r tcpdump.out udp port 53 |
My server communicate with these name servers:
199.253.183.183 b.in-addr-servers.arpa
199.180.180.63 r.arin.net
162.88.61.21 ns6.dynamicnetworkservices
These servers aren’t the root servers. And I also use ‘whois’ try to find their operators, but there isn’t any message about them.