一个用于管理 vagrant 环境 DNS 记录的插件
vagrant-dns allows you to configure a dns-server managing a development subdomain. It works much like pow, but manages Vagrant machines.
$ vagrant plugin install vagrant-dnsAttention: As of v2.0.0, vagrant-dns requires vagrant >= 1.9.6 (because it ships with a more modern version of ruby)
If you get an error like rubydns requires Ruby version >= 2.2.6. while installing, you probably need to upgrade vagrant.
Alternatively, you can install an older version of vagrant-dns like this: `vagrant plugin install --plugin-version=" 33.33.33.60
/^.*myothersite.test$/ => 33.33.33.60
Where the first part of each line is a [regular expression](https://ruby-doc.org/core-2.3.0/Regexp.html) and the second part is the mapped IPv4. (` => ` is just a separator)
## Multi VM config
We can use [multivm](https://www.vagrantup.com/docs/multi-machine/) configuration and have dns names for host.
* Use below given vagrant config
```ruby
BOX_IMAGE = "ubuntu/xenial64"
WORKER_COUNT = 2
Vagrant.configure("2") do |config|
(1..WORKER_COUNT).each do |i|
config.vm.define "worker#{i}" do |subconfig|
subconfig.dns.tld = "test"
subconfig.vm.hostname = "vagrant"
subconfig.dns.patterns = "worker#{i}.mysite.test"
subconfig.vm.box = BOX_IMAGE
subconfig.vm.network "private_network", ip: "10.240.0.#{i+15}"
end
end
end
…
ruby
Vagrant.configure(2) do |config|
# ...
config.vm.provider "virtualbox" do |vm_config, override|
vm_config.customize [
"modifyvm", :id,
"--natdnshostresolver1", "on",
# some systems also need this:
# "--natdnshostresolver2", "on"
]
end
end
…
ruby
Vagrant.configure("2") do |config|
# ...
# - `vm` is the vagrant virtual machine instance and can be used to communicate with it
# - `opts` is the vagrant-dns options hash (everything configured via `config.dns.*`)
config.dns.ip = -> (vm, opts) do
# note: the block handed to `execute` might get called multiple times, hence this closure
ip = nil
vm.communicate.execute("hostname -I | cut -d ' ' -f 1") do |type, data|
ip = data.strip if type == :stdout
end
ip
end
endNOTES: In order to obtain the IP in this way, the vagrant box needs to be up and running. You will get a log output (Postponing running user provided IP script until box has started.) when you try to run vagrant dns on a non-running box.
A records only暂无开放 Issues,或尚未同步最近议题。