configureDNS

configureDNS
This commit is contained in:
Kroese 2023-05-15 22:50:05 +02:00 committed by GitHub
commit 4903ff487c
2 changed files with 80 additions and 76 deletions

View File

@ -55,7 +55,7 @@ docker run -it --rm -p 5000:5000 --device=/dev/kvm --cap-add NET_ADMIN --stop-ti
To expand the default size of 16 GB, locate the `DISK_SIZE` setting in your compose file and modify it to your preferred capacity: To expand the default size of 16 GB, locate the `DISK_SIZE` setting in your compose file and modify it to your preferred capacity:
``` ```yaml
environment: environment:
DISK_SIZE: "256G" DISK_SIZE: "256G"
``` ```
@ -64,7 +64,7 @@ docker run -it --rm -p 5000:5000 --device=/dev/kvm --cap-add NET_ADMIN --stop-ti
To change the virtual disk's location from the default docker volume, include the following bind mount in your compose file: To change the virtual disk's location from the default docker volume, include the following bind mount in your compose file:
``` ```yaml
volumes: volumes:
- /home/user/data:/storage - /home/user/data:/storage
``` ```
@ -75,7 +75,7 @@ docker run -it --rm -p 5000:5000 --device=/dev/kvm --cap-add NET_ADMIN --stop-ti
By default, the entire disk space is reserved in advance. To create a growable disk, that only reserves the space that is actually used, add the following environment variable: By default, the entire disk space is reserved in advance. To create a growable disk, that only reserves the space that is actually used, add the following environment variable:
``` ```yaml
environment: environment:
ALLOCATE: "N" ALLOCATE: "N"
``` ```
@ -86,7 +86,7 @@ docker run -it --rm -p 5000:5000 --device=/dev/kvm --cap-add NET_ADMIN --stop-ti
By default, a single core and 512MB of RAM is allocated to the container. To increase this, add the following environment variables: By default, a single core and 512MB of RAM is allocated to the container. To increase this, add the following environment variables:
``` ```yaml
environment: environment:
CPU_CORES: "4" CPU_CORES: "4"
RAM_SIZE: "2048M" RAM_SIZE: "2048M"
@ -96,7 +96,7 @@ docker run -it --rm -p 5000:5000 --device=/dev/kvm --cap-add NET_ADMIN --stop-ti
To verify if your system supports KVM, run the following commands: To verify if your system supports KVM, run the following commands:
``` ```bash
sudo apt install cpu-checker sudo apt install cpu-checker
sudo kvm-ok sudo kvm-ok
``` ```
@ -109,27 +109,27 @@ docker run -it --rm -p 5000:5000 --device=/dev/kvm --cap-add NET_ADMIN --stop-ti
If you want to assign an individual IP address to the container, you can create a macvlan network as follows: If you want to assign an individual IP address to the container, you can create a macvlan network as follows:
``` ```bash
$ docker network create -d macvlan \ docker network create -d macvlan \
--subnet=192.168.0.0/24 \ --subnet=192.168.0.0/24 \
--gateway=192.168.0.1 \ --gateway=192.168.0.1 \
--ip-range=192.168.0.100/28 \ --ip-range=192.168.0.100/28 \
-o parent=eth0 vdsm -o parent=eth0 vdsm
``` ```
Be sure to modify the values to match your local subnet. Be sure to modify these values to match your local subnet.
Once you have created the network, modify the container's configuration in your compose file as follows: Once you have created the network, change your compose file to make it look as follows:
``` ```yaml
services:
dsm:
container_name: dsm
..<snip>..
networks: networks:
vdsm: vdsm:
ipv4_address: 192.168.0.100 ipv4_address: 192.168.0.100
```
Finally, add the network to the bottom of your compose file:
```
networks: networks:
vdsm: vdsm:
external: true external: true
@ -137,21 +137,21 @@ docker run -it --rm -p 5000:5000 --device=/dev/kvm --cap-add NET_ADMIN --stop-ti
An added benefit of this approach is that you won't have to perform any port mapping anymore, since all ports will be exposed by default. An added benefit of this approach is that you won't have to perform any port mapping anymore, since all ports will be exposed by default.
Please note that this IP address won't be accessible from the Docker host due to the design of macvlan, which doesn't permit communication between the two. If this is a concern, there are some workarounds available, but they go beyond the scope of this FAQ. Please note that this IP address won't be accessible from the Docker host due to the design of macvlan, which doesn't permit communication between the two. If this is a concern, you need to create a [second macvlan](https://blog.oddbit.com/post/2018-03-12-using-docker-macvlan-networks/#host-access) as a workaround.
* ### How can the container acquire an IP address from my router? * ### How can the container acquire an IP address from my router?
After configuring the container for macvlan (see above), it will now be able to join your home network by requesting an IP from your router, just like your other devices. After configuring the container for macvlan (see above), it is possible for DSM to become part of your home network by requesting an IP from your router, just like your other devices.
To enable this, add the following lines to your compose file: To enable this feature, add the following lines to your compose file:
``` ```yaml
environment: environment:
DHCP: "Y" DHCP: "Y"
devices: devices:
- /dev/vhost-net - /dev/vhost-net
device_cgroup_rules: device_cgroup_rules:
- 'c 510:* rwm' - 'c 511:* rwm'
``` ```
Please note that the exact `cgroup` rule number may vary depending on your system, but the log output will indicate the correct number in case of an error. Please note that the exact `cgroup` rule number may vary depending on your system, but the log output will indicate the correct number in case of an error.
@ -160,7 +160,7 @@ docker run -it --rm -p 5000:5000 --device=/dev/kvm --cap-add NET_ADMIN --stop-ti
By default version 7.2 will be installed, but if you prefer an older version, you can add its URL to your compose file as follows: By default version 7.2 will be installed, but if you prefer an older version, you can add its URL to your compose file as follows:
``` ```yaml
environment: environment:
URL: "https://global.synologydownload.com/download/DSM/release/7.1.1/42962-1/DSM_VirtualDSM_42962.pat" URL: "https://global.synologydownload.com/download/DSM/release/7.1.1/42962-1/DSM_VirtualDSM_42962.pat"
``` ```
@ -169,7 +169,7 @@ docker run -it --rm -p 5000:5000 --device=/dev/kvm --cap-add NET_ADMIN --stop-ti
* ### What are the differences compared to standard DSM? * ### What are the differences compared to standard DSM?
There are only three minor differences: the Virtual Machine Manager package is not provided, Surveillance Station doesn't include any free licenses, and logging in to your Synology account is not supported. There are only two minor differences: the Virtual Machine Manager package is not provided and Surveillance Station doesn't include any free licenses.
## Disclaimer ## Disclaimer

View File

@ -66,6 +66,52 @@ configureDHCP() {
return 0 return 0
} }
configureDNS () {
# dnsmasq configuration:
DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-range=$VM_NET_IP,$VM_NET_IP --dhcp-host=$VM_NET_MAC,,$VM_NET_IP,$VM_NET_HOST,infinite --dhcp-option=option:netmask,255.255.255.0"
# Create lease file for faster resolve
echo "0 $VM_NET_MAC $VM_NET_IP $VM_NET_HOST 01:${VM_NET_MAC}" > /var/lib/misc/dnsmasq.leases
chmod 644 /var/lib/misc/dnsmasq.leases
# Build DNS options from container /etc/resolv.conf
if [[ "${DEBUG}" == [Yy1]* ]]; then
echo "/etc/resolv.conf:" && echo && cat /etc/resolv.conf && echo
fi
mapfile -t nameservers < <( { grep '^nameserver' /etc/resolv.conf || true; } | sed 's/\t/ /g' | sed 's/nameserver //' | sed 's/ //g')
searchdomains=$( { grep '^search' /etc/resolv.conf || true; } | sed 's/\t/ /g' | sed 's/search //' | sed 's/#.*//' | sed 's/\s*$//g' | sed 's/ /,/g')
domainname=$(echo "$searchdomains" | awk -F"," '{print $1}')
for nameserver in "${nameservers[@]}"; do
nameserver=$(echo "$nameserver" | sed 's/#.*//' )
if ! [[ "$nameserver" =~ .*:.* ]]; then
[[ -z "$DNS_SERVERS" ]] && DNS_SERVERS="$nameserver" || DNS_SERVERS="$DNS_SERVERS,$nameserver"
fi
done
[[ -z "$DNS_SERVERS" ]] && DNS_SERVERS="1.1.1.1"
DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-option=option:dns-server,$DNS_SERVERS --dhcp-option=option:router,${VM_NET_IP%.*}.1"
if [ -n "$searchdomains" ] && [ "$searchdomains" != "." ]; then
DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-option=option:domain-search,$searchdomains --dhcp-option=option:domain-name,$domainname"
else
[[ -z $(hostname -d) ]] || DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-option=option:domain-name,$(hostname -d)"
fi
DNSMASQ_OPTS=$(echo "$DNSMASQ_OPTS" | sed 's/\t/ /g' | tr -s ' ' | sed 's/^ *//')
[[ "${DEBUG}" == [Yy1]* ]] && set -x
$DNSMASQ ${DNSMASQ_OPTS:+ $DNSMASQ_OPTS}
{ set +x; } 2>/dev/null
[[ "${DEBUG}" == [Yy1]* ]] && echo
return 0
}
configureNAT () { configureNAT () {
# Create a bridge with a static IP for the VM guest # Create a bridge with a static IP for the VM guest
@ -109,54 +155,12 @@ configureNAT () {
fi fi
fi fi
# dnsmasq configuration:
DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-range=$VM_NET_IP,$VM_NET_IP --dhcp-host=$VM_NET_MAC,,$VM_NET_IP,$VM_NET_HOST,infinite --dhcp-option=option:netmask,255.255.255.0"
# Create lease file for faster resolve
echo "0 $VM_NET_MAC $VM_NET_IP $VM_NET_HOST 01:${VM_NET_MAC}" > /var/lib/misc/dnsmasq.leases
chmod 644 /var/lib/misc/dnsmasq.leases
NET_OPTS="-netdev tap,ifname=${VM_NET_TAP},script=no,downscript=no,id=hostnet0" NET_OPTS="-netdev tap,ifname=${VM_NET_TAP},script=no,downscript=no,id=hostnet0"
{ exec 40>>/dev/vhost-net; rc=$?; } 2>/dev/null || : { exec 40>>/dev/vhost-net; rc=$?; } 2>/dev/null || :
(( rc == 0 )) && NET_OPTS="$NET_OPTS,vhost=on,vhostfd=40" (( rc == 0 )) && NET_OPTS="$NET_OPTS,vhost=on,vhostfd=40"
# Build DNS options from container /etc/resolv.conf configureDNS
if [[ "${DEBUG}" == [Yy1]* ]]; then
echo "/etc/resolv.conf:" && echo && cat /etc/resolv.conf && echo
fi
mapfile -t nameservers < <( { grep '^nameserver' /etc/resolv.conf || true; } | sed 's/\t/ /g' | sed 's/nameserver //' | sed 's/ //g')
searchdomains=$( { grep '^search' /etc/resolv.conf || true; } | sed 's/\t/ /g' | sed 's/search //' | sed 's/#.*//' | sed 's/\s*$//g' | sed 's/ /,/g')
domainname=$(echo "$searchdomains" | awk -F"," '{print $1}')
for nameserver in "${nameservers[@]}"; do
nameserver=$(echo "$nameserver" | sed 's/#.*//' )
if ! [[ "$nameserver" =~ .*:.* ]]; then
[[ -z "$DNS_SERVERS" ]] && DNS_SERVERS="$nameserver" || DNS_SERVERS="$DNS_SERVERS,$nameserver"
fi
done
[[ -z "$DNS_SERVERS" ]] && DNS_SERVERS="1.1.1.1"
DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-option=option:dns-server,$DNS_SERVERS --dhcp-option=option:router,${VM_NET_IP%.*}.1"
if [ -n "$searchdomains" ] && [ "$searchdomains" != "." ]; then
DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-option=option:domain-search,$searchdomains --dhcp-option=option:domain-name,$domainname"
else
[[ -z $(hostname -d) ]] || DNSMASQ_OPTS="$DNSMASQ_OPTS --dhcp-option=option:domain-name,$(hostname -d)"
fi
DNSMASQ_OPTS=$(echo "$DNSMASQ_OPTS" | sed 's/\t/ /g' | tr -s ' ' | sed 's/^ *//')
[[ "${DEBUG}" == [Yy1]* ]] && set -x
$DNSMASQ ${DNSMASQ_OPTS:+ $DNSMASQ_OPTS}
{ set +x; } 2>/dev/null
[[ "${DEBUG}" == [Yy1]* ]] && echo
return 0 return 0
} }
@ -165,6 +169,8 @@ configureNAT () {
# Configure Network # Configure Network
# ###################################### # ######################################
{ pkill -f server.sh || true; } 2>/dev/null
# Create the necessary file structure for /dev/net/tun # Create the necessary file structure for /dev/net/tun
if [ ! -c /dev/net/tun ]; then if [ ! -c /dev/net/tun ]; then
[ ! -d /dev/net ] && mkdir -m 755 /dev/net [ ! -d /dev/net ] && mkdir -m 755 /dev/net
@ -196,15 +202,13 @@ fi
if [[ "${DHCP}" == [Yy1]* ]]; then if [[ "${DHCP}" == [Yy1]* ]]; then
if [[ "$GATEWAY" == "172."* ]]; then if [[ "$GATEWAY" == "172."* ]]; then
error "You cannot enable DHCP while the container is " error "You can only enable DHCP while the container is on a macvlan network!" && exit 86
error "in a bridge network, only on a macvlan network!" && exit 86
fi fi
# Configuration for DHCP IP # Configuration for DHCP IP
configureDHCP configureDHCP
# Display IP on port 80 and 5000 # Display IP on port 80 and 5000
{ pkill -f server.sh || true; } 2>/dev/null
/run/server.sh 5000 /run/ip.sh & /run/server.sh 5000 /run/ip.sh &
else else