]> gitweb.fluxo.info Git - kvmx.git/commitdiff
Enhance net_dns behavior
authorSilvio Rhatto <rhatto@riseup.net>
Wed, 13 Jun 2018 21:00:42 +0000 (18:00 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Wed, 13 Jun 2018 21:00:42 +0000 (18:00 -0300)
kvmx
kvmx-create
kvmxfile

diff --git a/kvmx b/kvmx
index 70de3338700bf3e71410db788bbdfd4ffdcde482..9575ef9fbb066230769c39b60e92e397015c74e8 100755 (executable)
--- a/kvmx
+++ b/kvmx
@@ -416,6 +416,10 @@ function kvmx_up {
     net_opts="tap,ifname=$tap,script=no,downscript=no,vlan=0,name=hostnet0 -device virtio-net-pci,vlan=0,id=net0,mac=$mac_address,bus=pci.0"
   fi
 
+  if [ ! -z "$net_dns" ] && [ "$net_dns" != "host" ]; then
+    net_opts="$net_opts,dns=$net_dns"
+  fi
+
   if [ -z "$spice" ] || [ "$spice" == "1" ]; then
     spice_opts="-spice port=$PORT,addr=127.0.0.1,disable-ticketing,streaming-video=off,jpeg-wan-compression=never,playback-compression=off,zlib-glz-wan-compression=never,image-compression=off"
     spice_opts="$spice_opts -device virtio-serial-pci"
index a908663159b13f8c5c5718c66e33fef24e60ffcf..56b08b6d8fc362fbd43463032a92a89cc8f39370 100755 (executable)
@@ -364,10 +364,7 @@ EOF
 
 # Second stage procedure
 function __kvmx_create_custom_second_stage {
-  if [ ! -z "$net_ip" ] && [ ! -z "$net_mask" ] && [ ! -z "$net_gateway" ] && [ -z "$net_dns" ]; then
-    # DNS config
-    echo "nameserver $net_dns" > $WORK/etc/resolv.conf
-
+  if [ ! -z "$net_ip" ] && [ ! -z "$net_mask" ] && [ ! -z "$net_gateway" ]; then
     # Networking: eth0
     cat <<-EOF | $SUDO tee $WORK/etc/network/interfaces.d/eth0 > /dev/null
 auto eth0
@@ -403,6 +400,15 @@ iface ens3 inet dhcp
 EOF
   fi
 
+  # DNS config
+  if [ ! -z "$net_dns" ]; then
+    if [ "$net_dns" == "host" ]; then
+      cp /etc/resolv.conf $WORK/etc/resolv.conf
+    else
+      echo "nameserver $net_dns" > $WORK/etc/resolv.conf
+    fi
+  fi
+
   # Locale
   $APT_INSTALL locales
   echo "LANG=$LANG"  | $SUDO tee    $WORK/etc/default/locale > /dev/null
index 3247505e32abc5ed400b85e2f1f2dcd3b9002736..a15a1fb21508a53f87beb4d3898d8db31b760264 100644 (file)
--- a/kvmxfile
+++ b/kvmxfile
@@ -15,12 +15,15 @@ password="`head -c 20 /dev/urandom | base64`"
 #net="tap"
 net="user"
 
+# DNS config
+#net_dns="192.168.1.1"
+#net_dns="host" # copy /etc/resolv.conf from host when creating the box
+
 # Networking: tap config only
 # This setting is used during virtual machine bootstrapping by kvmx-create.
 #net_ip="10.1.1.2"
 #net_mask="255.255.255.0"
 #net_gateway="10.1.1.1"
-#net_dns="192.168.1.1"
 
 # Set this is you want to be able to share a single folder between host and guest.
 # Needs ssh_support set to "y" and a workable SSH connection to the guest.