Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom DNS #2701

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ permalink: /docs/en-US/changelog/

# Changelog

## 3.13 ( 2023 December TBA )
## 3.13 ( 2024 TBA )

### Enhancements

Expand All @@ -17,6 +17,10 @@ permalink: /docs/en-US/changelog/
* Opted out of Dotnet package telemetry ( #2689 )
* Replace references to the Squizlab PHPCS with that from the PHPCS Standards org ( #2692 )

### Maintenance

* Switch the Parallels Arm64 box from `mpasternak/focal64-arm` to `bento/ubuntu-22.04-arm64` to match x86 boxes ( #2695 )

### Bug Fixes

* The host file inside the VM was only adding sites with `127.0.0.1` addresses, now it adds the IPVv6 `::1` too ( #2689 )
Expand Down
2 changes: 1 addition & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
# this seems to be the most reliable way to detect whether or not we're
# running under ARM64.
if Etc.uname[:version].include? 'ARM64'
override.vm.box = 'mpasternak/focal64-arm'
override.vm.box = 'bento/ubuntu-20.04-arm64'
end
end

Expand Down
65 changes: 65 additions & 0 deletions provision/core/env/provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
set -eo pipefail

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
DNS_SERVERS=(
# Quad9
"9.9.9.9"
"149.112.112.112"
"2620:fe::fe"
"2620:fe::9"

# Cloudflare
"1.1.1.1"
"1.0.0.2"
"2606:4700:4700::1112"
"2606:4700:4700::1002"
)

# @description Adds the homebin folder to PATH
# @noargs
Expand All @@ -24,6 +37,57 @@ function setup_vvv_env() {
/etc/environment
}

# Function to test DNS resolution for a specified domain
function vvv_check_domain_dns() {
local domain="${1}"

if [ -z "${domain}" ]; then
vvv_Error "Error: No domain provided."
return 1
fi

if command -v nslookup &> /dev/null; then
nslookup "${domain}" >/dev/null 2>&1
elif command -v dig &> /dev/null; then
dig +short "${domain}" >/dev/null 2>&1
else
vvv_error "Error: Neither nslookup nor dig is available."
return 1
fi
}

# @description Tests for working DNS and re-configures on failure
function setup_dns() {
if vvv_check_domain_dns "github.com" && vvv_check_domain_dns "ppa.launchpadcontent.net"; then
return
fi

vvv_warn "Could not resolve github.com or ppa.launchpadcontent.net domains via DNS, configuring 3rd party DNS resolvers."

DNS_SERVERS_TO_ADD=()

# Test reachability of DNS servers
for dns_server in "${DNS_SERVERS[@]}"; do
if ping -c 1 -W 2 "${dns_server}" >/dev/null 2>&1; then
echo "DNS server ${dns_server} is reachable"
DNS_SERVERS_TO_ADD+=("${dns_server}")
fi
done

vvv_info "Adding DNS Servers: ${DNS_SERVERS_TO_ADD[*]}"

for file in /etc/netplan/*.yaml; do
for dns_server in "${DNS_SERVERS_TO_ADD[@]}"; do
if ! grep -qF "${dns_server}" "${file}"; then
sed -i "/nameservers:/a \ \ \ \ addresses: [${dns_server}]" "${file}"
echo "DNS updated to ${dns_server} in ${file}"
fi
done
done

netplan apply
}

# @description Remove MOTD output from Ubuntu and add our own
# @noargs
function cleanup_terminal_splash() {
Expand Down Expand Up @@ -116,6 +180,7 @@ function profile_setup() {
function vvv_init_profile() {
# Profile_setup
vvv_info " * Bash profile setup and directories."
setup_dns
setup_vvv_env
cleanup_terminal_splash
profile_setup
Expand Down
Loading