summaryrefslogtreecommitdiff
path: root/dhcp-server.sh
diff options
context:
space:
mode:
authorCody Hiar <codyfh@gmail.com>2018-05-12 18:50:17 -0600
committerCody Hiar <codyfh@gmail.com>2018-05-12 18:50:17 -0600
commit58a1a961d79991641be5b9c3ccec2ef750085d8d (patch)
tree30f3b29cb92110ee0b391a8ea5e8203dcd465ec9 /dhcp-server.sh
Initial commit
Diffstat (limited to 'dhcp-server.sh')
-rwxr-xr-xdhcp-server.sh33
1 files changed, 33 insertions, 0 deletions
diff --git a/dhcp-server.sh b/dhcp-server.sh
new file mode 100755
index 0000000..7a84d23
--- /dev/null
+++ b/dhcp-server.sh
@@ -0,0 +1,33 @@
+#!/bin/bash
+# Turn ethernet cable into DHCP device
+set -xeuo pipefail
+
+DEVICE='ens9'
+INTERNET='wlp3s0'
+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
+
+echo 'Allowing ip forwarding/enabling Nat'
+sysctl net.ipv4.ip_forward=1
+iptables -t nat -A POSTROUTING -o "$INTERNET" -j MASQUERADE
+iptables -A FORWARD -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
+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 subnet-mask 255.255.255.0;
+option routers 192.168.123.100;
+subnet 192.168.123.0 netmask 255.255.255.0 {
+ range 192.168.123.150 192.168.123.250;
+}
+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
+dhcpd $DEVICE