diff --git a/README.md b/README.md index e05d5e7..cc89ea6 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,12 @@ In addition to the required environment variable you saw above (`-e ServerIP="$I | VIRTUAL_HOST | Server_IP | What your web server 'virtual host' is, accessing admin through this Hostname/IP allows you to make changes to the whitelist / blacklists in addition to the default 'http://pi.hole/admin/' address | | IPv6 | True | Allows forced disabling of IPv6 for docker setups that can't support it (like unraid) | +*OPTIONAL Advanced* Environment Variables + +| Env Variable | Default | Description | +| INTERFACE | eth0 | The default works fine with our basic example docker run commands. If you're trying to use DHCP with `--net host` mode then you may have to customize this or DNSMASQ_LISTENING. +| DNSMASQ_LISTENING | | If set to `local` or `all` this will override `INTERFACE`. `local` listens on all local subnets, `all` permits listening on internet origin subnets in addition to local. + ## Tips and Tricks * A good way to test things are working right is by loading this page: [http://pi.hole/admin/](http://pi.hole/admin/) diff --git a/bash_functions.sh b/bash_functions.sh index f08e80a..3c83de6 100644 --- a/bash_functions.sh +++ b/bash_functions.sh @@ -27,7 +27,23 @@ setup_dnsmasq_dns() { echo "Using $dnsType DNS servers: $DNS1 & $DNS2" [ -n "$DNS1" ] && change_setting "PIHOLE_DNS_1" "${DNS1}" [ -n "$DNS2" ] && change_setting "PIHOLE_DNS_2" "${DNS2}" - ProcessDNSSettings +} + +setup_dnsmasq_interface() { + local INTERFACE="${1:-eth0}" + local interfaceType='default' + if [ "$INTERFACE" != 'eth0' ] ; then + interfaceType='custom' + fi; + echo "DNSMasq binding to $interfaceType interface: $INTERFACE" + [ -n "$INTERFACE" ] && change_setting "PIHOLE_INTERFACE" "${INTERFACE}" +} + +setup_dnsmasq() { + # Coordinates + setup_dnsmasq_dns "$DNS1" "$DNS2" + setup_dnsmasq_interface "$INTERFACE" + ProcessDNSSettings } setup_dnsmasq_hostnames() { diff --git a/start.sh b/start.sh index 9da2bad..0ecc7f8 100755 --- a/start.sh +++ b/start.sh @@ -10,8 +10,8 @@ export HOSTNAME export WEBLOGDIR export DNS1 export DNS2 +export INTERFACE export IPv6 -#export setupVars="${setupVars:-/etc/pihole/setupVars.conf}" . /bash_functions.sh @@ -21,7 +21,7 @@ prepare_setup_vars change_setting "IPV4_ADDRESS" "$ServerIP" change_setting "IPV6_ADDRESS" "$ServerIPv6" setup_web_password "$WEBPASSWORD" -setup_dnsmasq_dns "$DNS1" "$DNS2" +setup_dnsmasq setup_php_env setup_dnsmasq_hostnames "$ServerIP" "$ServerIPv6" "$HOSTNAME" setup_ipv4_ipv6 diff --git a/test/test_bash_functions.py b/test/test_bash_functions.py index 68a578a..47591e9 100644 --- a/test/test_bash_functions.py +++ b/test/test_bash_functions.py @@ -32,13 +32,26 @@ def test_IPv6_not_True_removes_ipv6(Docker, tag, args, expected_ipv6, expected_s ]) def test_DNS_Envs_override_defaults(Docker, args, expected_stdout, dns1, dns2): ''' When DNS environment vars are passed in, they override default dns servers ''' - function = Docker.run('. /bash_functions.sh ; eval `grep setup_dnsmasq_dns /start.sh`') + function = Docker.run('. /bash_functions.sh ; eval `grep setup_dnsmasq /start.sh`') assert expected_stdout in function.stdout docker_dns_servers = Docker.run('grep "^server=" /etc/dnsmasq.d/01-pihole.conf').stdout expected_servers = 'server={}\nserver={}\n'.format(dns1, dns2) assert expected_servers == docker_dns_servers +@pytest.mark.parametrize('args, expected_stdout, expected_config_line', [ + ('-e ServerIP="1.2.3.4"', 'binding to default interface: eth0', 'interface=eth0' ), + ('-e ServerIP="1.2.3.4" -e INTERFACE="eth0"', 'binding to default interface: eth0', 'interface=eth0' ), + ('-e ServerIP="1.2.3.4" -e INTERFACE="br0"', 'binding to custom interface: br0', 'interface=br0'), +]) +def test_DNS_interface_override_defaults(Docker, args, expected_stdout, expected_config_line): + ''' When INTERFACE environment var is passed in, overwrite dnsmasq interface ''' + function = Docker.run('. /bash_functions.sh ; eval `grep setup_dnsmasq /start.sh`') + assert expected_stdout in function.stdout + + docker_dns_interface = Docker.run('grep "^interface" /etc/dnsmasq.d/01-pihole.conf').stdout + assert expected_config_line + '\n' == docker_dns_interface + expected_debian_lines = [ '"VIRTUAL_HOST" => "192.168.100.2"', '"ServerIP" => "192.168.100.2"',