0%

code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# coding: utf-8

import logging
from flask import Flask


app = Flask(__name__)


@app.route('/')
def index():
logging.info("here is index")
return "<span style='color:red'>I am app 1</span>"


def main():
app.run('*', '8080')


if __name__ == '__main__':
main()

Development Server

$ python3 main.py

1
2
$ curl localhost:8080
<span style='color:red'>I am app 1</span>%

uWSGI

uwsgi.ini:

1
2
3
4
5
6
7
[uwsgi]
socket = 127.0.0.1:9090
wsgi-file = main.py
callable = app
processes = 4
threads = 2
stats = 127.0.0.1:9191

nginx:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
server {
listen 80 default_server;
listen [::]:80 default_server;

# SSL configuration
#
# listen 443 ssl default_server;
# listen [::]:443 ssl default_server;
#
# Note: You should disable gzip for SSL traffic.
# See: https://bugs.debian.org/773332
#
# Read up on ssl_ciphers to ensure a secure configuration.
# See: https://bugs.debian.org/765782
#
# Self signed certs generated by the ssl-cert package
# Don't use them in a production server!
#
# include snippets/snakeoil.conf;

root /var/www/html;

# Add index.php to the list if you are using PHP
index index.html index.htm index.nginx-debian.html;

server_name _;

location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.

uwsgi_pass 127.0.0.1:9090;
include uwsgi_params;

try_files $uri $uri/ =404;
}

# pass PHP scripts to FastCGI server
#
#location ~ \.php$ {
# include snippets/fastcgi-php.conf;
#
# # With php-fpm (or other unix sockets):
# fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
# # With php-cgi (or other tcp sockets):
# fastcgi_pass 127.0.0.1:9000;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

$ uwsgi --ini uwsgi.ini

1
2
$ curl localhost
<span style='color:red'>I am app 1</span>%

Deployment

https://github.com/memcached/memcached See the file BUILD to learn how to build.

The default configuration file /etc/memcached.conf is used by scripts/start-memcached when using this script to start service.

Protocol

Protocol is described in doc/protocol.txt.

server:

1
2
3
4
5
6
7
8
9
10
11
12
$ memcached -vv -m 3 -M
<17 server listening (auto-negotiate)
<18 server listening (auto-negotiate)
<19 new auto-negotiating client connection
19: Client using the ascii protocol
<19 get foo
>19 END
<19 set foo 0 0 3
>19 STORED
<19 get foo
>19 sending key foo
>19 END

client:

1
2
3
4
5
6
7
8
9
10
$ nc -c localhost 11211
get foo
END
set foo 0 0 3
bar
STORED
get foo
VALUE foo 0 3
bar
END

Evication

server:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
$ memcached -vv -m 3 -M
<19 new auto-negotiating client connection
19: Client using the ascii protocol
<19 set 0 0 0 10240
>19 STORED
<19 set 1 0 0 10240
>19 STORED
<19 set 2 0 0 10240
>19 STORED
<19 set 3 0 0 10240
>19 STORED
<19 set 4 0 0 10240
>19 STORED
<19 set 5 0 0 10240
>19 STORED
<19 set 6 0 0 10240
>19 STORED
......
<19 set 280 0 0 10240
>19 STORED
<19 set 281 0 0 10240
>19 STORED
<19 set 282 0 0 10240
>19 SERVER_ERROR out of memory storing object
<19 connection closed.

client:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# coding: utf-8

from pymemcache.client import base


def main():
client = base.Client(('localhost', 11211), default_noreply=False)
sz = 0
pos = 0
while True:
key = str(pos)
value = 'x' * 10240
try:
res = client.set(key, value)
if res:
sz += len(key) + len(value)
pos += 1
else:
break
except Exception as e:
print('exception: %s, sz: %s' % (e, sz))
break


if __name__ == "__main__":
main()

1
2
$ python3 main.py
exception: b'out of memory storing object', sz: 2888416

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main

import (
"bytes"
"os"

"github.com/bradfitz/gomemcache/memcache"
logger "github.com/sirupsen/logrus"
"github.com/x-cray/logrus-prefixed-formatter"
)

