LoginSignup
4
1

More than 5 years have passed since last update.

AzureのVMはなぜ設定なしでインターネットにつながるのか(番外) -UbuntuでDNSのデフォ設定が127.0.0.53#53だった件-

Last updated at Posted at 2018-12-05

※この記事は「AzureのIaaSはなぜ設定なしでインターネットにつながるのか①」の投稿をまとめていたときに
Azureとは関係ないUbuntuの設定でDNSの応答サーバが127.0.0.53#53だったことを発端に調査開始したUbunttu番外編のネタです。
ただ、この記事の最後に予想外の展開でAzureの世界へのループバックしますのでお楽しみに・・💛

:heart:関連記事:heart:
- AzureのVMはなぜ設定なしでネットにつながるのか①- Azureのデフォルトリゾルバ(168.63.129.16)について-
- AzureのVMはなぜ設定なしでネットにつながるのか(番外)-UbuntuでDNSのデフォ設定が127.0.0.53#53だった件-

Azure上のUbuntuVMで名前解決してみた結果

今回の環境はUbuntu18.04.1をMarketplaceから選択して作成し、
Azure上ではDHCPで勝手にDNSが設定された状態でdigコマンドを実行します。

一応バージョンは下記

user@testserver:~$ cat /etc/issue
Ubuntu 18.04.1 LTS \n \l

digをすると・・

user@testserver:~$ dig www.yahoo.co.jp
:中略
;; ANSWER SECTION:
www.yahoo.co.jp.        780     IN      CNAME   edge12.g.yimg.jp.
edge12.g.yimg.jp.       38      IN      A       182.22.25.252
:中略
;; Query time: 343 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Wed Dec 05 05:12:03 UTC 2018
:中略

yahooのアドレスが解決できました:v:
IaaSを立てて何も設定しなくてもすぐに名前解決ができることにモヤモヤしつつ
名前解決できた理由を調査していると・・

問い合わせを返しているサーバのアドレスが

127.0.0.53の53番ポートって・・・

ん!?ナンダコレハ。

127.0.0.XXということはローカルに問い合わせしてるー:weary:

こうなったら設定みるべです。

DNSリゾルブ設定も確認

古い人間なのでLinuxのリゾルバ設定っていえば/etc/resolv.confでしょということで
早速みてみると...

/etc/resolv.conf
user@testserver:~$ cat /etc/resolv.conf
# This file is managed by man:systemd-resolved(8). Do not edit.

# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.

# Run "systemd-resolve --status" to see details about the uplink DNS servers
# currently in use.
: 中略
nameserver 127.0.0.53
search xxxxxxxx.xx.internal.cloudapp.net

ん!?なんかdynamicとかDo not editとか書いてあるぞ・・

nameserverの記載はあったけどnameserver 127.0.0.53って:joy:
digの結果と同じだけどーだけどー・・

コメントの内容を読むとNetworkManagerなど同様でUbuntuさんが勝手に設定しちゃうよんという内容:weary:
古き良き手動設定ではなく今どきな感じでsystemd-resolvedによって動的に生成されてしまってるようだ・・:weary:

systemd-resolvedって何ですのん!?

現状のUbuntuのデフォルト設定とのことでなのでたくさん情報あり。
備忘録的に確認したWebをはりはりしてきます。

systemd-resolvedとは

/etc/resolv.confのコメントに記載の通りsystemd-resolvedはスタブリソルバ
本業AzureなのでそこまでDeepDiveしないけれど機能違いでdnsmasqなどもある。

127.0.0.53#53とは

systemd-resolvedで利用しているIPとポート。

systemd-resolvedを利用しているかの確認方法

リゾルバはデフォルトではsystemd-resolvedだけでなくdnsmasqもあるので53番ポートのリッスン状況で
systemd-resolvedを利用しているかを確認

Ubuntu18.04のDNSリゾルバをsystemd-resolvedからdnsmasqに変更する

user@testserver:~$ sudo lsof -i:53
COMMAND   PID            USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
systemd-r 718 systemd-resolve   12u  IPv4  14576      0t0  UDP localhost:domain
systemd-r 718 systemd-resolve   13u  IPv4  14577      0t0  TCP localhost:domain (LISTEN)

systemd-rがリッスンしてるのでsystemd-resolvedがサービス提供していると確認できた。

実際のリゾルバの設定は/etc/resolv.confじゃなくてどこに記載されている?

