dnsmasq: Refactor (#591)

* dnsmasq: Rewrite add-on onto Bashio

* dnsmasq: Removes debug statement from run.sh

* dnsmasq: Formats config.json

* dnsmasq: Adds README to add-on repository

* dnsmasq: Bumps version to 1.3, updates CHANGELOG
This commit is contained in:
Franck Nijhof
2019-06-02 13:34:59 +02:00
committed by GitHub
parent 59781645c4
commit fc839e76c7
5 changed files with 150 additions and 21 deletions

View File

@@ -1,7 +1,15 @@
# Changelog
## 1.3
- Rewrites add-on onto Bashio
- Adds README to add-on repository
- Some small code formatting
## 1.2
- Update DNSmasq 2.80
## 1.1
- Add AppArmor profile

108
dnsmasq/README.md Normal file
View File

@@ -0,0 +1,108 @@
# Hass.io Core Add-on: Dnsmasq
A simple DNS server.
![Supports aarch64 Architecture][aarch64-shield] ![Supports amd64 Architecture][amd64-shield] ![Supports armhf Architecture][armhf-shield] ![Supports armv7 Architecture][armv7-shield] ![Supports i386 Architecture][i386-shield]
## About
Setup and manage a Dnsmasq DNS server. This allows you to manipulate DNS
requests. For example, you can have your Home Assistant domain resolve with
an internal address inside your network.
## Installation
The installation of this add-on is straightforward and easy to do.
1. Navigate in your Home Assistant frontend to **Hass.io** -> **Add-on Store**.
2. Find the "Dnsmasq" add-on and click it.
3. Click on the "INSTALL" button.
## How to use
The add-on has a couple of options available. For more detailed instructions
see below. The basic thing to get the add-on running would be:
1. Start the add-on.
## Configuration
The Dnsmasq add-on can be tweaked to your likings. This section
describes each of the add-on configuration options.
Example add-on configuration:
```json
{
"defaults": ["8.8.8.8", "8.8.4.4"],
"forwards": [
{"domain": "mystuff.local", "server": "192.168.1.40"}
],
"hosts": [
{"host": "home.mydomain.io", "ip": "192.168.1.10"}
]
}
```
### Option: `defaults` (required)
The defaults are upstream DNS servers, where DNS requests that can't
be handled locally, are forwarded to. By default it is configured to have
Google's public DNS servers: `"8.8.8.8", "8.8.4.4".
### Option: `forwards` (optional)
This option allows you to list domain that are forwarded to a different
(not the default) upstream DNS server.
#### Option: `forwards` -> `domain`
The domain to forward to a different upstream DNS server.
#### Option: `forwards` -> `server`
The DNS server to forward the request for this domain to.
### Option: `hosts` (optional)
This option allows you to provide local static answer for your DNS server.
This is helpful for making addresses resolve on your internal network and
even override external domains to be answered with a local address.
For example, one could set `myuser.duckdns.org` to resolve directly to a
internal IP address, e.g., `192.168.1.10`. While outsite of this network,
it would resolve normally.
This options allows you to create a so called: Split DNS.
#### Option: `hosts` -> `host`
The hostname or domainname to resolve locally.
#### Option: `hosts` -> `ip`
The IP address Dnsmasq should respond with in its DNS answer.
## Support
Got questions?
You have several options to get them answered:
- The [Home Assistant Discord Chat Server][discord].
- The Home Assistant [Community Forum][forum].
- Join the [Reddit subreddit][reddit] in [/r/homeassistant][reddit]
In case you've found an bug, please [open an issue on our GitHub][issue].
[aarch64-shield]: https://img.shields.io/badge/aarch64-yes-green.svg
[amd64-shield]: https://img.shields.io/badge/amd64-yes-green.svg
[armhf-shield]: https://img.shields.io/badge/armhf-yes-green.svg
[armv7-shield]: https://img.shields.io/badge/armv7-yes-green.svg
[discord]: https://discord.gg/c5DvZ4e
[forum]: https://community.home-assistant.io
[i386-shield]: https://img.shields.io/badge/i386-yes-green.svg
[issue]: https://github.com/home-assistant/hassio-addons/issues
[reddit]: https://reddit.com/r/homeassistant
[repository]: https://github.com/hassio-addons/repository

View File

@@ -21,6 +21,10 @@ profile dnsmasq flags=(attach_disconnected,mediate_deleted) {
/{,var/}run/dnsmasq/ r,
/{,var/}run/dnsmasq/* rw,
/usr/lib/bashio/bashio ix,
/dev/tty rw,
/tmp/* rw,
/run.sh rix,
/data/** r,
}

View File

@@ -1,10 +1,16 @@
{
"name": "Dnsmasq",
"version": "1.2",
"version": "1.3",
"slug": "dnsmasq",
"description": "A simple DNS server",
"url": "https://home-assistant.io/addons/dnsmasq/",
"arch": ["armhf", "armv7", "aarch64", "amd64", "i386"],
"arch": [
"armhf",
"armv7",
"aarch64",
"amd64",
"i386"
],
"startup": "system",
"boot": "auto",
"ports": {
@@ -12,12 +18,17 @@
"53/udp": 53
},
"options": {
"defaults": ["8.8.8.8", "8.8.4.4"],
"defaults": [
"8.8.8.8",
"8.8.4.4"
],
"forwards": [],
"hosts": []
},
"schema": {
"defaults": ["str"],
"defaults": [
"str"
],
"forwards": [
{
"domain": "str",

View File

@@ -1,32 +1,30 @@
#!/bin/bash
#!/usr/bin/env bashio
set -e
CONFIG_PATH=/data/options.json
DEFAULTS=$(jq --raw-output '.defaults[]' $CONFIG_PATH)
FORWARDS=$(jq --raw-output '.forwards | length' $CONFIG_PATH)
HOSTS=$(jq --raw-output '.hosts | length' $CONFIG_PATH)
CONFIG="/etc/dnsmasq.conf"
bashio::log.info "Configuring dnsmasq..."
# Add default forward servers
for line in $DEFAULTS; do
echo "server=$line" >> /etc/dnsmasq.conf
for server in $(bashio::config 'defaults'); do
echo "server=${server}" >> "${CONFIG}"
done
# Create domain forwards
for (( i=0; i < "$FORWARDS"; i++ )); do
DOMAIN=$(jq --raw-output ".forwards[$i].domain" $CONFIG_PATH)
SERVER=$(jq --raw-output ".forwards[$i].server" $CONFIG_PATH)
for forward in $(bashio::config 'forwards|keys'); do
DOMAIN=$(bashio::config "forwards[${forward}].domain")
SERVER=$(bashio::config "forwards[${forward}].server")
echo "server=/$DOMAIN/$SERVER" >> /etc/dnsmasq.conf
echo "server=/${DOMAIN}/${SERVER}" >> "${CONFIG}"
done
# Create static hosts
for (( i=0; i < "$HOSTS"; i++ )); do
HOST=$(jq --raw-output ".hosts[$i].host" $CONFIG_PATH)
IP=$(jq --raw-output ".hosts[$i].ip" $CONFIG_PATH)
for host in $(bashio::config 'hosts|keys'); do
HOST=$(bashio::config "hosts[${host}].host")
IP=$(bashio::config "hosts[${host}].ip")
echo "address=/$HOST/$IP" >> /etc/dnsmasq.conf
echo "address=/${HOST}/${IP}" >> "${CONFIG}"
done
# run dnsmasq
exec dnsmasq -C /etc/dnsmasq.conf -z < /dev/null
bashio::log.info "Starting dnsmasq..."
exec dnsmasq -C "${CONFIG}" -z < /dev/null