読者です 読者をやめる 読者になる 読者になる

cloverrose's blog

Python, Machine learning, Emacs, CI/CD, Webアプリなど

Vagrantで作ったサーバの/etc/network/interfacesはいじるとダメ?

Vagrant

注意:この記事は完全に僕のメモ用途としての意味合いが強いです。



Vagrantのpublic_networkで嵌ってる時(Vagrantのpublic_networkで嵌まる → forwarded_portを使って解決! - cloverrose's blog)にeth0とeth1を入れ替えるために、/etc/udev/rules.d/70-persistent-net.rulesをいじりましたが、それとは別に/etc/network/interfacesをいじったりもしました。そして/etc/network/interfacesをいじったらいろいろエラーが出たのでメモしておきます。

いじる前の/etc/network/interfaces
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp
auto eth1
iface eth1 inet static
      address 192.168.0.100
      netmask 255.255.255.0

いじり1

いじり1をした後の/etc/network/interfaces
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
      address 192.168.0.100
      netmask 255.255.255.0

auto eth1
iface eth1 inet dhcp
vagrant upでのエラー
$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
[default] Clearing any previously set forwarded ports...
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Specific bridge 'eth0' not found. You may be asked to specify
which network to bridge to.
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] Booting VM...
[default] Waiting for machine to boot. This may take a few minutes...
[default] Machine booted and ready!
[default] Configuring and enabling network interfaces...
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

/sbin/ifup eth1

Stdout from the command:



Stderr from the command:

stdin: is not a tty
/etc/network/interfaces:14: interface eth1 declared allow-auto twice
/sbin/ifup: couldn't read interfaces file "/etc/network/interfaces"
/etc/network/interfacesが書き換わっている!

vagrant sshして/etc/network/interfacesを見てみるといじり1をした後の内容と変わっていた!!

auto lo
iface lo inet loopback

auto eth1
iface eth1 inet dhcp
auto eth1
iface eth1 inet static
      address 192.168.0.100
      netmask 255.255.255.0
ifconfig

ifconfigするともともとeth0だったMACアドレスにもともとeth1だったIPアドレスが割り振られ、eth0とloだけになってeth1は無くなっていた。これは怪しい

いじり2

いじり2をした後の/etc/network/interfaces
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
      address 192.168.0.100
      netmask 255.255.255.0

auto eth1
iface eth1 inet static
      address x.y.z.w
      netmask 255.255.255.0
vagrant upでのエラー
$ vagrant up
[default] Attempting graceful shutdown of VM...
Bringing machine 'default' up with 'virtualbox' provider...
[default] Clearing any previously set forwarded ports...
[default] Creating shared folders metadata...
[default] Clearing any previously set network interfaces...
[default] Specific bridge 'eth0' not found. You may be asked to specify
which network to bridge to.
[default] Preparing network interfaces based on configuration...
[default] Forwarding ports...
[default] -- 22 => 2222 (adapter 1)
[default] Booting VM...
[default] Waiting for machine to boot. This may take a few minutes...
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.ssh.timeout" value) time period. This can
mean a number of things.

If you're using a custom box, make sure that networking is properly
working and you're able to connect to the machine. It is a common
problem that networking isn't setup properly in these boxes.
Verify that authentication configurations are also setup properly,
as well.

If the box appears to be booting properly, you may want to increase
the timeout ("config.ssh.timeout") value.
vagrant sshでのエラー
$ vagrant ssh
ssh_exchange_identification: read: Connection reset by peer

まとめ

このような感じでVagrantで作ったサーバの/etc/network/interfacesはいじらない方がいいように感じました。
自分がネットワーク周りに詳しくないため、/etc/network/interfacesをいじった時にやらないといけない何かをやり忘れている可能性も大きそうですが