여기 한 가지 방법이 있습니다. Vagrantfile
은 Ruby 스크립트이므로 로컬 호스트 이름과 IP 주소를 찾기 위해 약간의 로직을 사용할 수 있습니다. 그런 다음이를 간단한 프로비저닝 스크립트에서 사용하여 게스트 /etc/hosts
파일에 추가합니다.
예 Vargrantfile
:
# -*- mode: ruby -*-
# vi: set ft=ruby :
# test setting the host IP address into the guest /etc/hosts
# determine host IP address - may need some other magic here
# (ref: http://stackoverflow.com/questions/5029427/ruby-get-local-ip-nix)
require 'socket'
def my_first_private_ipv4
Socket.ip_address_list.detect{|intf| intf.ipv4_private?}
end
ip = my_first_private_ipv4.ip_address()
# determine host name - may need some other magic here
hostname = `hostname`
script = <<SCRIPT
echo "#{ip} #{hostname}" | tee -a /etc/hosts
SCRIPT
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "hashicorp/precise64"
config.vm.hostname = "iptest"
config.vm.provision :shell, :inline => script
config.vm.provider "virtualbox" do |vb|
# vb.gui = true
vb.name = "iptest"
vb.customize ["modifyvm", :id, "--memory", "1000"]
end
end
주 : 추가 유지합니다 /etc/hosts
에 부가 echo | tee -a
명령 경우 (VM을 파괴하지 않고) 프로비저닝 여러 번. 거기에 더 나은 솔루션이 필요할 수도 있습니다.