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を見たところ、なぜかgateway
とdns-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
の中にgateway
とdns-nameservers
が書かれていないのですが、このこととUbuntuで名前解決ができないことは関係ありそうですか?
0. そうだった場合、/etc/network/interfaces
にgateway
とdns-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
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。