Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/abbbi/vagrant-libvirt-dns
How to manage DNS in your vagrant environment the libvirt way
https://github.com/abbbi/vagrant-libvirt-dns
dhcp dhcp-server dns dnsmasq documentation libvirt manual vagrant
Last synced: 25 days ago
JSON representation
How to manage DNS in your vagrant environment the libvirt way
- Host: GitHub
- URL: https://github.com/abbbi/vagrant-libvirt-dns
- Owner: abbbi
- Created: 2018-09-13T14:53:24.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-09-13T17:59:22.000Z (over 6 years ago)
- Last Synced: 2024-10-30T00:37:26.819Z (2 months ago)
- Topics: dhcp, dhcp-server, dns, dnsmasq, documentation, libvirt, manual, vagrant
- Homepage:
- Size: 16.6 KB
- Stars: 4
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
About
=========There are various ways to manage your vagrant machines hostnames and IP
addresses. Most of them require you to install additional vagrant plugins (
landrush, hostmanager, vagrant-dns)One of them is vagrant-landrush, which works nicely but has problems in multi
user environments (spinning up an DNS Service for each vagrant vm)This short manual should give you an easier way to setup DNS and DHCP
management of your Vagrant environment with libvirt backend.Goal
-------------The goal is to have a round robin style DNS and DHCP assignment for your
vagrant virtual machines. All machines should get an hostname from the dhcp
service and shall be resolvable forward and reverse from the host system aswell
as the other vagrant machines running.As example, lets say we have an dhcp range that goes from:
10.1.0.3 to 10.1.0.5
and want those ips to be associated with hostnames like:
```
sep003.mycloud.local -> 10.1.0.3
sep004.mycloud.local -> 10.1.0.4
sep005.mycloud.local -> 10.1.0.5
```These should match the ip given by the dhcp lease. The lease disappears as the
vagrant machine halts and can be re-used likewise by other machines.It should be possible doing this without the need of third party plugins just
by modifying our libvirt network configuration.Prerequisites
-------------Your vagrant boxes must honor DHCP's "hostname" option and allow to set the
systems hostname via DHCP client for better integration.Configuring Libvirt
-------------Define a new libvirt network from the provided example using:
```
virsh net-define examplenet.xml
```Note: you may have to assign a special bridge name in the config file to
avaoid libvirt re-using an existing one.```
```And start the network:
```
virsh net-start my_cloud
```This should spin up a new libvirt network with its according dnsmasq process:
```
$ ps axw | grep my_cloud
11714 ? S 0:00 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/my_cloud.conf --leasefile-ro --dhcp-script=/usr/lib/libvirt/libvirt_leaseshelper```
The example provides a lease range for three possible IP's and hostnames.
Spinning up vagrant box
-------------Now initialize a new Vagrant box (this example uses debian9):
```
vagrant init generic/debian9
```And edit your Vagantfile to contain the following section:
```
config.vm.provider :libvirt do |domain|
domain.management_network_name = "my_cloud"
domain.management_network_address = "10.1.0.0/24"
end
```Followed by:
```
vagrant up
```As the VM starts, it receives its dhcp lease and hostname from the dnsmasq
service:```
~$ virsh net-dhcp-leases my_cloud
Expiry Time MAC address Protocol IP address Hostname Client ID or DUID
-------------------------------------------------------------------------------------------------------------------
2018-09-13 18:10:58 52:54:00:02:7b:cb ipv4 10.1.0.4/24 sep004
```Getting into the box the hostname should have been set too:
```
~/mynet$ vagrant ssh
[..]
vagrant@sep004:~$
```As all boxes use the local dnsmasq dns server, other boxes can happily
forward and reverse lookup each other:```
~/mynet-2$ vagrant ssh
[..]
vagrant@sep003:~$ host sep004
sep004.mycloud.local has address 10.1.0.4
vagrant@sep003:~$ host 10.1.0.4
4.0.1.10.in-addr.arpa domain name pointer sep004.mycloud.local.
```Configuring the Hostsystem
-------------
In order to make the host system aware of the hostnames and domain you have to make
your system wide dnsmasq aware of the libvirt dnsmasq server. Place the provided example
file in:```
/etc/dnsmasq.d/my-cloud.local
```And reload your dnsmasq service. Now the hostsystem should be able to resolve your
vagrant boxes aswell:```
vagrantuser@hostsystem:~$ host sep003.mycloud.local
sep003.mycloud.local has address 10.1.0.3
```Freeing leases
-------------Leases are automatically freed as the vagrant box is halted:
```
:~/mynet$ vagrant halt
==> default: Halting domain...
~/mynet$ virsh net-dhcp-leases my_cloud
Expiry Time MAC address Protocol IP address Hostname Client ID or DUID
-------------------------------------------------------------------------------------------------------------------
2018-09-13 18:14:17 52:54:00:16:ee:ab ipv4 10.1.0.3/24 sep003 -
```