百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
V

vagrant-dns

> 编程语言
开源

一个用于管理 vagrant 环境 DNS 记录的插件

495 stars0 点赞0 次浏览
访问官网GitHub

工具介绍

一个用于管理 vagrant 环境 DNS 记录的插件

vagrant-dns

vagrant-dns allows you to configure a dns-server managing a development subdomain. It works much like pow, but manages Vagrant machines.

Installation

$ vagrant plugin install vagrant-dns

Attention: 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
end

NOTES: 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.

Issues

  • macOS and systemd-resolved enabled Linux only (please read: Platform Support before ranting about this).
  • A records only
  • No IPv6 support
  • Not automatically visible inside the box (special configuration of your guest system or provider needed)

Issues· 8 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Ruby

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言