Merge pull request #769 from ignic/dhcp_setup

Enable DHCP Server with environment variables
This commit is contained in:
Adam Warner 2021-04-16 23:45:43 +01:00 committed by GitHub
commit dba2317072
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 34 additions and 0 deletions

View File

@ -103,6 +103,14 @@ There are other environment variables if you want to customize various things in
| `WEBUIBOXEDLAYOUT: <boxed\|traditional>`<br/>*Optional Default: boxed* | Use boxed layout (helpful when working on large screens)
| `SKIPGRAVITYONBOOT`: <Not Set\|1><br/> *Optional Default: Not Set* | Use this option to skip updating the Gravity Database when booting up the container. By default this environment variable is not set so the Gravity Database will be updated when the container starts up. Setting this environment variable to 1 (or anything) will cause the Gravity Database to not be updated when container starts up.
| `QUERY_LOGGING: <"true"\|"false">`<br/> *Optional* *Default: "true"* | Enable query logging or not.
| `DHCP_ACTIVE: <"true"\|"false">`<br/> *Optional* *Default: "false"* | Enable DHCP server. Static DHCP leases can be configured with a custom `/etc/dnsmasq.d/04-pihole-static-dhcp.conf`
| `DHCP_START: <Start IP>`<br/> *Optional* *Default: Not Set* | Start of the range of IP addresses to hand out by the DHCP server (mandatory if DHCP server is enabled).
| `DHCP_END: <End IP>`<br/> *Optional* *Default: Not Set* | End of the range of IP addresses to hand out by the DHCP server (mandatory if DHCP server is enabled).
| `DHCP_ROUTER: <Router's IP>`<br/> *Optional* *Default: Not Set* | Router (gateway) IP address sent by the DHCP server (mandatory if DHCP server is enabled).
| `DHCP_LEASETIME: <hours>`<br/> *Optional* *Default: 24* | DHCP lease time in hours.
| `PIHOLE_DOMAIN: <domain>`<br/> *Optional* *Default: lan* | Domain name sent by the DHCP server.
| `DHCP_IPv6: <"true"\|"false">`<br/> *Optional* *Default: "false"* | Enable DHCP server IPv6 support (SLAAC + RA).
| `DHCP_rapid_commit <"true"\|"false">`<br/> *Optional* *Default: "false"* | Enable DHCPv4 rapid commit (fast address assignment).
## Deprecated environment variables:
While these may still work, they are likely to be removed in a future version. Where applicible, alternative variable names are indicated. Please review the table above for usage of the alternative variables

View File

@ -333,3 +333,19 @@ setup_admin_email() {
pihole -a -e "$EMAIL"
fi
}
setup_dhcp() {
if [ -z "${DHCP_START}" ] || [ -z "${DHCP_END}" ] || [ -z "${DHCP_ROUTER}" ]; then
echo "ERROR: Won't enable DHCP server because mandatory Environment variables are missing: DHCP_START, DHCP_END and/or DHCP_ROUTER"
change_setting "DHCP_ACTIVE" "false"
else
change_setting "DHCP_ACTIVE" "${DHCP_ACTIVE}"
change_setting "DHCP_START" "${DHCP_START}"
change_setting "DHCP_END" "${DHCP_END}"
change_setting "DHCP_ROUTER" "${DHCP_ROUTER}"
change_setting "DHCP_LEASETIME" "${DHCP_LEASETIME}"
change_setting "PIHOLE_DOMAIN" "${PIHOLE_DOMAIN}"
change_setting "DHCP_IPv6" "${DHCP_IPv6}"
change_setting "DHCP_rapid_commit" "${DHCP_rapid_commit}"
fi
}

View File

@ -30,6 +30,14 @@ export ADMIN_EMAIL
export WEBUIBOXEDLAYOUT
export QUERY_LOGGING
export PIHOLE_DNS_
export DHCP_ACTIVE
export DHCP_START
export DHCP_END
export DHCP_ROUTER
export DHCP_LEASETIME
export PIHOLE_DOMAIN
export DHCP_IPv6
export DHCP_rapid_commit
export adlistFile='/etc/pihole/adlists.list'
@ -118,6 +126,8 @@ else
fi
fi
[[ -n "${DHCP_ACTIVE}" && ${DHCP_ACTIVE} == "true" ]] && echo "Setting DHCP server" && setup_dhcp
setup_web_port "$WEB_PORT"
setup_web_password "$WEBPASSWORD"
setup_temp_unit "$TEMPERATUREUNIT"