summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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