With dnsmasq as the dns server, I can use tap_ip as the nameserver. The boottime back to normal. I create two scripts to setup the network. setup_iptable.sh sets the ip table. setup_dnsmasq configures dnsmasq and start it. After running these two scripts, I can run firecracker.py with only -n. I'm not familiar with sending patch through email with git. I include the patch below.
From bbc12eb31878bdacaf20313be444ac71f9ff6578 Mon Sep 17 00:00:00 2001
From: Zhiting Zhu <
zhit...@cs.utexas.edu>
Date: Wed, 9 Oct 2019 00:32:35 -0500
Subject: [PATCH] scripts to setup dnsmasq and NAT
Signed-off-by: Zhiting Zhu <
zhit...@cs.utexas.edu>
---
scripts/delete_dnsmasq_setting.sh | 6 ++++++
scripts/restore_iptable.sh | 5 +++++
scripts/setup_dnsmasq.sh | 20 ++++++++++++++++++++
scripts/setup_iptable.sh | 8 ++++++++
4 files changed, 39 insertions(+)
create mode 100755 scripts/delete_dnsmasq_setting.sh
create mode 100755 scripts/restore_iptable.sh
create mode 100755 scripts/setup_dnsmasq.sh
create mode 100755 scripts/setup_iptable.sh
diff --git a/scripts/delete_dnsmasq_setting.sh b/scripts/delete_dnsmasq_setting.sh
new file mode 100755
index 00000000..aa9c3c15
--- /dev/null
+++ b/scripts/delete_dnsmasq_setting.sh
@@ -0,0 +1,6 @@
+if [ "$#" -ne 1 ]; then
+ echo "Need to specify interface name"
+fi
+DEV=$1
+sudo rm -rf /var/lib/dnsmasq/$DEV
+sudo rm -rf /etc/dnsmasq.d/$DEV.conf
diff --git a/scripts/restore_iptable.sh b/scripts/restore_iptable.sh
new file mode 100755
index 00000000..e882948a
--- /dev/null
+++ b/scripts/restore_iptable.sh
@@ -0,0 +1,5 @@
+if [ -f iptables.rules.old ]; then
+ sudo iptables-restore < iptables.rules.old
+ rm iptables.rules.old
+fi
+sudo sh -c "echo 0 > /proc/sys/net/ipv4/ip_forward"
diff --git a/scripts/setup_dnsmasq.sh b/scripts/setup_dnsmasq.sh
new file mode 100755
index 00000000..b93c88df
--- /dev/null
+++ b/scripts/setup_dnsmasq.sh
@@ -0,0 +1,20 @@
+if [ "$#" -ne 1 ]; then
+ echo "need to specify the interface name"
+fi
+DEV=$1
+sudo mkdir -p /var/lib/dnsmasq/$DEV
+sudo touch /var/lib/dnsmasq/$DEV/hostsfile
+sudo touch /var/lib/dnsmasq/$DEV/leases
+sudo touch /var/lib/dnsmasq/$DEV/dnsmasq.conf
+sudo sh -c "cat << 'EOF' >/var/lib/dnsmasq/$DEV/dnsmasq.conf
+except-interface=lo
+interface=$DEV
+bind-dynamic
+strict-order
+EOF"
+sudo mkdir -p /etc/dnsmasq.d/
+sudo touch /etc/dnsmasq.d/$DEV.conf
+sudo bash -c "echo "except-interface=$DEV" >> /etc/dnsmasq.d/$DEV.conf"
+sudo bash -c "echo "bind-interfaces" >> /etc/dnsmasq.d/$DEV.conf"
+sudo mkdir -p /var/run/dnsmasq/
+sudo dnsmasq --conf-file=/var/lib/dnsmasq/$DEV/dnsmasq.conf --pid-file=/var/run/dnsmasq/$DEV.pid
diff --git a/scripts/setup_iptable.sh b/scripts/setup_iptable.sh
new file mode 100755
index 00000000..ce638b7b
--- /dev/null
+++ b/scripts/setup_iptable.sh
@@ -0,0 +1,8 @@
+INTERFACE=enp7s3
+sudo iptables-save > iptables.rules.old
+sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
+sudo iptables -t nat -A POSTROUTING -o $INTERFACE -j MASQUERADE
+sudo iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
+sudo iptables -A FORWARD -i fc_tap0 -o $INTERFACE -j ACCEPT
+sudo iptables -A INPUT -i fc_tap0 -p udp -m udp -m multiport --dports 53 -j ACCEPT
+sudo iptables -A INPUT -i fc_tap0 -p tcp -m tcp -m multiport --dports 53 -j ACCEPT
--
2.17.1