func init() {
logger.SetFormatter(&prefixed.TextFormatter{
TimestampFormat: "2006-01-02 15:04:05",
FullTimestamp: true,
ForceFormatting: true,
DisableColors: true,
})
logger.SetOutput(os.Stdout)
logger.SetLevel(logger.DebugLevel)
}

func main() {
mc := memcache.New("localhost:11211")

buf := bytes.NewBuffer(nil)
for i := 0; i < 10240; i++ {
buf.WriteRune('x')
}

if err := mc.Set(&memcache.Item{
Key: "foo",
Value: buf.Bytes(),
}); err != nil {
logger.Errorf("set error: %v", err)
}

if it, err := mc.Get("32"); err != nil {
logger.Errorf("get error: %v, is miss: %v", err, err == memcache.ErrCacheMiss)
} else {
logger.Infof("key: %v, value: %v", it.Key, string(it.Value))
}

if it, err := mc.Get("non"); err != nil {
logger.Errorf("get error: %v, is miss: %v", err, err == memcache.ErrCacheMiss)
} else {
logger.Infof("key: %v, value: %v", it.Key, string(it.Value))
}
}
1
2
3
[2020-05-19 18:21:20] ERROR set error: memcache: unexpected response line from "set": "SERVER_ERROR out of memory storing object\r\n"
[2020-05-19 18:21:20] INFO key: 32, value: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[2020-05-19 18:21:20] ERROR get error: memcache: cache miss, is miss: true

Retransmission

TCP sets a timer when it sends data, and if the data is not acknowledged when the timer expires, a timeout or timer-based retransmission of data occurs. The timeout occurs after an interval called the retransmission timeout (RTO). It has another way of initiating a retransmission called fast retransmission or fast retransmit, which usually happens without any delay. Fast retransmit is based on inferring losses by noticing when TCP’s cumulative acknowledgment fails to advance in the ACKs received over time, or when ACKs carrying selective acknowledgment information (SACKs) indicate that out-of-order segments are present at the receiver. Generally speaking, when the sender believes that the receiver might be missing some data, a choice needs to be made between sending new (unsent) data and retransmitting.

Fast retransmit

Flow Control and Window Management

Reset

In general, a reset is sent by TCP whenever a segment arrives that does not appear to be correct for the referenced connection. The reset segment elicits no response from the other end—it is not acknowledged at all. The receiver of the reset aborts the connection and advises the application that the connection was reset. This often results in the error indication “Connection reset by peer” or a similar message.

TIME-WAIT

http://www.serverframework.com/asynchronousevents/2011/01/time-wait-and-its-design-implications-for-protocols-and-scalable-servers.html

https://stackoverflow.com/a/60075710/13133551

The two reasons for the existence of the TIME-WAIT state and the 2SML timer:

  • If the last ACK segment is lost, the server TCP, which sets a timer for the last FIN (Finish) bit set, assumes that its FIN is lost and resends it. If the client goes to the CLOSED state and closes the connection before the 2MSL timer expires, it never receives this resent FIN segment, and consequently, the server never receives the final ACK. The server cannot close the connection. The 2MSL timer makes the client wait for a duration that is enough time for an ACK to be lost (one SML) and a FIN to arrive (another SML). If during the TIME-WAIT state, a new FIN arrives, the client sends a new ACK and restarts the 2SML timer.
  • A duplicate segment from one connection might appear in the next one. Assume a client and a server have closed a connection. After a short period, they open a connection with the same socket addresses (same source and destination IP addresses and the same source and destination port numbers). A duplicated segment from the previous connection may arrive in this new connection and be interpreted as belonging to the new connection if there is not enough time between the two connections. To prevent this problem, TCP requires that an incarnation cannot occur unless a 2MSL amount of time has elapsed.

Timestamp option

http://www.networksorcery.com/enp/protocol/tcp/option008.htm

Timestamp Value (TSval). 32 bits.

This field contains the current value of the timestamp clock of the TCP sending the option.

Timestamp Echo Reply (TSecr). 32 bits.

