LoginSignup
2
0

More than 3 years have passed since last update.

DnsmasqでCNAMEレコードを返却する

Posted at

Dnsmasqを使って、任意のドメインに対してCNAMEで別のドメインを返却し、そのドメインの名前解決を外部DNSへ再帰問い合わせする、という機能が実現できるか調査した。

結論としては、DnsmasqでCNAMEレコードを返却できるのはDnsmasqが(hostsファイルなどで)名前解決できるドメインのみであり、上記の機能は実現できないことがわかった。

検証方法・結果

docker-componse.yml
version: '3'
services:
  dnsmasq:
    image: andyshinn/dnsmasq
    command: >
      --auth-server=abc.com,eth0
      --auth-zone=abc.com
      --server=/google.com/8.8.8.8
      --cname=one.abc.com,google.com
      --dns-rr=two.abc.com,5,06676f6f676c6503636f6d00
    hostname: dnsmasq
    ports:
      - 53:53/udp
      - 53:53/tcp
    restart: always
    cap_add:
      - NET_ADMIN
  shell:
    tty: true
    build:
      context: .
Dockerfile
FROM ubuntu:18.04

RUN apt-get update \
    && apt-get install -y locales locale-gen ja_JP.UTF-8 \
    && echo "export LANG=ja_JP.UTF-8" >> ~/.bashrc
    && apt-get install -y iputils-ping net-tools dnsutils

CMD ["bash"]
DNS問い合わせ結果
# DnsmasqをAuthoritative modeで動かしている場合は、
# cnameオプションで返却するドメインもDnsmasqが権威を持つとみなされ、外部DNSへの転送が行われない。
# manページの引用:
# --cname as long as the record name is in the authoritative domain.
# If the target of the CNAME is unqualified,
# then it is qualified with the authoritative zone name. 
dig @dnsmasq one.abc.com

;; flags: qr aa rd ad; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
;; WARNING: recursion requested but not available

;; QUESTION SECTION:
;one.abc.com.                   IN      A

;; ANSWER SECTION:
one.abc.com.            600     IN      CNAME   google.com.
# 任意のレコードを返却できるdns-rrオプションも存在するが、
# このオプションで設定したレコードはAレコードの解決では返却されない。
dig @dnsmasq two.abc.com

;; flags: qr aa rd ad; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1
;; WARNING: recursion requested but not available

;; QUESTION SECTION:
;two.abc.com.                   IN      A

参考

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0