Cloudflare に対する DNS コマンドメモ

# Normal DNS

- [1.1.1.1 docs](https://developers.cloudflare.com/1.1.1.1/)

## IPv4 query

### IPv4 record

```shell
dig -4 @1.1.1.1 www.cloudflare.com A +short
```

### IPv6 record

```shell
dig -4 @1.1.1.1 www.cloudflare.com AAAA +short
```

## IPv6 query

### IPv4 record

```shell
dig -6 @2606:4700:4700::1111 www.cloudflare.com A +short
```

### IPv6 record

```shell
dig -6 @2606:4700:4700::1111 www.cloudflare.com AAAA +short
```

# DNS over HTTPS (DoH)

- [Making requests · 1.1.1.1 docs](https://developers.cloudflare.com/1.1.1.1/dns-over-https/request-structure)

## IPv4 query

### IPv4 record

```shell
curl -4 -s -H 'accept: application/dns-json' \
'https://cloudflare-dns.com/dns-query?name=www.cloudflare.com&type=A' | jq
```

個人的には結果が見やすいのが好みです。

```json
{
  "Status": 0,
  "TC": false,
  "RD": true,
  "RA": true,
  "AD": true,
  "CD": false,
  "Question": [
    {
      "name": "www.cloudflare.com",
      "type": 1
    }
  ],
  "Answer": [
    {
      "name": "www.cloudflare.com",
      "type": 1,
      "TTL": 53,
      "data": "104.16.123.96"
    },
    {
      "name": "www.cloudflare.com",
      "type": 1,
      "TTL": 53,
      "data": "104.16.124.96"
    }
  ]
}
```

### IPv6 record

```shell
curl -4 -s -H 'accept: application/dns-json' \
'https://cloudflare-dns.com/dns-query?name=www.cloudflare.com&type=AAAA' | jq
```

## IPv6 query

### IPv4 record

```shell
curl -6 -s -H 'accept: application/dns-json' \
'https://cloudflare-dns.com/dns-query?name=www.cloudflare.com&type=A' | jq
```

### IPv6 record

```shell
curl -6 -s -H 'accept: application/dns-json' \
'https://cloudflare-dns.com/dns-query?name=www.cloudflare.com&type=AAAA' | jq
```

# DNS over TLS (DoT)

- [Installation — Knot DNS 2.6.9 documentation](https://www.knot-dns.cz/docs/2.6/html/installation.html#installation-from-a-package)

```shell
brew install knot
```

- [DNS over TLS · 1.1.1.1 docs](https://developers.cloudflare.com/1.1.1.1/dns-over-tls)

## IPv4 query

### IPv4 record

```shell
kdig -4 @1.1.1.1 +tls-ca +tls-host=cloudflare-dns.com  www.cloudflare.com A +short
```

↓結果

```shell
;; TLS session (TLS1.3)-(ECDHE-X25519)-(ECDSA-SECP256R1-SHA256)-(AES-256-GCM)
;; ->>HEADER<<- opcode: QUERY; status: NOERROR; id: 49543
;; Flags: qr rd ra; QUERY: 1; ANSWER: 2; AUTHORITY: 0; ADDITIONAL: 1

;; EDNS PSEUDOSECTION:
;; Version: 0; flags: ; UDP size: 1232 B; ext-rcode: NOERROR
;; PADDING: 385 B

;; QUESTION SECTION:
;; www.cloudflare.com. 		IN	A

;; ANSWER SECTION:
www.cloudflare.com. 	83	IN	A	104.16.124.96
www.cloudflare.com. 	83	IN	A	104.16.123.96

;; Received 468 B
;; Time 2021-07-07 09:56:54 JST
;; From 1.1.1.1@853(TCP) in 12.7 ms
```

### IPv6 record

```shell
kdig -4 @1.1.1.1 +tls-ca +tls-host=cloudflare-dns.com  www.cloudflare.com AAAA +short
```

## IPv6 query

### IPv4 record

```shell
kdig -6 @2606:4700:4700::1111 +tls-ca +tls-host=cloudflare-dns.com  www.cloudflare.com A +short
```

### IPv6 record

```shell
kdig -6 @2606:4700:4700::1111 +tls-ca +tls-host=cloudflare-dns.com  www.cloudflare.com AAAA +short
```

# 参考：Whoami

## IPv4 query

```shell
dig -4 +short @1.1.1.1 whoami.cloudflare ch txt | sed "s/\"//g"
```

## IPv6 query

```shell
dig -6 +short @2606:4700:4700::1111 ch txt whoami.cloudflare | sed "s/\"//g"
```

# 参考：Whoami over TLS

## IPv4 query

```shell
kdig -4 @1.1.1.1 +tls-ca +tls-host=cloudflare-dns.com whoami.cloudflare ch txt +short | sed "s/\"//g"
```

## IPv6 query

```shell
kdig -6 @2606:4700:4700::1111 +tls-ca +tls-host=cloudflare-dns.com whoami.cloudflare ch txt +short | sed "s/\"//g"
```

# 参考：WhatsMyIp

## IPv4 query

```shell
curl -4 -s https://cloudflare.com/cdn-cgi/trace | grep ip | awk -F'=' '{print $2}'
```

## IPv6 query

```shell
curl -6 -s https://cloudflare.com/cdn-cgi/trace | grep ip | awk -F'=' '{print $2}'
```

# 参考：Which node

```shell
dig -4 +short @1.1.1.1 id.server ch txt | sed "s/\"//g"
```