This field is only valid if the ACK bit is set in the TCP header. If it is valid, it echos a timestamp value that was sent by the remote TCP in the TSval field of a Timestamps option. When TSecr is not valid, its value must be zero. The TSecr value will generally be from the most recent Timestamp option that was received; however, there are exceptions that are explained below. A TCP may send the Timestamp option in an initial SYN segment (i.e., segment containing a SYN bit and no ACK bit), and may send a TSopt in other segments only if it received a TSopt in the initial SYN segment for the connection.

Headers

Connection Management

State Tansition Diagram

Sequence Diagram

Normal

Simultaneous Open

Simultaneous Close

Half Close

Normal with State

Examples

server:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
In [1]: import socket

In [2]: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

In [3]: s.bind(('localhost', 30002))

In [4]: s.listen(5)

In [5]: conn, addr = s.accept()

In [6]: conn.send(b'who are you')
Out[6]: 11

In [7]: conn.recv(1024)
Out[7]: b'hello world'

In [8]: conn.recv(1024)
Out[8]: b''

In [9]: conn.close()

client

1
2
3
4
5
6
7
8
9
10
11
12
13
In [1]: import socket

In [2]: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

In [3]: s.connect(('localhost', 30002))

In [4]: s.send(b'hello world')
Out[4]: 11

In [5]: s.recv(1024)
Out[5]: b'who are you'

In [6]: s.close()

netstat

1
2
3
4
5
6
7
8
9
10
11
12
13
$ netstat -tan | grep 30002
tcp 0 0 127.0.0.1:30002 0.0.0.0:* LISTEN
$ netstat -tan | grep 30002
tcp 0 0 127.0.0.1:30002 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:30002 127.0.0.1:48496 ESTABLISHED
tcp 0 0 127.0.0.1:48496 127.0.0.1:30002 ESTABLISHED
$ netstat -tan | grep 30002
tcp 0 0 127.0.0.1:30002 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:30002 127.0.0.1:48496 CLOSE_WAIT
tcp 0 0 127.0.0.1:48496 127.0.0.1:30002 FIN_WAIT2
$ netstat -tan | grep 30002
tcp 0 0 127.0.0.1:30002 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:48496 127.0.0.1:30002 TIME_WAIT

