Nextcloud docker (Collabora) DNS does not resolve (nextcloud#1213) (#1306)
Signed-off-by: aaaskew <aaaskew@yahoo.com> Co-authored-by: Daniel Hansson <github@hanssonit.se>
This commit is contained in:
Родитель
7a69f992d3
Коммит
cecad410de
|
@ -82,6 +82,7 @@ Please report any issues you can find. Improvments are welcome!
|
|||
* [Lorenzo Faleschini](https://github.com/penzoiders)
|
||||
* [Georg Großmann](https://github.com/ggeorgg)
|
||||
* [liao20081228](https://github.com/liao20081228)
|
||||
* [aaaskew](https://github.com/aaaskew)
|
||||
|
||||
[Nextcloud Server]: https://bit.ly/2CHIUkA
|
||||
[app store]: https://bit.ly/2HUy4v9
|
||||
|
|
64
lib.sh
64
lib.sh
|
@ -44,8 +44,32 @@ WANIP4=$(curl -s -k -m 5 https://ipv4bot.whatismyipaddress.com)
|
|||
[ -n "$LOAD_IP6" ] && WANIP6=$(curl -s -k -m 5 https://ipv6bot.whatismyipaddress.com)
|
||||
INTERFACES="/etc/netplan/01-netcfg.yaml"
|
||||
GATEWAY=$(ip route | grep default | awk '{print $3}')
|
||||
# Internet DNS required when a check needs to be made to a server outside the home/SME
|
||||
INTERNET_DNS="9.9.9.9"
|
||||
# Default Quad9 DNS servers, overwritten by the systemd global DNS defined servers, if set
|
||||
DNS1="9.9.9.9"
|
||||
DNS2="149.112.112.112"
|
||||
use_global_systemd_dns() {
|
||||
if [ -f "/etc/systemd/resolved.conf" ]
|
||||
then
|
||||
local resolvedDns1
|
||||
resolvedDns1=$(grep -m 1 -E "^DNS=.+" /etc/systemd/resolved.conf | sed s/^DNS=// | awk '{print $1}')
|
||||
if [ -n "$resolvedDns1" ]
|
||||
then
|
||||
DNS1="$resolvedDns1"
|
||||
|
||||
local resolvedDns2
|
||||
resolvedDns2=$(grep -m 1 -E "^DNS=.+" /etc/systemd/resolved.conf | sed s/^DNS=// | awk '{print $2}')
|
||||
if [ -n "$resolvedDns2" ]
|
||||
then
|
||||
DNS2="$resolvedDns2"
|
||||
else
|
||||
DNS2=
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
}
|
||||
use_global_systemd_dns
|
||||
# Repo
|
||||
GITHUB_REPO="https://raw.githubusercontent.com/nextcloud/vm/master"
|
||||
STATIC="$GITHUB_REPO/static"
|
||||
|
@ -230,14 +254,14 @@ domain_check_200() {
|
|||
install_if_not dnsutils
|
||||
|
||||
# Try to resolve the domain with nslookup using $DNS as resolver
|
||||
if nslookup "${1}" $DNS1 >/dev/null 2>&1
|
||||
if nslookup "${1}" "$INTERNET_DNS" >/dev/null 2>&1
|
||||
then
|
||||
print_text_in_color "$IGreen" "DNS seems correct when checking with nslookup!"
|
||||
else
|
||||
print_text_in_color "$IRed" "DNS lookup failed with nslookup."
|
||||
print_text_in_color "$IRed" "Please check your DNS settings! Maybe the domain isn't propagated?"
|
||||
print_text_in_color "$ICyan" "Please check https://www.whatsmydns.net/#A/${1} if the IP seems correct."
|
||||
nslookup "${1}" $DNS1
|
||||
nslookup "${1}" "$INTERNET_DNS"
|
||||
return 1
|
||||
fi
|
||||
|
||||
|
@ -263,6 +287,22 @@ You can always contact us for further support if you wish: https://shop.hanssoni
|
|||
fi
|
||||
}
|
||||
|
||||
# A function to set the systemd-resolved default DNS servers based on the
|
||||
# current Internet facing interface. This is needed for docker interfaces
|
||||
# that might not use the same DNS servers otherwise.
|
||||
set_systemd_resolved_dns() {
|
||||
local iface="$1"
|
||||
local pattern="$iface(?:.|\n)*?DNS Servers: ((?:[0-9a-f.: ]|\n)*?)\s*(?=\n\S|\n.+: |$)"
|
||||
local dnss
|
||||
dnss=$( systemd-resolve --status | perl -0777 -ne "if ((\$v) = (/$pattern/)) {\$v=~s/(?:\s|\n)+/ /g;print \"\$v\n\";}" )
|
||||
if [ -n "$dnss" ]
|
||||
then
|
||||
sed -i "s/^#\?DNS=.*$/DNS=${dnss}/" /etc/systemd/resolved.conf
|
||||
systemctl restart systemd-resolved &>/dev/null
|
||||
sleep 1
|
||||
fi
|
||||
}
|
||||
|
||||
# A function to fetch a file with curl to a directory
|
||||
# 1 = https://example.com
|
||||
# 2 = name of file
|
||||
|
@ -415,30 +455,28 @@ if ! dpkg-query -W -f='${Status}' "net-tools" | grep -q "ok installed"
|
|||
then
|
||||
apt update -q4 & spinner_loading && apt install net-tools -y
|
||||
fi
|
||||
# After applying Netplan settings, try a DNS lookup.
|
||||
# Restart systemd-networkd if this fails and try again.
|
||||
# If this second check also fails, consider this a problem.
|
||||
print_text_in_color "$ICyan" "Checking connection..."
|
||||
netplan apply
|
||||
sleep 2
|
||||
if nslookup github.com
|
||||
then
|
||||
print_text_in_color "$IGreen" "Online!"
|
||||
elif ! nslookup github.com
|
||||
if ! nslookup github.com
|
||||
then
|
||||
print_text_in_color "$ICyan" "Trying to restart netplan service..."
|
||||
check_command systemctl restart systemd-networkd && sleep 2
|
||||
if nslookup github.com
|
||||
then
|
||||
print_text_in_color "$IGreen" "Online!"
|
||||
fi
|
||||
else
|
||||
if ! nslookup github.com
|
||||
then
|
||||
msg_box "Network NOT OK. You must have a working network connection to run this script
|
||||
msg_box "Network NOT OK. You must have a working network connection to run this script.
|
||||
If you think that this is a bug, please report it to https://github.com/nextcloud/vm/issues."
|
||||
exit 1
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
print_text_in_color "$IGreen" "Online!"
|
||||
return 0
|
||||
}
|
||||
|
||||
|
||||
# Check that the script can see the external IP (apache fails otherwise), used e.g. in the adminer app script.
|
||||
check_external_ip() {
|
||||
if [ -z "$WANIP4" ]
|
||||
|
|
|
@ -82,6 +82,7 @@ SETDHCP
|
|||
check_command netplan apply
|
||||
print_text_in_color "$ICyan" "Checking connection..."
|
||||
sleep 1
|
||||
set_systemd_resolved_dns "$IFACE"
|
||||
if ! nslookup github.com
|
||||
then
|
||||
msg_box "The script failed to get an address from DHCP.
|
||||
|
@ -239,7 +240,6 @@ download_script LETS_ENC activate-tls
|
|||
download_script STATIC temporary-fix
|
||||
download_script STATIC update
|
||||
download_script STATIC trusted
|
||||
download_script STATIC test_connection
|
||||
download_script STATIC setup_secure_permissions_nextcloud
|
||||
download_script STATIC change_db_pass
|
||||
download_script STATIC nextcloud
|
||||
|
@ -465,7 +465,6 @@ rm "$SCRIPTS"/temporary-fix.sh
|
|||
occ_command maintenance:repair
|
||||
rm -f "$SCRIPTS/ip.sh"
|
||||
rm -f "$SCRIPTS/change_db_pass.sh"
|
||||
rm -f "$SCRIPTS/test_connection.sh"
|
||||
rm -f "$SCRIPTS/instruction.sh"
|
||||
rm -f "$NCDATA/nextcloud.log"
|
||||
rm -f "$SCRIPTS/static_ip.sh"
|
||||
|
|
|
@ -198,30 +198,41 @@ esac
|
|||
fi
|
||||
|
||||
# Set DNS resolver
|
||||
# https://medium.com/@ahmadb/fixing-dns-issues-in-ubuntu-18-04-lts-bd4f9ca56620
|
||||
choice=$(whiptail --title "Set DNS Resolver" --radiolist "Which DNS provider should this Nextcloud box use?\nSelect by pressing the spacebar and ENTER" "$WT_HEIGHT" "$WT_WIDTH" 4 \
|
||||
"Quad9" "(https://www.quad9.net/)" ON \
|
||||
"Cloudflare" "(https://www.cloudflare.com/dns/)" OFF \
|
||||
"Local" "($GATEWAY + 149.112.112.112)" OFF 3>&1 1>&2 2>&3)
|
||||
# https://unix.stackexchange.com/questions/442598/how-to-configure-systemd-resolved-and-systemd-networkd-to-use-local-dns-server-f
|
||||
while :
|
||||
do
|
||||
choice=$(whiptail --title "Set DNS Resolver" --radiolist "Which DNS provider should this Nextcloud box use?\nSelect by pressing the spacebar and ENTER" "$WT_HEIGHT" "$WT_WIDTH" 4 \
|
||||
"Quad9" "(https://www.quad9.net/)" ON \
|
||||
"Cloudflare" "(https://www.cloudflare.com/dns/)" OFF \
|
||||
"Local" "($GATEWAY) - DNS on gateway" OFF 3>&1 1>&2 2>&3)
|
||||
|
||||
case "$choice" in
|
||||
"Quad9")
|
||||
sed -i "s|#DNS=.*|DNS=9.9.9.9 2620:fe::fe|g" /etc/systemd/resolved.conf
|
||||
sed -i "s|#FallbackDNS=.*|FallbackDNS=149.112.112.112 2620:fe::9|g" /etc/systemd/resolved.conf
|
||||
;;
|
||||
"Cloudflare")
|
||||
sed -i "s|#DNS=.*|DNS=1.1.1.1 2606:4700:4700::1111|g" /etc/systemd/resolved.conf
|
||||
sed -i "s|#FallbackDNS=.*|FallbackDNS=1.0.0.1 2606:4700:4700::1001|g" /etc/systemd/resolved.conf
|
||||
;;
|
||||
"Local")
|
||||
sed -i "s|#DNS=.*|DNS=$GATEWAY|g" /etc/systemd/resolved.conf
|
||||
sed -i "s|#FallbackDNS=.*|FallbackDNS=149.112.112.112 2620:fe::9|g" /etc/systemd/resolved.conf
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
test_connection
|
||||
network_ok
|
||||
case "$choice" in
|
||||
"Quad9")
|
||||
sed -i "s|^#\?DNS=.*$|DNS=9.9.9.9 149.112.112.112 2620:fe::fe 2620:fe::9|g" /etc/systemd/resolved.conf
|
||||
;;
|
||||
"Cloudflare")
|
||||
sed -i "s|^#\?DNS=.*$|DNS=1.1.1.1 1.0.0.1 2606:4700:4700::1111 2606:4700:4700::1001|g" /etc/systemd/resolved.conf
|
||||
;;
|
||||
"Local")
|
||||
sed -i "s|^#\?DNS=.*$|DNS=$GATEWAY|g" /etc/systemd/resolved.conf
|
||||
if network_ok
|
||||
then
|
||||
break
|
||||
else
|
||||
msg_box "Could not validate the local DNS server. Pick an Internet DNS server and try again."
|
||||
continue
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
esac
|
||||
if test_connection
|
||||
then
|
||||
break
|
||||
else
|
||||
msg_box "Could not validate the DNS server. Please try again."
|
||||
fi
|
||||
done
|
||||
|
||||
# Check current repo
|
||||
run_script STATIC locate_mirror
|
||||
|
|
|
@ -63,135 +63,163 @@ then
|
|||
exit
|
||||
fi
|
||||
|
||||
# Loop until working network settings are validated or the user asks to quit
|
||||
echo
|
||||
while true
|
||||
do
|
||||
# Ask for IP address
|
||||
cat << ENTERIP
|
||||
# Loop until user is happy with the IP address and subnet
|
||||
echo
|
||||
while true
|
||||
do
|
||||
# Ask for IP address
|
||||
cat << ENTERIP
|
||||
+----------------------------------------------------------+
|
||||
| Please enter the static IP address you want to set, |
|
||||
| including the subnet. Example: 192.168.1.100/24 |
|
||||
+----------------------------------------------------------+
|
||||
ENTERIP
|
||||
echo
|
||||
read -r LANIP
|
||||
echo
|
||||
echo
|
||||
read -r LANIP
|
||||
echo
|
||||
|
||||
if [[ $LANIP == *"/"* ]]
|
||||
then
|
||||
if [[ "yes" == $(ask_yes_or_no "Is this correct? $LANIP") ]]
|
||||
if [[ $LANIP == *"/"* ]]
|
||||
then
|
||||
break
|
||||
if [[ "yes" == $(ask_yes_or_no "Is this correct? $LANIP") ]]
|
||||
then
|
||||
break
|
||||
fi
|
||||
else
|
||||
print_text_in_color "$IRed" "Did you forget the /subnet?"
|
||||
fi
|
||||
else
|
||||
print_text_in_color "$IRed" "Did you forget the /subnet?"
|
||||
fi
|
||||
done
|
||||
done
|
||||
|
||||
echo
|
||||
while true
|
||||
do
|
||||
# Ask for domain name
|
||||
cat << ENTERGATEWAY
|
||||
# Loop until user is happy with the default gateway
|
||||
echo
|
||||
while true
|
||||
do
|
||||
# Ask for domain name
|
||||
cat << ENTERGATEWAY
|
||||
+-------------------------------------------------------+
|
||||
| Please enter the gateway address you want to set. |
|
||||
| Just hit enter to choose the current gateway. |
|
||||
| Your current gateway is: $GATEWAY |
|
||||
+-------------------------------------------------------+
|
||||
ENTERGATEWAY
|
||||
echo
|
||||
read -r GATEWAYIP
|
||||
echo
|
||||
if [ -z "$GATEWAYIP" ]
|
||||
then
|
||||
GATEWAYIP="$GATEWAY"
|
||||
fi
|
||||
if [[ "yes" == $(ask_yes_or_no "Is this correct? $GATEWAYIP") ]]
|
||||
then
|
||||
break
|
||||
fi
|
||||
done
|
||||
echo
|
||||
read -r GATEWAYIP
|
||||
echo
|
||||
if [ -z "$GATEWAYIP" ]
|
||||
then
|
||||
GATEWAYIP="$GATEWAY"
|
||||
fi
|
||||
if [[ "yes" == $(ask_yes_or_no "Is this correct? $GATEWAYIP") ]]
|
||||
then
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
# DNS
|
||||
msg_box "You will now be provided with the option to set your own local DNS.
|
||||
# DNS
|
||||
msg_box "You will now be provided with the option to set your own local DNS.
|
||||
|
||||
If you're not sure what DNS is, or if you don't have a local DNS server,
|
||||
please don't touch this setting.
|
||||
|
||||
If something goes wrong here, you will not be
|
||||
able to get any deb packages, download files, or reach internet.
|
||||
able to get any deb packages, download files, or reach the internet.
|
||||
|
||||
The default nameservers are:
|
||||
The current nameservers are:
|
||||
$DNS1
|
||||
$DNS2
|
||||
"
|
||||
|
||||
if [[ "yes" == $(ask_yes_or_no "Do you want to set your own nameservers?") ]]
|
||||
then
|
||||
echo
|
||||
while true
|
||||
do
|
||||
# Ask for nameserver
|
||||
cat << ENTERNS1
|
||||
# Set the variable used to fill in the Netplan nameservers. The existing
|
||||
# values are used if the user does not decides not to update the nameservers.
|
||||
DNSs="$DNS1"
|
||||
# Only add a second nameserver to the list if it is defined.
|
||||
if [ -n "$DNS2" ]
|
||||
then
|
||||
DNSs="$DNS1,$DNS2"
|
||||
fi
|
||||
|
||||
if [[ "yes" == $(ask_yes_or_no "Do you want to set your own nameservers?") ]]
|
||||
then
|
||||
# Loop until user is happy with the nameserver 1
|
||||
echo
|
||||
while true
|
||||
do
|
||||
# Ask for nameserver
|
||||
cat << ENTERNS1
|
||||
+-------------------------------------------------------+
|
||||
| Please enter the local nameserver address you want |
|
||||
| to set. Just hit enter to choose the current NS1. |
|
||||
| Your current NS1 is: $DNS1 |
|
||||
+-------------------------------------------------------+
|
||||
ENTERNS1
|
||||
echo
|
||||
read -r NSIP1
|
||||
echo
|
||||
if [ -z "$NSIP1" ]
|
||||
then
|
||||
NSIP1="$DNS1"
|
||||
fi
|
||||
if [[ "yes" == $(ask_yes_or_no "Is this correct? $NSIP1") ]]
|
||||
then
|
||||
break
|
||||
fi
|
||||
done
|
||||
echo
|
||||
read -r NSIP1
|
||||
echo
|
||||
if [ -z "$NSIP1" ]
|
||||
then
|
||||
NSIP1="$DNS1"
|
||||
fi
|
||||
if [[ "yes" == $(ask_yes_or_no "Is this correct? $NSIP1") ]]
|
||||
then
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
echo
|
||||
while true
|
||||
do
|
||||
# Ask for nameserver
|
||||
cat << ENTERNS2
|
||||
# Nameserver 2 might be empty. As this will not be clear
|
||||
# in prompts, 'none' is used in this case.
|
||||
DISPLAY_DNS2="$DNS2"
|
||||
if [ -z "$DISPLAY_DNS2" ]
|
||||
then
|
||||
DISPLAY_DNS2="'none'"
|
||||
fi
|
||||
|
||||
# Loop until user is happy with the nameserver 2
|
||||
echo
|
||||
while true
|
||||
do
|
||||
# Ask for nameserver
|
||||
cat << ENTERNS2
|
||||
+-------------------------------------------------------+
|
||||
| Please enter the local nameserver address you want |
|
||||
| to set. Just hit enter to choose the current NS2. |
|
||||
| Your current NS2 is: $DNS2 |
|
||||
| to set. The 3 options are: |
|
||||
| - Hit enter to choose the current NS2. |
|
||||
| - Enter a new IP address for NS2. |
|
||||
| - Enter the text 'none' if you only have one NS. |
|
||||
| Your current NS2 is: $DISPLAY_DNS2 |
|
||||
+-------------------------------------------------------+
|
||||
ENTERNS2
|
||||
echo
|
||||
read -r NSIP2
|
||||
echo
|
||||
if [ -z "$NSIP2" ]
|
||||
echo
|
||||
read -r NSIP2
|
||||
echo
|
||||
if [ -z "$NSIP2" ]
|
||||
then
|
||||
NSIP2="$DISPLAY_DNS2"
|
||||
fi
|
||||
if [[ "yes" == $(ask_yes_or_no "Is this correct? $NSIP2") ]]
|
||||
then
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# Check if DNS is set manaully and set variables accordingly
|
||||
if [ -n "$NSIP1" ]
|
||||
then
|
||||
DNSs="$NSIP1"
|
||||
# Only add a second nameserver to the list if it is defined and not 'none'.
|
||||
if [[ -n "$NSIP2" && ! ( "none" == "$NSIP2" || "'none'" == "$NSIP2" ) ]]
|
||||
then
|
||||
NSIP2="$DNS2"
|
||||
DNSs="$NSIP1,$NSIP2"
|
||||
fi
|
||||
if [[ "yes" == $(ask_yes_or_no "Is this correct? $NSIP2") ]]
|
||||
then
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
# Check if DNS is set manaully and set variables accordingly
|
||||
if [ -n "$NSIP1" ]
|
||||
then
|
||||
DNS1="$NSIP1"
|
||||
fi
|
||||
|
||||
if [ -n "$NSIP2" ]
|
||||
then
|
||||
DNS2="$NSIP2"
|
||||
fi
|
||||
|
||||
# Check if IFACE is empty, if yes, try another method:
|
||||
if [ -n "$IFACE" ]
|
||||
then
|
||||
cat <<-IPCONFIG > "$INTERFACES"
|
||||
# Check if IFACE is empty, if yes, try another method:
|
||||
if [ -n "$IFACE" ]
|
||||
then
|
||||
cat <<-IPCONFIG > "$INTERFACES"
|
||||
network:
|
||||
version: 2
|
||||
ethernets:
|
||||
|
@ -201,15 +229,16 @@ network:
|
|||
addresses: [$LANIP] # client IP address
|
||||
gateway4: $GATEWAYIP # gateway address
|
||||
nameservers:
|
||||
addresses: [$DNS1,$DNS2] #name servers
|
||||
addresses: [$DNSs] #name servers
|
||||
IPCONFIG
|
||||
|
||||
msg_box "These are your settings, please make sure they are correct:
|
||||
msg_box "These are your settings, please make sure they are correct:
|
||||
|
||||
$(cat /etc/netplan/01-netcfg.yaml)"
|
||||
netplan try
|
||||
else
|
||||
cat <<-IPCONFIGnonvmware > "$INTERFACES"
|
||||
netplan try
|
||||
set_systemd_resolved_dns "$IFACE"
|
||||
else
|
||||
cat <<-IPCONFIGnonvmware > "$INTERFACES"
|
||||
network:
|
||||
version: 2
|
||||
ethernets:
|
||||
|
@ -219,16 +248,32 @@ network:
|
|||
addresses: [$ADDRESS/24] # client IP address
|
||||
gateway4: $GATEWAY # gateway address
|
||||
nameservers:
|
||||
addresses: [$DNS1,$DNS2] #name servers
|
||||
addresses: [$DNSs] #name servers
|
||||
IPCONFIGnonvmware
|
||||
msg_box "These are your settings, please make sure they are correct:
|
||||
|
||||
msg_box "These are your settings, please make sure they are correct:
|
||||
|
||||
$(cat /etc/netplan/01-netcfg.yaml)"
|
||||
netplan try
|
||||
fi
|
||||
netplan try
|
||||
set_systemd_resolved_dns "$IFACE2"
|
||||
fi
|
||||
|
||||
if test_connection
|
||||
then
|
||||
sleep 1
|
||||
msg_box "Static IP sucessfully set!"
|
||||
fi
|
||||
if test_connection
|
||||
then
|
||||
sleep 1
|
||||
msg_box "Static IP sucessfully set!"
|
||||
break
|
||||
fi
|
||||
|
||||
cat << BADNETWORKTEXT
|
||||
|
||||
The network settings do not provide access to the Internet and/or the DNS
|
||||
servers are not reachable. Unless Wi-Fi is required and still to be configured
|
||||
proceeding will not succeed.
|
||||
|
||||
BADNETWORKTEXT
|
||||
if [[ "no" == $(ask_yes_or_no "Try new network settings?") ]]
|
||||
then
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
|
Загрузка…
Ссылка в новой задаче