DNSタグで学んだこと

[Linuxコマンド集 - 【 dig 】 ドメイン情報をDNSサーバーから取得する：ITpro](http://itpro.nikkeibp.co.jp/article/COLUMN/20060227/230743/)

[/etc/resolv.conf が勝手に書き換えられて悲しいときの対処法](http://qiita.com/okkez@github/items/1f5b5d83fed513b446f5)
===========================

ubuntu, centos共通。(macでは使えない)

```diff:/etc/dhcp/dhclient.conf
+prepend domain-name-servers 192.168.30.1; 
```

[osx で dnsmasq を homebrew で入れてみる](http://qiita.com/okitan/items/fbc4cf39d63eb7152049)
===========================

```bash:DNSキャッシュのクリア(mac)
$ sudo dscacheutil -flushcache
```

[想像できそうなdig情報を一覧するスクリプト](http://qiita.com/Katsumata_RYO/items/6b52b3d1f78403c55085)
===========================

これでいい。

```bash:dig_all.sh
#!/bin/sh
set -eu

if [ $# -eq 0 ];then
    echo "usage: $0 domain dnsserver"
    echo "ex) $0 aa.dev @127.0.0.1"
    exit 0
fi

DOMAIN=$1
DNS_SERVER=""
if [ $# -eq 2 ];then
    DNS_SERVER=${2}
fi

echo "# ${DOMAIN}"
dig any ${DOMAIN} ${DNS_SERVER} | egrep -v "(;|^$)" | sort -k 4 | uniq
if [ "`dig any ${DOMAIN} ${DNS_SERVER} | grep SOA`" = "" ];then
    dig soa ${DOMAIN} ${DNS_SERVER} | grep SOA | grep -v ";"
fi
```

```bash:使い方
$ ./dig_all.sh
usage: ./dig_all.sh domain dnsserver
ex) ./dig_all.sh aa.dev @127.0.0.1

$ ./dig_all.sh qiita.com
# qiita.com
ns-171.awsdns-21.com.	45934	IN	A	205.251.192.171
ns-772.awsdns-32.net.	45479	IN	A	205.251.195.4
ns-1049.awsdns-03.org.	45479	IN	A	205.251.196.25
ns-1956.awsdns-52.co.uk. 45478	IN	A	205.251.199.164
qiita.com.		34	IN	A	54.248.227.194
qiita.com.		45479	IN	NS	ns-1049.awsdns-03.org.
qiita.com.		45479	IN	NS	ns-171.awsdns-21.com.
qiita.com.		45479	IN	NS	ns-1956.awsdns-52.co.uk.
qiita.com.		45479	IN	NS	ns-772.awsdns-32.net.
qiita.com.		86338	IN	SOA	ns-1956.awsdns-52.co.uk. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400
```


[infrastructure - ネームサーバ移行　〜虎の巻〜](http://qiita.com/YamaguchiRei/items/280eb9cdd75842c418bd)
===========================

TTL
---

```bash:TTL確認
$ dig qiita.com
qiita.com.		47	IN	A	54.248.227.194
```

クライアントは1回DNS問い合わせをしたら47秒間は再度問い合わせをしないという意味。
AWSだから短くしてるのかな。


ネガティブキャッシュ
--------------------

FQDNが存在しないことをキャッシュする時間。(86400 = 24時間)

```bash:一番後ろの数字 (86400)
$ dig soa qiita.com
qiita.com.		86338	IN	SOA	ns-1956.awsdns-52.co.uk. awsdns-hostmaster.amazon.com. 1 7200 900 1209600 86400
```

ルートサーバのTTL
--------------------

```bash:
$ dig moongift.jp ns @g.dns.jp | grep "^m"
moongift.jp.		86400	IN	NS	ns2.value-domain.com.
moongift.jp.		86400	IN	NS	ns1.value-domain.com.
moongift.jp.		86400	IN	NS	ns3.value-domain.com.
```

IN の左の数字 86400 が`ネームサーバを移転した場合に伝播しきるまでに必要な時間`。



[ワイルドカード CNAME と Apache の vhost_alias でバーチャルホストを作る](http://qiita.com/ngyuki/items/8cb089023075b825e41a)
===========================

```bash:CNAMEに*を設定
example.net.zone
www             IN      A       192.0.2.123
*               IN      CNAME   www
```

```diff:httpd.conf
+LoadModule vhost_alias_module modules/mod_vhost_alias.so
```

```diff:httpd.conf
<VirtualHost *:80>
        ServerName www.example.net
        ServerAlias *.example.net
        VirtualDocumentRoot /home/htdocs/%1/html
        <Directory /home/htdocs>
                AllowOverride All
                Order allow,deny
                Allow from all
        </Directory>
</VirtualHost>
```

* /home/htdocs/aaa/html/ にファイルを置けば http://aaa.example.net/
* /home/htdocs/bbb/html/ にファイルを置けば http://bbb.example.net/


[Homebrewでdnsmasqをインストールして、Web開発用にDNSサーバを立てる](http://qiita.com/ispern/items/a43d6bbfca73ee0b8173)
===========================

```bash:
$ brew install dnsmasq
$ cp /usr/local/opt/dnsmasq/dnsmasq.conf.example /usr/local/etc/dnsmasq.conf
```

```diff:/usr/local/etc/dnsmasq.conf
-#address=/double-click.net/127.0.0.1
+#address=/local/127.0.0.1
-#listen-address=
+listen-address=127.0.0.1
```

```bash:起動スクリプト
$ sudo cp -fv /usr/local/opt/dnsmasq/homebrew.mxcl.dnsmasq.plist /Library/LaunchDaemons
$ sudo launchctl unload /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
$ sudo launchctl load -w /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
```

```bash:/etc/resolv.conf
 domain plala.co.jp
+nameserver 127.0.0.1
 nameserver 192.168.0.1
```

他のnameserverより前に書くこと。

```bash:動作確認
$ dig_all.sh aa.dev
aa.dev.			0	IN	A	127.0.0.1
```

apacheの設定に使うなら以下

```diff:httpd.conf
<VirtualHost *:80>
        ServerName dev
        ServerAlias *.dev
        VirtualDocumentRoot /home/htdocs/%1/html
        <Directory /home/htdocs>
                AllowOverride All
                Order allow,deny
                Allow from all
        </Directory>
</VirtualHost>
```


[ローカルDNSを立てずにホスト名をIPアドレスに解決する超絶簡単な方法](http://qiita.com/tady/items/b7b46486fb3175dac0b1)
===========================

[xip.io](http://xip.io/)覚えておこう。

```bash:
          192.168.11.2.xip.io   resolves to   192.168.11.2
      www.192.168.11.2.xip.io   resolves to   192.168.11.2
   mysite.192.168.11.2.xip.io   resolves to   192.168.11.2
```

[DNSゾーン転送をslave側から強制実施](http://qiita.com/n_morioka/items/3b08499c9a40a66156f9)
===========================

```bash:
$ sudo rndc retransfer example.com
```

[BIND9 で Dynamic DNS のゾーン情報を確認](http://qiita.com/ngyuki/items/65f6c80a1819bf239e75)
===========================

わからん。bind勉強してからにしよう。