tcpdump

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
$ sudo tcpdump -ilo "tcp and port 30002" -v -X
tcpdump: listening on lo, link-type EN10MB (Ethernet), capture size 262144 bytes
17:41:56.089133 IP (tos 0x0, ttl 64, id 29424, offset 0, flags [DF], proto TCP (6), length 60)
localhost.48496 > localhost.30002: Flags [S], cksum 0xfe30 (incorrect -> 0xc989), seq 310491251, win 43690, options [mss 65495,sackOK,TS val 327862915 ecr 0,nop,wscale 7], length 0
0x0000: 4500 003c 72f0 4000 4006 c9c9 7f00 0001 E..<r.@.@.......
0x0010: 7f00 0001 bd70 7532 1281 b873 0000 0000 .....pu2...s....
0x0020: a002 aaaa fe30 0000 0204 ffd7 0402 080a .....0..........
0x0030: 138a ca83 0000 0000 0103 0307 ............
17:41:56.089145 IP (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto TCP (6), length 60)
localhost.30002 > localhost.48496: Flags [S.], cksum 0xfe30 (incorrect -> 0x8343), seq 33121838, ack 310491252, win 43690, options [mss 65495,sackOK,TS val 327862915 ecr 327862915,nop,wscale 7], length 0
0x0000: 4500 003c 0000 4000 4006 3cba 7f00 0001 E..<..@.@.<.....
0x0010: 7f00 0001 7532 bd70 01f9 662e 1281 b874 ....u2.p..f....t
0x0020: a012 aaaa fe30 0000 0204 ffd7 0402 080a .....0..........
0x0030: 138a ca83 138a ca83 0103 0307 ............
17:41:56.089155 IP (tos 0x0, ttl 64, id 29425, offset 0, flags [DF], proto TCP (6), length 52)
localhost.48496 > localhost.30002: Flags [.], cksum 0xfe28 (incorrect -> 0x5588), ack 1, win 342, options [nop,nop,TS val 327862915 ecr 327862915], length 0
0x0000: 4500 0034 72f1 4000 4006 c9d0 7f00 0001 E..4r.@.@.......
0x0010: 7f00 0001 bd70 7532 1281 b874 01f9 662f .....pu2...t..f/
0x0020: 8010 0156 fe28 0000 0101 080a 138a ca83 ...V.(..........
0x0030: 138a ca83 ....
17:42:16.978059 IP (tos 0x0, ttl 64, id 29426, offset 0, flags [DF], proto TCP (6), length 63)
localhost.48496 > localhost.30002: Flags [P.], cksum 0xfe33 (incorrect -> 0xaf40), seq 1:12, ack 1, win 342, options [nop,nop,TS val 327868137 ecr 327862915], length 11
0x0000: 4500 003f 72f2 4000 4006 c9c4 7f00 0001 E..?r.@.@.......
0x0010: 7f00 0001 bd70 7532 1281 b874 01f9 662f .....pu2...t..f/
0x0020: 8018 0156 fe33 0000 0101 080a 138a dee9 ...V.3..........
0x0030: 138a ca83 6865 6c6c 6f20 776f 726c 64 ....hello.world
17:42:16.978068 IP (tos 0x0, ttl 64, id 44204, offset 0, flags [DF], proto TCP (6), length 52)
localhost.30002 > localhost.48496: Flags [.], cksum 0xfe28 (incorrect -> 0x2cb1), ack 12, win 342, options [nop,nop,TS val 327868137 ecr 327868137], length 0
0x0000: 4500 0034 acac 4000 4006 9015 7f00 0001 E..4..@.@.......
0x0010: 7f00 0001 7532 bd70 01f9 662f 1281 b87f ....u2.p..f/....
0x0020: 8010 0156 fe28 0000 0101 080a 138a dee9 ...V.(..........
0x0030: 138a dee9 ....
17:42:26.921826 IP (tos 0x0, ttl 64, id 44205, offset 0, flags [DF], proto TCP (6), length 63)
localhost.30002 > localhost.48496: Flags [P.], cksum 0xfe33 (incorrect -> 0x875c), seq 1:12, ack 12, win 342, options [nop,nop,TS val 327870623 ecr 327868137], length 11
0x0000: 4500 003f acad 4000 4006 9009 7f00 0001 E..?..@.@.......
0x0010: 7f00 0001 7532 bd70 01f9 662f 1281 b87f ....u2.p..f/....
0x0020: 8018 0156 fe33 0000 0101 080a 138a e89f ...V.3..........
0x0030: 138a dee9 7768 6f20 6172 6520 796f 75 ....who.are.you
17:42:26.921835 IP (tos 0x0, ttl 64, id 29427, offset 0, flags [DF], proto TCP (6), length 52)
localhost.48496 > localhost.30002: Flags [.], cksum 0xfe28 (incorrect -> 0x193a), ack 12, win 342, options [nop,nop,TS val 327870623 ecr 327870623], length 0
0x0000: 4500 0034 72f3 4000 4006 c9ce 7f00 0001 E..4r.@.@.......
0x0010: 7f00 0001 bd70 7532 1281 b87f 01f9 663a .....pu2......f:
0x0020: 8010 0156 fe28 0000 0101 080a 138a e89f ...V.(..........
0x0030: 138a e89f ....
17:42:39.804551 IP (tos 0x0, ttl 64, id 29428, offset 0, flags [DF], proto TCP (6), length 52)
localhost.48496 > localhost.30002: Flags [F.], cksum 0xfe28 (incorrect -> 0x0ca4), seq 12, ack 12, win 342, options [nop,nop,TS val 327873844 ecr 327870623], length 0
0x0000: 4500 0034 72f4 4000 4006 c9cd 7f00 0001 E..4r.@.@.......
0x0010: 7f00 0001 bd70 7532 1281 b87f 01f9 663a .....pu2......f:
0x0020: 8011 0156 fe28 0000 0101 080a 138a f534 ...V.(.........4
0x0030: 138a e89f ....
17:42:39.843347 IP (tos 0x0, ttl 64, id 44206, offset 0, flags [DF], proto TCP (6), length 52)
localhost.30002 > localhost.48496: Flags [.], cksum 0xfe28 (incorrect -> 0x0005), ack 13, win 342, options [nop,nop,TS val 327873854 ecr 327873844], length 0
0x0000: 4500 0034 acae 4000 4006 9013 7f00 0001 E..4..@.@.......
0x0010: 7f00 0001 7532 bd70 01f9 663a 1281 b880 ....u2.p..f:....
0x0020: 8010 0156 fe28 0000 0101 080a 138a f53e ...V.(.........>
0x0030: 138a f534 ...4
17:42:51.138882 IP (tos 0x0, ttl 64, id 44207, offset 0, flags [DF], proto TCP (6), length 52)
localhost.30002 > localhost.48496: Flags [F.], cksum 0xfe28 (incorrect -> 0xf4fc), seq 12, ack 13, win 342, options [nop,nop,TS val 327876677 ecr 327873844], length 0
0x0000: 4500 0034 acaf 4000 4006 9012 7f00 0001 E..4..@.@.......
0x0010: 7f00 0001 7532 bd70 01f9 663a 1281 b880 ....u2.p..f:....
0x0020: 8011 0156 fe28 0000 0101 080a 138b 0045 ...V.(.........E
0x0030: 138a f534 ...4
17:42:51.138897 IP (tos 0x0, ttl 64, id 27317, offset 0, flags [DF], proto TCP (6), length 52)
localhost.48496 > localhost.30002: Flags [.], cksum 0xe9eb (correct), ack 13, win 342, options [nop,nop,TS val 327876677 ecr 327876677], length 0
0x0000: 4500 0034 6ab5 4000 4006 d20c 7f00 0001 E..4j.@.@.......
0x0010: 7f00 0001 bd70 7532 1281 b880 01f9 663b .....pu2......f;
0x0020: 8010 0156 e9eb 0000 0101 080a 138b 0045 ...V...........E
0x0030: 138b 0045 ...E

What is endianness?

Little and big endian are two ways of storing multibyte data-types ( int, float, etc). In little endian machines, last byte of binary representation of the multibyte data-type is stored first. On the other hand, in big endian machines, first byte of binary representation of the multibyte data-type is stored first.

How to check

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <bits/stdc++.h>
#define DBG(x) cerr << #x << " = " << x << endl

using namespace std;
typedef long long LL;


string get_endian() {
union {
short s;
char c[sizeof(short)];
} un;
un.s = 0x1020;

if (sizeof(short) != 2)
return "sizeof(short) != 2";

if (un.c[0] == 0x20 && un.c[1] == 0x10)
return "little-endian";
if (un.c[0] == 0x10 && un.c[1] == 0x20)
return "big-endian";
return "unknown";

}

int main(int argc, char **argv) {
cout << "endian: " << get_endian() << "\n";
return 0;
}

Network byte order

https://stackoverflow.com/a/997586/13133551

"Network byte order" is Big Endian, and protocols such as TCP use this for integer fields (e.g. port numbers). Functions such as htons and ntohs can be used to do conversion.

The data itself doesn't have any endianness it's entirely application defined.

As we can see from the picture, the endianness of net is Big Endian.

Headers

Lables

Each label can be up to 63 characters long, and an entire FQDN(fully qualified domain name) is limited to at most 255 (1-byte) characters.

Query Format

Answer Format

Commands and Packets

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$ dig baidu.com

; <<>> DiG 9.16.1-Ubuntu <<>> baidu.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 22302
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;baidu.com. IN A

;; ANSWER SECTION:
baidu.com. 5 IN A 39.156.69.79
baidu.com. 5 IN A 220.181.38.148

;; Query time: 3 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: 日 5月 03 13:16:51 CST 2020
;; MSG SIZE rcvd: 70

Simulation

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
$ dig +trace baidu.com

; <<>> DiG 9.16.1-Ubuntu <<>> +trace baidu.com
;; global options: +cmd
. 5 IN NS l.root-servers.net.
. 5 IN NS g.root-servers.net.
. 5 IN NS b.root-servers.net.
. 5 IN NS d.root-servers.net.
. 5 IN NS j.root-servers.net.
. 5 IN NS c.root-servers.net.
. 5 IN NS a.root-servers.net.
. 5 IN NS e.root-servers.net.
. 5 IN NS m.root-servers.net.
. 5 IN NS f.root-servers.net.
. 5 IN NS i.root-servers.net.
. 5 IN NS k.root-servers.net.
. 5 IN NS h.root-servers.net.
;; Received 262 bytes from 127.0.0.53#53(127.0.0.53) in 4 ms

com. 172800 IN NS l.gtld-servers.net.
com. 172800 IN NS b.gtld-servers.net.
com. 172800 IN NS c.gtld-servers.net.
com. 172800 IN NS d.gtld-servers.net.
com. 172800 IN NS e.gtld-servers.net.
com. 172800 IN NS f.gtld-servers.net.
com. 172800 IN NS g.gtld-servers.net.
com. 172800 IN NS a.gtld-servers.net.
com. 172800 IN NS h.gtld-servers.net.
com. 172800 IN NS i.gtld-servers.net.
com. 172800 IN NS j.gtld-servers.net.
com. 172800 IN NS k.gtld-servers.net.
com. 172800 IN NS m.gtld-servers.net.
com. 86400 IN DS 30909 8 2 E2D3C916F6DEEAC73294E8268FB5885044A833FC5459588F4A9184CF C41A5766
com. 86400 IN RRSIG DS 8 1 86400 20200515170000 20200502160000 48903 . ypoqNHa/RJ1a9uTlm4QyNZ9V//oHsA2EnziYqGpmhTGWfZm1VbAriN/R cKPWdyq03XcdJl8chkHjyYFc2O7iLNiqJVTc2zUBKyBCcSY4nqftN4J+ Xhpn8i2PZaK89YoJ0u3ptUuoNQO7r7qqFoQA38TjZmVjb0xtpRsc3Qe8 NFzkHkpGG0lE87BUcxob2xxwG/w2THCu7067TbF9s5pm1NcOIgLpLrPN qAN9gal6OWpPcoj78SLrp+WG66yJLEQ1UgZafO3JaUTTUF78HCC08GL/ YfuQQSNVAJdkdYmhdSMNEPHF3YVYu2C6RWveng0HJeDfY487jKpgsmp7 0qfo8w==
;; Received 1169 bytes from 192.5.5.241#53(f.root-servers.net) in 312 ms

baidu.com. 172800 IN NS ns2.baidu.com.
baidu.com. 172800 IN NS ns3.baidu.com.
baidu.com. 172800 IN NS ns4.baidu.com.
baidu.com. 172800 IN NS ns1.baidu.com.
baidu.com. 172800 IN NS ns7.baidu.com.
CK0POJMG874LJREF7EFN8430QVIT8BSM.com. 86400 IN NSEC3 1 1 0 - CK0Q1GIN43N1ARRC9OSM6QPQR81H5M9A NS SOA RRSIG DNSKEY NSEC3PARAM
CK0POJMG874LJREF7EFN8430QVIT8BSM.com. 86400 IN RRSIG NSEC3 8 2 86400 20200509044919 20200502033919 39844 com. TuW7Gtye26JizEnQgFR2wx0iaSNeV0B+H+NGxpMvErXVC8UgY0qikZYw Q2edAoLCg1NUX+eQe6XJxCg6fxZXgmjY53nFrvS96DVAmlzHXIMGRZz9 XLb6r1dM5a9FmjWj7/Ad8CLFU4tKaARAP1eL7XAuFDIxOquFBlr2ezsz ekU8XCfOPXoFDVBREFxTbUmR09Dca+ZHK5aQmb+22qzr6A==
HPVUNU64MJQUM37BM3VJ6O2UBJCHOS00.com. 86400 IN NSEC3 1 1 0 - HPVVN3Q5E5GOQP2QFE2LEM4SVB9C0SJ6 NS DS RRSIG
HPVUNU64MJQUM37BM3VJ6O2UBJCHOS00.com. 86400 IN RRSIG NSEC3 8 2 86400 20200508042230 20200501031230 39844 com. O1F4LRXLKjRCSFcKBKFZRjVdZ7qGVDs2J3TcPWoiCg3XEfghP2I6lA8e SGhCEbmSuLlKh7bnhLuASVnN69/y+gVUtNa16eK2rNBtIrbBorwm32Dz KzMlZHdK5g5JI73IZtMaSz/oUKdqxpCgsilK0P7guLT5e9+q2pO2ROGg XrA4o3fThVbDWzRXvyXKFX1zCyBaHs+18ko17GGb8qTWDw==
;; Received 757 bytes from 192.42.93.30#53(g.gtld-servers.net) in 104 ms

baidu.com. 600 IN A 220.181.38.148
baidu.com. 600 IN A 39.156.69.79
baidu.com. 86400 IN NS ns4.baidu.com.
baidu.com. 86400 IN NS dns.baidu.com.
baidu.com. 86400 IN NS ns7.baidu.com.
baidu.com. 86400 IN NS ns3.baidu.com.
baidu.com. 86400 IN NS ns2.baidu.com.
;; Received 240 bytes from 220.181.33.31#53(ns2.baidu.com) in 12 ms

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
$ dig

; <<>> DiG 9.16.1-Ubuntu <<>>
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 18754
;; flags: qr rd ra; QUERY: 1, ANSWER: 13, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;. IN NS

;; ANSWER SECTION:
. 5 IN NS l.root-servers.net.
. 5 IN NS g.root-servers.net.
. 5 IN NS b.root-servers.net.
. 5 IN NS d.root-servers.net.
. 5 IN NS j.root-servers.net.
. 5 IN NS c.root-servers.net.
. 5 IN NS a.root-servers.net.
. 5 IN NS e.root-servers.net.
. 5 IN NS m.root-servers.net.
. 5 IN NS f.root-servers.net.
. 5 IN NS i.root-servers.net.
. 5 IN NS k.root-servers.net.
. 5 IN NS h.root-servers.net.

;; Query time: 4 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: 日 5月 03 13:28:35 CST 2020
;; MSG SIZE rcvd: 239

$ dig @l.root-servers.net. baidu.com

; <<>> DiG 9.16.1-Ubuntu <<>> @l.root-servers.net. baidu.com
; (2 servers found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 4979
;; flags: qr rd; QUERY: 1, ANSWER: 0, AUTHORITY: 13, ADDITIONAL: 27
;; WARNING: recursion requested but not available

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;baidu.com. IN A

;; AUTHORITY SECTION:
com. 172800 IN NS a.gtld-servers.net.
com. 172800 IN NS b.gtld-servers.net.
com. 172800 IN NS c.gtld-servers.net.
com. 172800 IN NS d.gtld-servers.net.
com. 172800 IN NS e.gtld-servers.net.
com. 172800 IN NS f.gtld-servers.net.
com. 172800 IN NS g.gtld-servers.net.
com. 172800 IN NS h.gtld-servers.net.
com. 172800 IN NS i.gtld-servers.net.
com. 172800 IN NS j.gtld-servers.net.
com. 172800 IN NS k.gtld-servers.net.
com. 172800 IN NS l.gtld-servers.net.
com. 172800 IN NS m.gtld-servers.net.

;; ADDITIONAL SECTION:
a.gtld-servers.net. 172800 IN A 192.5.6.30
b.gtld-servers.net. 172800 IN A 192.33.14.30
c.gtld-servers.net. 172800 IN A 192.26.92.30
d.gtld-servers.net. 172800 IN A 192.31.80.30
e.gtld-servers.net. 172800 IN A 192.12.94.30
f.gtld-servers.net. 172800 IN A 192.35.51.30
g.gtld-servers.net. 172800 IN A 192.42.93.30
h.gtld-servers.net. 172800 IN A 192.54.112.30
i.gtld-servers.net. 172800 IN A 192.43.172.30
j.gtld-servers.net. 172800 IN A 192.48.79.30
k.gtld-servers.net. 172800 IN A 192.52.178.30
l.gtld-servers.net. 172800 IN A 192.41.162.30
m.gtld-servers.net. 172800 IN A 192.55.83.30
a.gtld-servers.net. 172800 IN AAAA 2001:503:a83e::2:30
b.gtld-servers.net. 172800 IN AAAA 2001:503:231d::2:30
c.gtld-servers.net. 172800 IN AAAA 2001:503:83eb::30
d.gtld-servers.net. 172800 IN AAAA 2001:500:856e::30
e.gtld-servers.net. 172800 IN AAAA 2001:502:1ca1::30
f.gtld-servers.net. 172800 IN AAAA 2001:503:d414::30
g.gtld-servers.net. 172800 IN AAAA 2001:503:eea3::30
h.gtld-servers.net. 172800 IN AAAA 2001:502:8cc::30
i.gtld-servers.net. 172800 IN AAAA 2001:503:39c1::30
j.gtld-servers.net. 172800 IN AAAA 2001:502:7094::30
k.gtld-servers.net. 172800 IN AAAA 2001:503:d2d::30
l.gtld-servers.net. 172800 IN AAAA 2001:500:d937::30
m.gtld-servers.net. 172800 IN AAAA 2001:501:b1f9::30

;; Query time: 8 msec
;; SERVER: 199.7.83.42#53(199.7.83.42)
;; WHEN: 日 5月 03 13:28:42 CST 2020
;; MSG SIZE rcvd: 834

$ dig @a.gtld-servers.net. baidu.com

; <<>> DiG 9.16.1-Ubuntu <<>> @a.gtld-servers.net. baidu.com
; (2 servers found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 59027
;; flags: qr rd; QUERY: 1, ANSWER: 0, AUTHORITY: 5, ADDITIONAL: 6
;; WARNING: recursion requested but not available

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;baidu.com. IN A

;; AUTHORITY SECTION:
baidu.com. 172800 IN NS ns2.baidu.com.
baidu.com. 172800 IN NS ns3.baidu.com.
baidu.com. 172800 IN NS ns4.baidu.com.
baidu.com. 172800 IN NS ns1.baidu.com.
baidu.com. 172800 IN NS ns7.baidu.com.

;; ADDITIONAL SECTION:
ns2.baidu.com. 172800 IN A 220.181.33.31
ns3.baidu.com. 172800 IN A 112.80.248.64
ns4.baidu.com. 172800 IN A 14.215.178.80
ns1.baidu.com. 172800 IN A 202.108.22.220
ns7.baidu.com. 172800 IN A 180.76.76.92

;; Query time: 292 msec
;; SERVER: 192.5.6.30#53(192.5.6.30)
;; WHEN: 日 5月 03 13:28:48 CST 2020
;; MSG SIZE rcvd: 208

$ dig @ns2.baidu.com. baidu.com

; <<>> DiG 9.16.1-Ubuntu <<>> @ns2.baidu.com. baidu.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 2415
;; flags: qr aa rd; QUERY: 1, ANSWER: 2, AUTHORITY: 5, ADDITIONAL: 6
;; WARNING: recursion requested but not available

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;baidu.com. IN A

;; ANSWER SECTION:
baidu.com. 600 IN A 39.156.69.79
baidu.com. 600 IN A 220.181.38.148

;; AUTHORITY SECTION:
baidu.com. 86400 IN NS ns7.baidu.com.
baidu.com. 86400 IN NS ns2.baidu.com.
baidu.com. 86400 IN NS dns.baidu.com.
baidu.com. 86400 IN NS ns3.baidu.com.
baidu.com. 86400 IN NS ns4.baidu.com.

;; ADDITIONAL SECTION:
dns.baidu.com. 86400 IN A 202.108.22.220
ns2.baidu.com. 86400 IN A 220.181.33.31
ns3.baidu.com. 86400 IN A 112.80.248.64
ns4.baidu.com. 86400 IN A 14.215.178.80
ns7.baidu.com. 86400 IN A 180.76.76.92

;; Query time: 8 msec
;; SERVER: 220.181.33.31#53(220.181.33.31)
;; WHEN: 日 5月 03 13:28:54 CST 2020
;; MSG SIZE rcvd: 240

We can see the response of $ dig @ns2.baidu.com. baidu.com have aa flag set.