質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Ubuntu

Ubuntuは、Debian GNU/Linuxを基盤としたフリーのオペレーティングシステムです。

Vagrant

Vagrantは、VirtualBox上の仮想マシンを コマンドラインから作成してくれるソフトウェアです。 ビルド環境など容易に構築が可能です。

Q&A

解決済

2回答

1879閲覧

Ubuntuで名前解決ができない

Gr.

総合スコア89

Ubuntu

Ubuntuは、Debian GNU/Linuxを基盤としたフリーのオペレーティングシステムです。

Vagrant

Vagrantは、VirtualBox上の仮想マシンを コマンドラインから作成してくれるソフトウェアです。 ビルド環境など容易に構築が可能です。

0グッド

3クリップ

投稿2019/02/14 06:49

編集2019/02/14 09:12

Ubuntuで以下のように名前解決ができない問題と格闘中です。

$ curl https://google.com

vagrant@vagrant-ubuntu-trusty-32:~$ curl https://google.com curl: (6) Could not resolve host: google.com

/etc/resolv.confにnameservers 8.8.8.8を書こうとしたところ、ファイルがないという返事が返ってきました。次に/etc/network/interfacesを見たところ、なぜかgatewaydns-nameserversが書かれていないかったのですが、そもそもここが問題なのでしょうか。

$ cat /etc/network/interfaces

vagrant@vagrant-ubuntu-trusty-32:$ cat /etc/network/interfaces # This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). # The loopback network interface auto lo iface lo inet loopback # Source interfaces # Please check /etc/network/interfaces.d before changing this file # as interfaces may have been defined in /etc/network/interfaces.d # NOTE: the primary ethernet device is defined in # /etc/network/interfaces.d/eth0 # See LP: #1262951 source /etc/network/interfaces.d/*.cfg #VAGRANT-BEGIN # The contents below are automatically generated by Vagrant. Do not modify. auto eth1 iface eth1 inet static address 192.168.33.10 netmask 255.255.255.0  ←この下に普通はgatewayやdns-nameserversが書かれていると思います。 #VAGRANT-END

$ route -n

vagrant@vagrant-ubuntu-trusty-32:$ route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface 0.0.0.0 10.0.2.2 0.0.0.0 UG 0 0 0 eth0 10.0.2.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0 ←なぜeth0が2つある? 192.168.33.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1

上記を踏まえ、教えていただきたいことは以下の4点です。
0. /etc/network/interfacesの中にgatewaydns-nameserversが書かれていないのですが、このこととUbuntuで名前解決ができないことは関係ありそうですか?
0. そうだった場合、/etc/network/interfacesgatewaydns-nameserversを書き入れる必要があると思いますが、書く内容はGateway 10.0.2.2, dns-nameservers 8.8.8.8で大丈夫でしょうか?
0. そうだった場合、# The contents below are automatically generated by Vagrant. Do not modify.とあるようにvi /etc/network/interfacesでは編集できないのですが(実際にやってみてダメでした)、どうやって追記するのですか?
0. $ route -nの結果にeth0が2つ出ていますが、これは問題ないですか?


以下、参考までに

WindowsでVirtualBox+Vagrant+Ubuntu
Ubuntu 16.04.4 LTS

$ cat /etc/resolv.conf

vagrant@vagrant-ubuntu-trusty-32:$ cat /etc/resolv.conf cat: /etc/resolv.conf: No such file or directory

$ ifconfig

