From 24b72b570459da37dd40d5f1dce3e96295a418af Mon Sep 17 00:00:00 2001 From: RealStickman Date: Fri, 20 May 2022 21:19:06 +0200 Subject: [PATCH] (Grav GitSync) Automatic Commit from RealStickman --- .../15.dhcp-server-and-routing/default.en.md | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) create mode 100644 pages/02.linux/15.dhcp-server-and-routing/default.en.md diff --git a/pages/02.linux/15.dhcp-server-and-routing/default.en.md b/pages/02.linux/15.dhcp-server-and-routing/default.en.md new file mode 100644 index 0000000..f8ef699 --- /dev/null +++ b/pages/02.linux/15.dhcp-server-and-routing/default.en.md @@ -0,0 +1,94 @@ +--- +title: 'DHCP Server and Routing' +--- + +## Installation +`# apt install isc-dhcp-server` + +## Configuration +Edit `/etc/default/isc-dhcp-server` +`INTERFACESv4="(interface 1) (interface 2)"` + +Edit `/etc/dhcp/dhcpd.conf` to set a subnet +``` +subnet (netaddress) netmask (subnetmask) { + range (first dhcp) (last dhcp); + option subnet-mask (subnetmask); + option routers (gateway); + option domain-name "(name)"; + option domain-name-servers (dns server); +} +``` + +Edit `/etc/network/interfaces` +``` +auto (interface) +iface (interface) inet static + address (address) + network (netaddress) + netmask (netmask) + broadcast (broadcast) +``` + +Enable the interface +`# ifup (interface)` + +Restart DHCP Server +`# systemctl restart isc-dhcp-server.service` + +### Enable routing +`# echo "net.ipv4.ip_forward=1" >> /etc/sysctl.d/80-forwarding.conf` +`# sysctl -p /etc/sysctl.d/80-forwarding.conf` + +`# iptables -t nat -A POSTROUTING -o (WAN interface) -j MASQUERADE` +`# iptables -A FORWARD -i (LAN interface) -j ACCEPT` + +Make iptables permanent +Select `Yes` during the installation to save current rules +`# apt install iptables-persistent` + +### Enable DHCP-managed fixed IP address +``` +host (hostname) { + hardware ethernet (mac); + fixed-address (ip address); +} +``` + +### Dynamic DNS +*Needs a supported DNS like BIND or PowerDNS* +[Configure your DNS server to accept updates](https://wiki.realstickman.net/e/en/linux/services/powerdns) +Add the following snippet to your `/etc/dhcp/dhcpd.conf` file +How to generate the key is also described in the DNS article +``` + +ddns-updates on; +ddns-update-style interim; +update-static-leases on; + +ddns-domainname "testpdns"; +ddns-rev-domainname "in-addr.arpa."; + +key "(keyname)" { + algorithm hmac-md5; + secret "(key)"; +}; + +zone testpdns { + primary 127.0.0.1; + key (keyname); +} + +zone 7.168.192.in-addr.arpa. { + primary 127.0.0.1; + key (keyname); +} + +``` + +## Client +DHCP Request +`# dhclient -v` + +Release IP +`# dhclient -v -r` \ No newline at end of file