-
Notifications
You must be signed in to change notification settings - Fork 0
/
dns-over-https.bash
193 lines (174 loc) · 8 KB
/
dns-over-https.bash
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/bin/bash
sudo apt update
echo "[+] Install ansible"
sudo apt -y install ansible
echo "[+] Installing NGINX as proxy"
sudo add-apt-repository ppa:ondrej/nginx -y
sudo apt -y install nginx-full
# Create self-signed certificate
#sudo openssl req -new -newkey rsa:4096 -days 365 -nodes -x509 \
# -subj "/C=EE/ST=Harjumaa/L=Tallinn/O=TalTech/CN=192.168.0.10" \
# -addext "subjectAltName = IP:192.168.0.10" \
# -keyout /etc/ssl/private/192.168.0.10.key -out /etc/ssl/certs/192.168.0.10.crt
cat << EOF > /etc/ssl/certs/192.168.0.10.crt
-----BEGIN CERTIFICATE-----
MIIFqDCCA5CgAwIBAgIUYnQfjP+J+MOrPMu7q5vBqOEOKNcwDQYJKoZIhvcNAQEL
BQAwWzELMAkGA1UEBhMCRUUxETAPBgNVBAgMCEhhcmp1bWFhMRAwDgYDVQQHDAdU
YWxsaW5uMRAwDgYDVQQKDAdUYWxUZWNoMRUwEwYDVQQDDAwxOTIuMTY4LjAuMTAw
HhcNMjIwNTA3MDgyNDI0WhcNMjMwNTA3MDgyNDI0WjBbMQswCQYDVQQGEwJFRTER
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IBAQDbiPSFCKySEdlAZUB0
nIlfE7jUejN3o9Os3wgiZRSjZ3PyGuPsFKzGv6nIeO/EyCfveS+crkpIYiLT82+J
CGl/WdOhl6ImaFqnakYztd5oCJ7RC2EeY2iI5PO6fdoTpX18lNOlstvVAUq4fXaf
fqxsNTE8ssbDNKxKm+JQWXlm6gQNJ381VuXc78sgkvHzAyWuwi/RsRCIT7Qfv9gn
/bUvHA4ccRMZYewtv9ShKy5Sqs7h6gZsoC1qfJyYXLz0gAs/fPZ0AA2u33pKcft6
vPqHhwVz2mwGGLvp1z76p1BjmeF2Iow6QVOyESClt1GWr5wEzbc9K71rr8OtJ9NR
GJjvAoIBAQDdOOSQ/SobwLxx09BjSgBnf+xuj7qiqeEOcLiXc8+Oq5ZeqakGRNev
h+lJtXvF9rbvJWgnG/v9mxv8ueWXQFkXNnaPmYDmFCAlgV/Xl5G58+0cDcAVKTAd
iiKdL1avOlCdSOdSTaaRI/BV9hedX6msEge5o95tlBktJg9Q6gD0qI9FrywhVDMz
nVW6bshAgH0BAiaaASVc4iiPhkNmEq9wZwSUngFva302iv5r+47qYtZFj6hVJrJH
LLnvDZ9BmiY27HAiofU7issGBvieplIIm5lzeuy9jXihE0ujEYAfb/B55b+V/sZd
sYmqdTvYWQOrh0xv2UsOv8kM8IB81Vp7
-----END PRIVATE KEY-----
EOF
# Configure NGINX
cat << EOF > /etc/nginx/sites-available/dns-over-https
upstream dns-backend {
server 127.0.0.1:8053;
}
server {
listen 443 ssl;
server_name 192.168.0.10;
ssl_certificate /etc/ssl/certs/192.168.0.10.crt;
ssl_certificate_key /etc/ssl/private/192.168.0.10.key;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
root /var/www/html/dns;
access_log /var/log/nginx/dns.access.log;
location /dns-query {
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header Host \$http_host;
proxy_set_header X-NginX-Proxy true;
proxy_http_version 1.1;
proxy_set_header Upgrade \$http_upgrade;
proxy_redirect off;
proxy_set_header X-Forwarded-Proto \$scheme;
proxy_read_timeout 86400;
proxy_pass http://dns-backend/dns-query ;
}
}
EOF
rm /etc/nginx/sites-enabled/default
ln -s /etc/nginx/sites-available/dns-over-https /etc/nginx/sites-enabled/
sudo systemctl restart nginx
echo "[+] Installing DoH server"
# Install GO
curl -OL https://golang.org/dl/go1.16.7.linux-amd64.tar.gz
sudo tar -C /usr/local -xvf go1.16.7.linux-amd64.tar.gz
export PATH=$PATH:/usr/local/go/bin
go version
mkdir ~/gopath
export GOPATH=~/gopath
# Install dns-over-https server
git clone https://github.com/m13253/dns-over-https.git
cd dns-over-https/
make
sudo make install
# Confiugure dns-over-https server
cat << EOF > /etc/dns-over-https/doh-server.conf
listen = [
"127.0.0.1:8053",
"[::1]:8053",
]
local_addr = ""
cert = ""
key = ""
path = "/dns-query"
upstream = [
"udp:192.168.0.20:53",
]
timeout = 10
tries = 3
verbose = true
log_guessed_client_ip = false
ecs_allow_non_global_ip = false
ecs_use_precise_ip = false
EOF
# Setup DoH logging
cat << EOF > /etc/rsyslog.d/99-doh.conf
:syslogtag, startswith, "doh-server" /var/log/doh-server.log
EOF
sudo systemctl restart rsyslog
# Enable/disable, start/stop systemd services
sudo systemctl disable systemd-resolved
sudo systemctl enable doh-server.service
systemctl daemon-reload