下記をみながら確認してみる。
- Ubuntuで「ネームサーバー」の設定を確認する方法

↑で/etc/resolv.confは動的に生成されているといいましたが、ファイル自体systemd配下へのリンクになっています。

user@testserver:~$ ls -l /etc/resolv.conf
lrwxrwxrwx 1 root root 39 Nov  1 21:29 /etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf

そこで実際に確認をするのがsystemd-resolve --statusコマンド。
実行してみると・・・

user@testserver:~$ systemd-resolve --status
Global
          DNSSEC NTA: 10.in-addr.arpa
:中略
Link 2 (eth0)
      Current Scopes: DNS
:中略
         DNS Servers: 168.63.129.16
         DNS Domain: xxxxxxxx.xx.internal.cloudapp.net(伏字)

DNSの設定内容発見!!
でも、/etc/resolv.confには記載がない・・

DNS設定の元ネタ(systemd-resolvedの設定)はどこに・・

動的に設定されるようになってからどこに設定されているのか謎なことがおおいですが、
下記サイトに手がかりになる情報が。

systemd-resolveが問い合わせるネームサーバーのIPアドレスは、「/run/systemd/resolve/resolv.conf」に記述されています。ここに記載されるIPアドレスは、DHCPサーバーから取得したものや、デスクトップ版ならGUIで設定したもの、サーバー版なら「/etc/netplan/」以下のYAMLファイルに記述したもの、そして「/etc/systemd/resolved.conf」で設定したものです。

/etc/systemd/resolved.confからみてみる

/etc/systemd/resolved.conf
user@testserver:~$ cat /etc/systemd/resolved.conf
:#コメント中略
[Resolve]
#DNS=
#FallbackDNS=
#Domains=
#LLMNR=no
#MulticastDNS=no
#DNSSEC=no
#Cache=yes

なにも設定入っていない・・

お次はDHCP設定の確認

/etc/network/interfaces

user@testserver:~$ cat /etc/network/interfaces
# ifupdown has been replaced by netplan(5) on this system.  See
# /etc/netplan for current configuration.
# To re-enable ifupdown on this system, you can run:
#    sudo apt install ifupdown

DHCPの設定はなし

お次は/etc/netplan/

2つのファイルが!!
しかも今回Azureで構成しましたが、
cloudやAzureの文字が!これは何かありそう!

/etc/netplan/*

user@testserver:~$  ls -l /etc/netplan/
total 8
-rw-r--r-- 1 root root 473 Dec  4 11:43 50-cloud-init.yaml
-rw-r--r-- 1 root root 554 Nov  2 01:00 90-hotplug-azure.yaml
/etc/netplan/50-cloud-init.yaml

user@testserver:~$  cat /etc/netplan/50-cloud-init.yaml
# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    version: 2
    ethernets:
        eth0:
            dhcp4: true
            match:
                macaddress: 00:0d:3a:f2:49:48
            set-name: eth0
/etc/netplan/90-hotplug-azure.yaml
user@testserver:~$  cat /etc/netplan/90-hotplug-azure.yaml
# This netplan yaml is delivered in Azure cloud images to support
# attaching and detaching nics after the instance first boot.
# Cloud-init otherwise handles initial boot network configuration in
# /etc/netplan/50-cloud-init.yaml
network:
    version: 2
    ethernets:
        ephemeral:
            dhcp4: true
            match:
                driver: hv_netvsc
                name: '!eth0'
            optional: true
        hotpluggedeth0:
            dhcp4: true
            match:
                driver: hv_netvsc
                name: 'eth0'

dhcp4: true!?
dhcpをなにがしか設定している様子!!!:heart_eyes_cat:ハスハス💛

次回は・・

Ubuntuの世界からAzureの世界へもどってAzureのVMはなぜ設定なしでインターネットにつながるのか②
dhcp4: trueの記載があった/etc/netplan/*を深堀していきマス💛

その他参考にさせていただいた記事

127.0.0.53:53 って 誰が 使ってるの?

:heart:関連記事:heart:
- AzureのVMはなぜ設定なしでネットにつながるのか①- Azureのデフォルトリゾルバ(168.63.129.16)について-
- AzureのVMはなぜ設定なしでネットにつながるのか(番外)-UbuntuでDNSのデフォ設定が127.0.0.53#53だった件-

4
1
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
4
1