-
Notifications
You must be signed in to change notification settings - Fork 0
/
ubuntu2004-test-domain.sh
79 lines (66 loc) · 2 KB
/
ubuntu2004-test-domain.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/bin/bash
set -e
ZONE=".devenv.test"
END="\033[0m"
BLACK="\033[0;30m"
BLACKB="\033[1;30m"
WHITE="\033[0;37m"
WHITEB="\033[1;37m"
RED="\033[0;31m"
REDB="\033[1;31m"
GREEN="\033[0;32m"
GREENB="\033[1;32m"
YELLOW="\033[0;33m"
YELLOWB="\033[1;33m"
BLUE="\033[0;34m"
BLUEB="\033[1;34m"
PURPLE="\033[0;35m"
PURPLEB="\033[1;35m"
LIGHTBLUE="\033[0;36m"
LIGHTBLUEB="\033[1;36m"
ERROR="${RED}Error:${END}"
function error
{
echo -e "$ERROR ${REDB}${1}${END}"
exit 1
}
INFO="${LIGHTBLUE}[INFO]${END}"
function info
{
echo -e "${LIGHTBLUE}${1}${END}"
}
function success
{
echo -e "${GREEN}${1}${END}"
}
function ok
{
echo -e "${LIGHTBLUE}- ${GREEN}OK${LIGHTBLUE}${END}"
}
if ! command -v lsb_release &> /dev/null; then
error "lsb_release could not be found (not running on Ubuntu 20.04)."
fi
if [[ $(lsb_release -rs) == "20.04" ]]; then
success "Ubuntu 20.04 detected."
else
lsb_release -a
error "Incompatible OS Version."
fi
info "Installing ${YELLOW}dnsmasq${LIGHTBLUE} (sudo password might be required)."
sudo apt-get -y dnsmasq || error "Failed to install dnsmasq" ; ok
info "Setting up dnsmasq to resolve ${YELLOW}${ZONE}${LIGHTBLUE} zone as 127.0.0.1."
sudo echo "address=/${ZONE}/127.0.0.1" >> "/etc/dnsmasq.d/custom-zone"
sudo echo "port=53" >> "/etc/dnsmasq.d/custom-zone"
ok
info "Starting dnsmasq daemon (sudo password will be required)."
sudo systemctl enable --now dnsmasq || error "Failed to enable and/or start dnsmasq"; ok
info "Creating resolver."
sudo mkdir -pv /etc/systemd/resolved.conf.d
sudo bash -c "echo \"[Resolve]\" > /etc/systemd/resolved.conf.d/dns_servers.conf"
sudo bash -c "echo \"DNS=127.0.0.1\" >> /etc/systemd/resolved.conf.d/dns_servers.conf"
sudo bash -c "echo \"Domains=${ZONE:1}\" >> /etc/systemd/resolved.conf.d/dns_servers.conf"
ok
success
success "That's it! You can run ${YELLOWB}resolvectl status${GREEN} to show all your current resolvers,"
success "and you should see that all requests for a domain ending in ${YELLOWB}${ZONE}${GREEN} will go"
success "to the DNS server at 127.0.0.1"