vagrant@vagrant-ubuntu-trusty-32:$ ifconfig eth0 Link encap:Ethernet HWaddr 08:00:27:88:e7:b2 inet addr:10.0.2.15 Bcast:10.0.2.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fe88:e7b2/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:8641 errors:0 dropped:0 overruns:0 frame:0 TX packets:8216 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:589752 (589.7 KB) TX bytes:11584764 (11.5 MB) eth1 Link encap:Ethernet HWaddr 08:00:27:8d:04:d3 inet addr:192.168.33.10 Bcast:192.168.33.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fe8d:4d3/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:62 errors:0 dropped:0 overruns:0 frame:0 TX packets:16 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:9177 (9.1 KB) TX bytes:1296 (1.2 KB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:64 errors:0 dropped:0 overruns:0 frame:0 TX packets:64 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1 RX bytes:4848 (4.8 KB) TX bytes:4848 (4.8 KB)

$ ip route show

vagrant@vagrant-ubuntu-trusty-32:$ ip route show default via 10.0.2.2 dev eth0 10.0.2.0/24 dev eth0 proto kernel scope link src 10.0.2.15 192.168.33.0/24 dev eth1 proto kernel scope link src 192.168.33.10

追記

Vagrantfile

1# -*- mode: ruby -*- 2# vi: set ft=ruby : 3 4# All Vagrant configuration is done below. The "2" in Vagrant.configure 5# configures the configuration version (we support older styles for 6# backwards compatibility). Please don't change it unless you know what 7# you're doing. 8Vagrant.configure(2) do |config| 9 # The most common configuration options are documented and commented below. 10 # For a complete reference, please see the online documentation at 11 # https://docs.vagrantup.com. 12 13 # Every Vagrant development environment requires a box. You can search for 14 # boxes at https://atlas.hashicorp.com/search. 15 config.vm.box = "ubuntu/trusty32" 16 # Disable automatic box update checking. If you disable this, then 17 # boxes will only be checked for updates when the user runs 18 # `vagrant box outdated`. This is not recommended. 19 # config.vm.box_check_update = false 20 21 # Create a forwarded port mapping which allows access to a specific port 22 # within the machine from a port on the host machine. In the example below, 23 # accessing "localhost:8080" will access port 80 on the guest machine. 24 config.vm.network "forwarded_port", guest: 3000, host: 3000 25 26 # Create a private network, which allows host-only access to the machine 27 # using a specific IP. 28 config.vm.network "private_network", ip: "192.168.33.10" 29 30 # Create a public network, which generally matched to bridged network. 31 # Bridged networks make the machine appear as another physical device on 32 # your network. 33 # config.vm.network "public_network" 34 35 # Share an additional folder to the guest VM. The first argument is 36 # the path on the host to the actual folder. The second argument is 37 # the path on the guest to mount the folder. And the optional third 38 # argument is a set of non-required options. 39 config.vm.synced_folder "./", "/home/vagrant" 40 41 # Provider-specific configuration so you can fine-tune various 42 # backing providers for Vagrant. These expose provider-specific options. 43 # Example for VirtualBox: 44 # 45 # config.vm.provider "virtualbox" do |vb| 46 # # Display the VirtualBox GUI when booting the machine 47 # vb.gui = true 48 # 49 # # Customize the amount of memory on the VM: 50 # vb.memory = "1024" 51 # end 52 # 53 # View the documentation for the provider you are using for more 54 # information on available options. 55 56 # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies 57 # such as FTP and Heroku are also available. See the documentation at 58 # https://docs.vagrantup.com/v2/push/atlas.html for more information. 59 # config.push.define "atlas" do |push| 60 # push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME" 61 # end 62 63 # Enable provisioning with a shell script. Additional provisioners such as 64 # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the 65 # documentation for more information about their specific syntax and use. 66 config.vm.provision "shell", inline: <<-SHELLSC 67 function install { 68 echo installing $1 69 shift 70 apt-get -y install "$@" >/dev/null 2>&1 71 } 72 73 echo updating package information 74 apt-add-repository -y ppa:brightbox/ruby-ng >/dev/null 2>&1 75 apt-get -y update >/dev/null 2>&1 76 77 install 'development tools' build-essential 78 79 install Ruby ruby2.3 ruby2.3-dev 80 update-alternatives --set ruby /usr/bin/ruby2.3 >/dev/null 2>&1 81 update-alternatives --set gem /usr/bin/gem2.3 >/dev/null 2>&1 82 echo installing Bundler 83 echo "gem: --no-ri --no-rdoc" > ~/.gemrc 84 gem install bundler -N >/dev/null 2>&1 85 install Git git 86 install SQLite sqlite3 libsqlite3-dev 87 install 'Nokogiri dependencies' libxml2 libxml2-dev libxslt1-dev zlib1g-dev 88 install 'ExecJS runtime' nodejs 89 echo 'Installing rails' 90 gem install rails -v '5.1.5' 91 gem install railties 92 gem install listen 93 gem install puma 94 gem install sass 95 gem install tilt 96 gem install spring 97 gem install byebug 98 gem install chromedriver-helper 99 gem install sqlite3 100 update-locale LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8 LC_ALL=en_US.UTF-8 101 echo 'You are now on Rails!' 102 echo ' o o o o o o o . . . ______________________________ _____=======_||____' 103 echo ' o _____ | | | |' 104 echo ' .][__n_n_|DD[ ====_____ | | | |' 105 echo ' >(________|__|_[_________]_|____________________________|_|_________________|' 106 echo ' _/oo OOOOO oo` ooo ooo `o!o!o o!o!o` `o!o o!o` ' 107 echo ' -+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-' 108 SHELLSC 109end 110

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答2

0

自己解決

rails new から作り直すことで解決しました。

投稿2019/06/04 01:57

Gr.

総合スコア89

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

/etc/network/interfacesの中にgatewayとdns-nameserversが書かれていないのですが、このこととUbuntuで名前解決ができないことは関係ありそうですか?

関係ありません。手元の環境で試したところ、vagrant up時にresolv.confが自動生成されました。

$ route -nの結果にeth0が2つ出ていますが、これは問題ないですか?

問題ありません。0.0.0.0宛(デフォルトゲートウェイ)と10.0.2.0/24宛がeth0のインタフェースから出るよということが記載されています。

手元の環境ではresolv.confを削除してもvagrant reloadで再作成されました。
vagrant reloadを試してみてください。

追記

ホストOS側のnslookupコマンドでIPv6のDNSサーバを参照されていましたが、こちらは想定通りですか?
ホストOS側でIPv6を使用していないのであれば、ホストOSでIPv6を無効にすることでうまくいくかもしれません。

投稿2019/02/14 07:25

編集2019/02/14 07:27
ozwind918

総合スコア1140

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

Gr.

2019/02/14 07:56

ozwind918さん 回答ありがとうございます。 > 0.0.0.0宛(デフォルトゲートウェイ)と10.0.2.0/24宛がeth0のインタフェースから出るよということ eth0が2つ出るのはこういうわけなんですね。 > ホストOSでIPv6を無効にすることでうまくいくかもしれません これはwindowsのコントロールパネルからネットワーク接続へ進んで、VirtualBox Host-Only Network #4のプロパティをいじるので良いでしょうか? 無効化してみましたが変化ありませんでした。 vagrant reload をしましたがやはり変わりませんでした。 改めて $ cat /etc/resolv.conf しても結果は同じでした。 よくわかりませんが、wi-fiのIPv6も無効にしてIPv6の接続性をテストしてみたら、「IPv6 アドレスが検出されませんでした」という結果が出ました。 同じ接続テストで「あなたの DNS サーバ (おそらくお使いのプロバイダが運用) は、IPv6 インターネットアクセスがあるように思われます。」と出ているのですが、無効にできていないということでしょうか?
ozwind918

2019/02/14 08:02

vagrant reloadしても駄目でしたか。 wifiのIPv6を無効にした状態で、Windowsのコマンドプロンプトでipconfigとping 8.8.8.8、nslookup www.google.co.jp などを実施するとどうでしょうか。
Gr.

2019/02/14 08:09

ozwind918さん 以下、wifiのIPv6を無効にした状態で入力しました。 >ipconfig Windows IP 構成 イーサネット アダプター VirtualBox Host-Only Network #4: 接続固有の DNS サフィックス . . . . .: IPv4 アドレス . . . . . . . . . . . .: 192.168.33.1 サブネット マスク . . . . . . . . . .: 255.255.255.0 デフォルト ゲートウェイ . . . . . . .: Wireless LAN adapter ローカル エリア接続* 1: メディアの状態. . . . . . . . . . . .: メディアは接続されていません 接続固有の DNS サフィックス . . . . .: Wireless LAN adapter ローカル エリア接続* 2: メディアの状態. . . . . . . . . . . .: メディアは接続されていません 接続固有の DNS サフィックス . . . . .: Wireless LAN adapter Wi-Fi: 接続固有の DNS サフィックス . . . . .: IPv4 アドレス . . . . . . . . . . . .: 192.168.11.15 サブネット マスク . . . . . . . . . .: 255.255.255.0 デフォルト ゲートウェイ . . . . . . .: 192.168.11.1 イーサネット アダプター Bluetooth ネットワーク接続: メディアの状態. . . . . . . . . . . .: メディアは接続されていません 接続固有の DNS サフィックス . . . . .: >ping 8.8.8.8 8.8.8.8 に ping を送信しています 32 バイトのデータ: 8.8.8.8 からの応答: バイト数 =32 時間 =17ms TTL=120 8.8.8.8 からの応答: バイト数 =32 時間 =5ms TTL=120 8.8.8.8 からの応答: バイト数 =32 時間 =13ms TTL=120 8.8.8.8 からの応答: バイト数 =32 時間 =8ms TTL=120 8.8.8.8 の ping 統計: パケット数: 送信 = 4、受信 = 4、損失 = 0 (0% の損失)、 ラウンド トリップの概算時間 (ミリ秒): 最小 = 5ms、最大 = 17ms、平均 = 10ms >nslookup www.google.co.jp サーバー: buffalo.setup Address: 192.168.11.1 権限のない回答: 名前: www.google.co.jp Address: 172.217.24.131 ご助力いただき本当に感謝いたします。
ozwind918

2019/02/14 08:16

このままの状態でvagrant reloadしてみたらどうなりますか?
Gr.

2019/02/14 08:35

ozwind918さん このままの状態でvagrant reloadしてみましたが、これまで試した各コマンドを打っても特に変化はありませんでした。 上の >ipconfig で見られる イーサネット アダプター VirtualBox Host-Only Network #4: の デフォルト ゲートウェイ が空欄なのですが、今少し調べたところ、「デフォルトゲートウェイが表示されていないとIPアドレスが正常に取得できていません。」的なことが書かれていたのでもっと深く調べてみますが、質問への回答と同様にこれも関係ないのでしょうか?
Gr.

2019/02/14 08:42

ozwind918さん すみません。そこはやはり問題ではなさそうでした。
ozwind918

2019/02/14 09:03

vagrantfileを質問文に追記していただけますか?
Gr.

2019/02/14 09:16

ozwind918さん vagrantfileを追記しました。
ozwind918

2019/02/14 09:29 編集

vagrantfileにも特に問題は見当たりません。 このvagrantfileを使用して別ディレクトリで仮想マシンを作成すると現在の仮想マシンと 同じ状況になるか確認してみてはどうでしょうか。 その際はconfig.vm.network "forwarded_port"とconfig.vm.network "private_network"の設定を既存のものと変えてください。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問