summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCody Hiar <codyfh@gmail.com>2018-05-12 19:31:38 -0600
committerCody Hiar <codyfh@gmail.com>2018-05-12 19:31:38 -0600
commit7910823bd48800dfa4903fd0047f09255cae04ad (patch)
treeb9e4f4ac99fb8466ef7382bc2d228ea1b4ab9fa4
parent58a1a961d79991641be5b9c3ccec2ef750085d8d (diff)
Making dhcp script repeatable
-rwxr-xr-xdhcp-server.sh9
1 files changed, 7 insertions, 2 deletions
diff --git a/dhcp-server.sh b/dhcp-server.sh
index 7a84d23..ac4b75c 100755
--- a/dhcp-server.sh
+++ b/dhcp-server.sh
@@ -9,7 +9,11 @@ ROUTERIP='192.168.123.1'
echo 'Restarting Device'
ip link set "$DEVICE" down
ip link set "$DEVICE" up
-ip addr add "$ROUTERIP"/24 dev "$DEVICE" # arbitrary address
+# Check if ip already assigned
+IP_ASSIGNED=$(ip a | grep -A 5 ens9 | grep 192.168.123.1)
+if [ -z "$IP_ASSIGNED" ]; then
+ ip addr add "$ROUTERIP"/24 dev "$DEVICE" # arbitrary address
+fi
echo 'Allowing ip forwarding/enabling Nat'
sysctl net.ipv4.ip_forward=1
@@ -20,7 +24,7 @@ iptables -A FORWARD -i "$DEVICE" -o "$INTERNET" -j ACCEPT
echo 'Creating /etc/dhcpd.conf file'
#Config file: /etc/dhcpd.conf
cat > /etc/dhcpd.conf <<- EOM
-option domain-name-servers 1.1.1.1, 1.0.0.1;
+option domain-name-servers 8.8.8.8, 8.8.4.4;
option subnet-mask 255.255.255.0;
option routers 192.168.123.100;
subnet 192.168.123.0 netmask 255.255.255.0 {
@@ -30,4 +34,5 @@ EOM
#Database file: /var/lib/dhcp/dhcpd.leases
# cat this to see if a device has been assigned a lease
#PID file: /var/run/dhcpd.pid
+pkill dhcpd || true
dhcpd $DEVICE