Fix #26. Just provide sample dnsmasq configuration

This commit is contained in:
Matt Churchyard
2015-11-09 09:18:37 +00:00
parent bc78126ccf
commit ad0425e7ce
4 changed files with 33 additions and 30 deletions

View File

@@ -28,7 +28,8 @@ If you want to run guests other than FreeBSD, you will need the grub2-bhyve pack
# pkg install grub2-bhyve
Additionally, NAT support is only available if you have dnsmasq installed.
Additionally, while not specifically required, dnsmasq can be used to provid DHCP services
when vm-bhyve is configured to run NAT.
# pkg install dnsmasq
@@ -106,9 +107,10 @@ side of the NAT network. Just enable NAT on the switch:
# vm switch nat public on
This will automatically create a private network on the switch, enable DHCP for it, and forward guest traffic
via your default gateway. Please note that NAT functionality requires the dnsmasq package to be installed,
and both dnsmasq & pf must be enabled in /etc/rc.conf. See the man page for more details.
This will automatically create a private network on the switch, and forward guest traffic
via your default gateway. Please note that pf must be enabled in /etc/rc.conf for NAT functionality to work.
Whilst not strictly required, dnsmasq can be used to provide DHCP services to guests on the NAT network.
vm-bhyve will generate a sample dnsmasq.conf file which can be installed for this purpose.
If you want guest traffic to be on a specific VLAN when leaving the host, specify a vlan number. To turn
off vlans, just set the vlan number to 0:

View File

@@ -350,12 +350,14 @@ __switch_nat(){
__err "pf needs to be enabled for nat functionality"
fi
if ! checkyesno dnsmasq_enable; then
__err "dnsmasq needs to be installed and enabled for nat functionality"
fi
sysrc -inqf "${vm_dir}/.config/switch" "nat_${_switch}=yes" >/dev/null 2>&1
[ $? -ne 0 ] && __err "failed to store nat configuration"
echo "******"
echo " NAT has been enabled on the specified switch"
echo " A sample dnsmasq configuration has been created in /usr/local/etc/dnsmasq.conf.bhyve"
echo " To enable DHCP on this switch, please install the dnsmasq confguration or merge with your existing."
echo "******"
;;
*)
__err "last option should either be 'on' or 'off' to enable/disable nat functionality"
@@ -384,14 +386,14 @@ __switch_nat_init(){
_gw=$(netstat -rn | grep default | awk '{print $4}')
# basic dnsmasq settings
echo "# vm-bhyve dhcp" > /usr/local/etc/dnsmasq.conf
echo "port=0" >> /usr/local/etc/dnsmasq.conf
echo "domain-needed" >> /usr/local/etc/dnsmasq.conf
echo "no-resolv" >> /usr/local/etc/dnsmasq.conf
echo "except-interface=lo0" >> /usr/local/etc/dnsmasq.conf
echo "bind-interfaces" >> /usr/local/etc/dnsmasq.conf
echo "local-service" >> /usr/local/etc/dnsmasq.conf
echo "dhcp-authoritative" >> /usr/local/etc/dnsmasq.conf
echo "# vm-bhyve dhcp" > /usr/local/etc/dnsmasq.conf.bhyve
echo "port=0" >> /usr/local/etc/dnsmasq.conf.bhyve
echo "domain-needed" >> /usr/local/etc/dnsmasq.conf.bhyve
echo "no-resolv" >> /usr/local/etc/dnsmasq.conf.bhyve
echo "except-interface=lo0" >> /usr/local/etc/dnsmasq.conf.bhyve
echo "bind-interfaces" >> /usr/local/etc/dnsmasq.conf.bhyve
echo "local-service" >> /usr/local/etc/dnsmasq.conf.bhyve
echo "dhcp-authoritative" >> /usr/local/etc/dnsmasq.conf.bhyve
# reset our pf config and create /etc/pf.conf if needed
echo "# vm-bhyve nat" > "${vm_dir}/.config/pf-nat.conf"
@@ -413,9 +415,9 @@ __switch_nat_init(){
_net24="172.16.${_bnum}"
echo "nat on ${_gw} from {${_net24}.0/24} to any -> (${_gw})" >> "${vm_dir}/.config/pf-nat.conf"
echo "" >> /usr/local/etc/dnsmasq.conf
echo "interface=${_id}" >> /usr/local/etc/dnsmasq.conf
echo "dhcp-range=${_net24}.10,${_net24}.254" >> /usr/local/etc/dnsmasq.conf
echo "" >> /usr/local/etc/dnsmasq.conf.bhyve
echo "interface=${_id}" >> /usr/local/etc/dnsmasq.conf.bhyve
echo "dhcp-range=${_net24}.10,${_net24}.254" >> /usr/local/etc/dnsmasq.conf.bhyve
# make sure interface has an ip
# this doesn't get removed when nat disabled but not a major issue
@@ -430,7 +432,6 @@ __switch_nat_init(){
# restart services regardless
# still need to restart if _havenat=0, in case we've just removed last nat switch
__restart_service "dnsmasq"
__restart_service "pf"
}

2
vm
View File

@@ -24,7 +24,7 @@
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
VERSION=0.9.7
VERSION=0.9.9
PATH=${PATH}:/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin
BSD_VERSION=$(uname -K)

18
vm.8
View File

@@ -308,11 +308,16 @@ To remove the VLAN configuration from a virtual switch, specify a
.Ar vlan-id
of 0.
.It Cm switch nat Ar name Ar on|off
Enable or disable NAT functionality on the specified switch. Both
Enable or disable NAT functionality on the specified switch. Please note that
.Xr pf
and
is required for this functionality and must be enabled in
.Pa /etc/rc.conf .
If DHCP is desired, please install the
.Xr dnsmasq
are required for this function to be available.
pacakge. vm-bhyve will generate a sample dnsmasq configuration in
.Pa /usr/local/etc/dnsmasq.conf.bhyve ,
but it is up to the user to either use this configuration directly, or merge with
any existing dnsmasq settings you have configured.
.Pp
The switch should have no host ports assigned, as these will end up on the private side
of the NAT network.
@@ -325,15 +330,10 @@ Once enabled, a 172.16.X.0/24 network is assigned to the switch (bridge) interfa
is chosen based on the ID of the bridge interface. For example, if the switch is using
bridge10, the network will be 172.16.10.0/24.
.Xr dnsmasq
is used to provide DHCP to the guests, and
can be used to provide DHCP to the guests, and
.Xr pf
rules are inserted to provide the NAT translation.
.Pp
Please note that
.Nm
will overwrite the dnsmasq configuration file
.Pa /usr/local/etc/dnsmasq.conf
as it creates a specific configuration to provide DHCP on each switch interface.
.Pa /etc/pf.conf
is created if it doesn't exist, and a single include statement is added. This
include statement can be moved within the file if required.