LoginSignup
0
2

More than 5 years have passed since last update.

自前 vagrant box で作成した VM のネットワークがつながらない

Last updated at Posted at 2017-06-30

環境

Mac

コマンド 出力
uname -a Darwin xxx-MacBook-Pro.local 16.6.0 Darwin Kernel Version 16.6.0: Fri Apr 14 16:21:16 PDT 2017; root:xnu-3789.60.24~6/RELEASE_X86_64 x86_64
vagrant -v Vagrant 1.9.3
VirtualBox --help Oracle VM VirtualBox Manager 5.1.22
vagrant plugin list vagrant-share (1.1.7)
vagrant-vbguest (0.14.2)

VM

コマンド 出力
cat /etc/redhat-release CentOS release 6.5 (Final)
uname -a Linux xxx 2.6.32-696.el6.x86_64 #1 SMP Tue Mar 21 19:29:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

Vagrantfile

$ cat ./Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
  config.vm.box = "xxx.box"
  config.vm.define :xxx do |app|
    app.vm.hostname = 'xxx'
    app.vm.network 'private_network', ip: '192.168.33.52'
    app.vm.network 'public_network', bridge: 'en0: air Wi-Fi (AirPort)'
  end
  config.vm.provider :virtualbox do |v|
    v.customize ['modifyvm', :id, '--memory', 1024]
  end
end

問題

vagrant のリロード(起動)をすると、下記のようなエラーメッセージが出ます。

$ vagrant reload
==> xxx: Attempting graceful shutdown of VM...
==> xxx: Clearing any previously set forwarded ports...
==> xxx: Clearing any previously set network interfaces...
==> xxx: Preparing network interfaces based on configuration...
    xxx: Adapter 1: nat
    xxx: Adapter 2: hostonly
    xxx: Adapter 3: bridged
==> xxx: Forwarding ports...
    xxx: 22 (guest) => 2222 (host) (adapter 1)
==> xxx: Running 'pre-boot' VM customizations...
==> xxx: Booting VM...
==> xxx: Waiting for machine to boot. This may take a few minutes...
    xxx: SSH address: 127.0.0.1:2222
    xxx: SSH username: vagrant
    xxx: SSH auth method: private key
    xxx: Warning: Remote connection disconnect. Retrying...
==> xxx: Machine booted and ready!
[xxx] GuestAdditions 5.1.22 running --- OK.
==> xxx: Checking for guest additions in VM...
==> xxx: Setting hostname...
==> xxx: Configuring and enabling network interfaces...
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

# Down the interface before munging the config file. This might
# fail if the interface is not actually set up yet so ignore
# errors.
/sbin/ifdown 'eth1'
# Move new config into place
mv -f '/tmp/vagrant-network-entry-eth1-1498836932-0' '/etc/sysconfig/network-scripts/ifcfg-eth1'
# attempt to force network manager to reload configurations
nmcli c reload || true

# Down the interface before munging the config file. This might
# fail if the interface is not actually set up yet so ignore
# errors.
/sbin/ifdown 'eth2'
# Move new config into place
mv -f '/tmp/vagrant-network-entry-eth2-1498836932-1' '/etc/sysconfig/network-scripts/ifcfg-eth2'
# attempt to force network manager to reload configurations
nmcli c reload || true

# Restart network
service network restart


Stdout from the command:

Shutting down interface eth0:  [  OK  ]
Shutting down loopback interface:  [  OK  ]
Bringing up loopback interface:  [  OK  ]
Bringing up interface eth0:
Determining IP information for eth0... done.
[  OK  ]
Bringing up interface eth1:  Determining if ip address 192.168.33.52 is already in use for device eth1...
[  OK  ]
Bringing up interface eth2:
Determining IP information for eth2... done.
[  OK  ]
Bringing up interface eth3:  Device eth3 does not seem to be present, delaying initialization.
[FAILED]
Bringing up interface eth4:  Device eth4 does not seem to be present, delaying initialization.
[FAILED]


Stderr from the command:

bash: line 11: nmcli: command not found
bash: line 20: nmcli: command not found

対策を講じる

問題点は、起動できないネットワークがあることなので、エラーの出ているネットワークを確認します。

$ sudo service network restart

起動失敗だと言われた ethX の設定ファイルを確認します。物は下記の場所にあります。
ethXX には数字が入ります。

$ ls -la /etc/sysconfig/network-scripts/ifcfg-*
-rw-r--r-- 1 root    root    197 Jun 30 14:52 /etc/sysconfig/network-scripts/ifcfg-eth0
-rw------- 1 vagrant vagrant 213 Jun 30 17:44 /etc/sysconfig/network-scripts/ifcfg-eth1
-rw------- 1 vagrant vagrant 142 Jun 30 17:44 /etc/sysconfig/network-scripts/ifcfg-eth2
-rw-r--r-- 1 root    root    254 Jun 30 14:52 /etc/sysconfig/network-scripts/ifcfg-lo

で、中身を確認し、想定どおりでないものをどうにかします。
おそらく、vagrant box のパッケージ元のイメージの設定と vagrant box を使用して作った VM の設定がごっちゃになっているのかなと言う気がします。
なので、重複が発生していたりする場合は、設定ファイルを削除(退避)してあげましょう。

で、下記コマンドを実行します。

$ sudo service network restart

エラーが出なくなったら、下記コマンドでネットワークの設定がちゃんと生きているか確認します。

$ ifconifg

ここで、想定のものが出力されなければ、別の問題があると思われます。


エラーメッセージの一行目の下記の文章を検索するといくつか記事が出てきます。

The following SSH command responded with a non-zero exit status.

/etc/udev/rules.d/70-persistent-net.rules を削除するなり、/dev/null のシンボリックリンクにしてしまうなりが必要かもしれません。

まとめ

vagrant box を元に作成した VM では、ネットワークの問題が発生することがよくあるような気がします。
ネットワークの設定がどこにあって、何によって読み込まれてるのかくらいがわかれば、ひとまず自力での調査ができそうです。

あと、vagrant up (reload) で出力されるエラーに惑わされちゃいかんなって思います。
別の記事でも書かれてましたが、「vagrant を使っている中で出る問題に関して、VM の問題なのか、vagrant の問題なのかちゃんと切り分ける」ことが非常に重要そうです。
判別の方法はよくわからないですが、、、

ホントはちゃんと勉強せんといかんのだろうなと思いつつ、とりあえずの突貫対応が必要な場合もあります。

0
2
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
0
2