NestedA.sh
#!/bin/bash
set -e
# Ensure the script is running as root
if [ "$(id -u)" -ne 0 ]; then
echo "This script must be run as root"
exit 1
fi
# Update system and install dependencies
apt update && apt upgrade -y
apt install -y unbound tor nginx certbot python3-certbot-nginx curl jq dnsutils bind9 bind9utils bind9-doc
# DOMAIN configuration
DOMAIN="REPLACEWITHYOURDOMAINHERE"
# Configure Unbound with DNSSEC
echo "Configuring Unbound with DNSSEC..."
cat <<EOF > /etc/unbound/unbound.conf
server:
verbosity: 1
interface: 0.0.0.0
access-control: 0.0.0.0/0 allow
port: 53
do-ip6: no
root-hints: /var/lib/unbound/root.hints
auto-trust-anchor-file: "/var/lib/unbound/root.key"
logfile: "/var/log/unbound.log"
log-time-ascii: yes
use-syslog: yes
log-level: 2
cache-min-ttl: 3600
cache-max-ttl: 86400
EOF
# Fetch DNSSEC root hints
wget -O /var/lib/unbound/root.hints https://www.internic.net/domain/named.root
touch /var/lib/unbound/root.key
# Obtain or renew SSL certificate using HTTP-01 challenge
echo "Obtaining or renewing SSL certificate using HTTP-01 challenge..."
certbot certonly --standalone --http-01-port 8080 -d $DOMAIN --agree-tos --no-eff-email --email [email protected]
# Generate DNSSEC Key with BIND tools
echo "Generating DNSSEC Key with BIND..."
cd /etc/bind
dnssec-keygen -a RSASHA256 -b 2048 -n ZONE $DOMAIN
# Find the key file generated by dnssec-keygen
KEY_FILE=$(ls K$DOMAIN.+008+*.key | head -n 1)
# Ensure the key file exists
if [ ! -f "$KEY_FILE" ]; then
echo "Key file $KEY_FILE not found!"
exit 1
fi
echo "Using key file: $KEY_FILE"
# Generate DS Record using dnssec-dsfromkey (locally)
echo "Generating DS record for DNSSEC..."
DS_RECORD=$(dnssec-dsfromkey -2 $KEY_FILE)
# Output the raw DS record for debugging
echo "Raw DS record: $DS_RECORD"
# Check if the DS Record was generated successfully
if [ $? -ne 0 ]; then
echo "Error generating DS record!"
exit 1
fi
# Extract the DS record contents using awk
DS_KEY_TAG=$(echo $DS_RECORD | awk '{print $3}')
DS_ALGORITHM=$(echo $DS_RECORD | awk '{print $4}')
DS_DIGEST_TYPE=$(echo $DS_RECORD | awk '{print $5}')
DS_DIGEST=$(echo $DS_RECORD | awk '{print $6}')
# Check if the DS fields are extracted correctly
if [ -z "$DS_KEY_TAG" ] || [ -z "$DS_ALGORITHM" ] || [ -z "$DS_DIGEST_TYPE" ] || [ -z "$DS_DIGEST" ]; then
echo "Error: Missing required DS record fields."
exit 1
fi
echo "DNSSEC setup completed successfully!"
# DNSSEC Nested Setup (local generation)
echo "Local DS record generated for nested DNSSEC setup:"
echo "$DS_KEY_TAG $DS_ALGORITHM $DS_DIGEST_TYPE $DS_DIGEST"
# Add DS record to your parent zone manually (for nested DNSSEC setup)
echo "Ensure that the DS record for $DOMAIN is added to your parent zone."
# Configure NGINX for SSL
echo "Configuring NGINX for SSL..."
cat <<EOF > /etc/nginx/sites-available/unbound
server {
listen 8080;
server_name $DOMAIN;
location / {
proxy_pass http://127.0.0.1:5335;
}
}
server {
listen 443 ssl;
server_name $DOMAIN;
ssl_certificate /etc/letsencrypt/live/$DOMAIN/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/$DOMAIN/privkey.pem;
location / {
proxy_pass http://127.0.0.1:5335;
}
}
EOF
# Ensure no existing symbolic link is in place before creating a new one
if [ -L /etc/nginx/sites-enabled/unbound ]; then
rm /etc/nginx/sites-enabled/unbound
fi
ln -s /etc/nginx/sites-available/unbound /etc/nginx/sites-enabled/
systemctl restart nginx
echo "[+] Setup completed."
NestedB1.sh
#!/bin/bash
# Ensure the script is running as root
if [ "$(id -u)" -ne 0 ]; then
echo "This script must be run as root"
exit 1
fi
# Update the system and install dependencies
apt update && apt upgrade -y
apt install -y unbound tor nginx certbot python3-certbot-nginx curl jq dnsutils
# Set up Cloudflare API for DNS record management
CLOUDFLARE_API_TOKEN="your-cloudflare-api-token"
CLOUDFLARE_ZONE_ID="your-cloudflare-zone-id"
DOMAIN="yourdomain.com"
# Function to create DNS record in Cloudflare
create_dns_record() {
local record_type=$1
local record_name=$2
local record_content=$3
local ttl=$4
curl -X POST "https://api.cloudflare.com/client/v4/zones/$CLOUDFLARE_ZONE_ID/dns_records" \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
-H "Content-Type: application/json" \
--data "{\"type\":\"$record_type\",\"name\":\"$record_name\",\"content\":\"$record_content\",\"ttl\":$ttl,\"proxied\":false}"
}
# Set up Unbound with DNSSEC and CA-signed certificate
echo "Configuring Unbound with DNSSEC and CA-signed certificate..."
# Backup current Unbound config
cp /etc/unbound/unbound.conf /etc/unbound/unbound.conf.bak
# Update Unbound config for DNSSEC
cat <<EOF > /etc/unbound/unbound.conf
server:
verbosity: 1
interface: 0.0.0.0
access-control: 0.0.0.0/0 allow
port: 53
do-ip6: no
root-hints: /var/lib/unbound/root.hints
auto-trust-anchor-file: "/var/lib/unbound/root.key"
logfile: "/var/log/unbound.log"
log-time-ascii: yes
use-syslog: yes
log-level: 2
cache-min-ttl: 3600
cache-max-ttl: 86400
edns-buffer-size: 1232
prefetch: yes
prefetch-key: yes
trust-anchor-file: "/etc/unbound/trust-anchor.pem"
include: /etc/unbound/unbound.conf.d/*.conf
EOF
# Fetch root hints and trust anchor
wget -O /var/lib/unbound/root.hints https://www.internic.net/domain/named.root
touch /var/lib/unbound/root.key
# Dynamically fetch the CA DNSSEC trust anchor (example for Let's Encrypt)
curl -s https://letsencrypt.org/certificates/lets-encrypt-x3-cross-signed.pem > /etc/unbound/trust-anchor.pem
# Install certificate via Certbot
echo "Obtaining SSL certificate via Certbot..."
# Replace 'yourdomain.com' with your domain
certbot certonly --standalone -d $DOMAIN --agree-tos --no-eff-email --email [email protected]
# Generate DS record from DNSSEC key
echo "Generating DS record for DNSSEC..."
# First, generate the DS record
dnssec-dsfromkey -2 /etc/letsencrypt/live/$DOMAIN/privkey.pem > /etc/unbound/ds-record.txt
# Extract the DS record from the file
DS_RECORD_CONTENT=$(cat /etc/unbound/ds-record.txt)
# Create the DS record in Cloudflare
create_dns_record "DS" "$DOMAIN" "$DS_RECORD_CONTENT" 3600
# Configure NGINX to use SSL and serve Unbound DNSSEC
echo "Configuring NGINX for SSL..."
cat <<EOF > /etc/nginx/sites-available/unbound
server {
listen 80;
server_name $DOMAIN;
location / {
proxy_pass http://127.0.0.1:53;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
}
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
}
server {
listen 443 ssl;
server_name $DOMAIN;
ssl_certificate /etc/letsencrypt/live/$DOMAIN/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/$DOMAIN/privkey.pem;
location / {
proxy_pass http://127.0.0.1:53;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
}
}
EOF
# Enable and start NGINX
ln -s /etc/nginx/sites-available/unbound /etc/nginx/sites-enabled/
systemctl restart nginx
# Set up Tor and configure strict routing (following script2 rules)
echo "Configuring Tor routing logic with strict mode and routing rules..."
# Backup current Tor config
cp /etc/tor/torrc /etc/tor/torrc.bak
cat <<EOF > /etc/tor/torrc
# Use the default Tor configuration
SocksPort 9050
Log notice stdout
RunAsDaemon 1
ExitNodes {us}
StrictNodes 1
ControlPort 9051
CookieAuthentication 1
DataDirectory /var/lib/tor
# Ensure all traffic routes through Tor
TransPort 9040
DNSPort 53
AutomapHostsOnResolve 1
DNSExitNode 1
EOF
# Restart Tor service
systemctl restart tor
# Set up Unbound to forward DNS queries to Tor
echo "Configuring Unbound to use Tor for DNS queries..."
# Update Unbound config to route DNS queries through Tor
cat <<EOF >> /etc/unbound/unbound.conf.d/tor.conf
forward-zone:
name: "."
forward-addr: 127.0.0.1@9053
EOF
# Restart Unbound
systemctl restart unbound
# Configure logs for debugging
echo "Setting up logs for debugging..."
# Create log file for Unbound
touch /var/log/unbound.log
chmod 640 /var/log/unbound.log
# Create log file for Tor
touch /var/log/tor.log
chmod 640 /var/log/tor.log
# Create log file for NGINX
touch /var/log/nginx/access.log
touch /var/log/nginx/error.log
chmod 640 /var/log/nginx/*.log
# Enable services to start on boot
systemctl enable unbound
systemctl enable tor
systemctl enable nginx
# Output success message
echo "Configuration complete. Your Unbound DNSSEC server is now running with a CA-signed certificate and Tor routing enabled."
echo "Logs for debugging are available at /var/log/unbound.log, /var/log/tor.log, and /var/log/nginx/."
# Dynamically create DNS records for your domain via Cloudflare API (A record and DS record for DNSSEC)
echo "Creating DNS records for $DOMAIN..."
# Create A record for the domain
create_dns_record "A" "$DOMAIN" "$(curl -s ifconfig.me)" 3600
echo "DNS records created in Cloudflare. Please check your domain to confirm everything is set up."
NestedB2.sh
#!/bin/bash
# Ensure the script is running as root
if [ "$(id -u)" -ne 0 ]; then
echo "This script must be run as root"
exit 1
fi
# Update the system and install dependencies
apt update && apt upgrade -y
apt install -y unbound tor nginx certbot python3-certbot-nginx curl jq
# Set up Cloudflare API for DNS record management
CLOUDFLARE_API_TOKEN="your-cloudflare-api-token"
CLOUDFLARE_ZONE_ID="your-cloudflare-zone-id"
DOMAIN="yourdomain.com"
# Function to create DNS record in Cloudflare
create_dns_record() {
local record_type=$1
local record_name=$2
local record_content=$3
local ttl=$4
curl -X POST "https://api.cloudflare.com/client/v4/zones/$CLOUDFLARE_ZONE_ID/dns_records" \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
-H "Content-Type: application/json" \
--data "{\"type\":\"$record_type\",\"name\":\"$record_name\",\"content\":\"$record_content\",\"ttl\":$ttl,\"proxied\":false}"
}
# Set up Unbound with DNSSEC and CA-signed certificate
echo "Configuring Unbound with DNSSEC and CA-signed certificate..."
# Backup current Unbound config
cp /etc/unbound/unbound.conf /etc/unbound/unbound.conf.bak
# Update Unbound config for DNSSEC
cat <<EOF > /etc/unbound/unbound.conf
server:
verbosity: 1
interface: 0.0.0.0
access-control: 0.0.0.0/0 allow
port: 53
do-ip6: no
root-hints: /var/lib/unbound/root.hints
auto-trust-anchor-file: "/var/lib/unbound/root.key"
logfile: "/var/log/unbound.log"
log-time-ascii: yes
use-syslog: yes
log-level: 2
cache-min-ttl: 3600
cache-max-ttl: 86400
edns-buffer-size: 1232
prefetch: yes
prefetch-key: yes
trust-anchor-file: "/etc/unbound/trust-anchor.pem"
include: /etc/unbound/unbound.conf.d/*.conf
EOF
# Fetch root hints and trust anchor
wget -O /var/lib/unbound/root.hints https://www.internic.net/domain/named.root
touch /var/lib/unbound/root.key
# Dynamically fetch the CA DNSSEC trust anchor (example for Let's Encrypt)
curl -s https://letsencrypt.org/certificates/lets-encrypt-x3-cross-signed.pem > /etc/unbound/trust-anchor.pem
# Install certificate via Certbot
echo "Obtaining SSL certificate via Certbot..."
# Replace 'yourdomain.com' with your domain
certbot certonly --standalone -d $DOMAIN --agree-tos --no-eff-email --email [email protected]
# Configure NGINX to use SSL and serve Unbound DNSSEC
echo "Configuring NGINX for SSL..."
cat <<EOF > /etc/nginx/sites-available/unbound
server {
listen 80;
server_name $DOMAIN;
location / {
proxy_pass http://127.0.0.1:53;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
}
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
}
server {
listen 443 ssl;
server_name $DOMAIN;
ssl_certificate /etc/letsencrypt/live/$DOMAIN/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/$DOMAIN/privkey.pem;
location / {
proxy_pass http://127.0.0.1:53;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
}
}
EOF
# Enable and start NGINX
ln -s /etc/nginx/sites-available/unbound /etc/nginx/sites-enabled/
systemctl restart nginx
# Set up Tor and configure strict routing (following script2 rules)
echo "Configuring Tor routing logic with strict mode and routing rules..."
# Backup current Tor config
cp /etc/tor/torrc /etc/tor/torrc.bak
cat <<EOF > /etc/tor/torrc
# Use the default Tor configuration
SocksPort 9050
Log notice stdout
RunAsDaemon 1
ExitNodes {us}
StrictNodes 1
ControlPort 9051
CookieAuthentication 1
DataDirectory /var/lib/tor
# Ensure all traffic routes through Tor
TransPort 9040
DNSPort 53
AutomapHostsOnResolve 1
DNSExitNode 1
EOF
# Restart Tor service
systemctl restart tor
# Set up Unbound to forward DNS queries to Tor
echo "Configuring Unbound to use Tor for DNS queries..."
# Update Unbound config to route DNS queries through Tor
cat <<EOF >> /etc/unbound/unbound.conf.d/tor.conf
forward-zone:
name: "."
forward-addr: 127.0.0.1@9053
EOF
# Restart Unbound
systemctl restart unbound
# Configure logs for debugging
echo "Setting up logs for debugging..."
# Create log file for Unbound
touch /var/log/unbound.log
chmod 640 /var/log/unbound.log
# Create log file for Tor
touch /var/log/tor.log
chmod 640 /var/log/tor.log
# Create log file for NGINX
touch /var/log/nginx/access.log
touch /var/log/nginx/error.log
chmod 640 /var/log/nginx/*.log
# Enable services to start on boot
systemctl enable unbound
systemctl enable tor
systemctl enable nginx
# Output success message
echo "Configuration complete. Your Unbound DNSSEC server is now running with a CA-signed certificate and Tor routing enabled."
echo "Logs for debugging are available at /var/log/unbound.log, /var/log/tor.log, and /var/log/nginx/."
# Dynamically create DNS records for your domain via Cloudflare API (A record and DS record for DNSSEC)
echo "Creating DNS records for $DOMAIN..."
# Create A record for the domain
create_dns_record "A" "$DOMAIN" "$(curl -s ifconfig.me)" 3600
# Create DS record for DNSSEC
DS_RECORD_CONTENT="your-ds-record-here" # Replace with your actual DS record
create_dns_record "DS" "$DOMAIN" "$DS_RECORD_CONTENT" 3600
echo "DNS records created in Cloudflare. Please check your domain to confirm everything is set up."
NestedB3.sh
#!/bin/bash
# Ensure the script is running as root
if [ "$(id -u)" -ne 0 ]; then
echo "This script must be run as root"
exit 1
fi
# Update the system and install dependencies
apt update && apt upgrade -y
apt install -y unbound tor nginx certbot python3-certbot-nginx curl jq
# Set up Cloudflare API for DNS record management
CLOUDFLARE_API_TOKEN="your-cloudflare-api-token"
CLOUDFLARE_ZONE_ID="your-cloudflare-zone-id"
DOMAIN="yourdomain.com"
# Function to create DNS record in Cloudflare
create_dns_record() {
local record_type=$1
local record_name=$2
local record_content=$3
local ttl=$4
curl -X POST "https://api.cloudflare.com/client/v4/zones/$CLOUDFLARE_ZONE_ID/dns_records" \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
-H "Content-Type: application/json" \
--data "{\"type\":\"$record_type\",\"name\":\"$record_name\",\"content\":\"$record_content\",\"ttl\":$ttl,\"proxied\":false}"
}
# Set up Unbound with DNSSEC and CA-signed certificate
echo "Configuring Unbound with DNSSEC and CA-signed certificate..."
# Backup current Unbound config
cp /etc/unbound/unbound.conf /etc/unbound/unbound.conf.bak
# Update Unbound config for DNSSEC
cat <<EOF > /etc/unbound/unbound.conf
server:
verbosity: 1
interface: 0.0.0.0
access-control: 0.0.0.0/0 allow
port: 53
do-ip6: no
root-hints: /var/lib/unbound/root.hints
auto-trust-anchor-file: "/var/lib/unbound/root.key"
logfile: "/var/log/unbound.log"
log-time-ascii: yes
use-syslog: yes
log-level: 2
cache-min-ttl: 3600
cache-max-ttl: 86400
edns-buffer-size: 1232
prefetch: yes
prefetch-key: yes
trust-anchor-file: "/etc/unbound/trust-anchor.pem"
include: /etc/unbound/unbound.conf.d/*.conf
EOF
# Fetch root hints and trust anchor
wget -O /var/lib/unbound/root.hints https://www.internic.net/domain/named.root
touch /var/lib/unbound/root.key
# Dynamically fetch the CA DNSSEC trust anchor (example for Let's Encrypt)
curl -s https://letsencrypt.org/certificates/lets-encrypt-x3-cross-signed.pem > /etc/unbound/trust-anchor.pem
# Install certificate via Certbot
echo "Obtaining SSL certificate via Certbot..."
# Replace 'yourdomain.com' with your domain
certbot certonly --standalone -d $DOMAIN --agree-tos --no-eff-email --email [email protected]
# Configure NGINX to use SSL and serve Unbound DNSSEC
echo "Configuring NGINX for SSL..."
cat <<EOF > /etc/nginx/sites-available/unbound
server {
listen 80;
server_name $DOMAIN;
location / {
proxy_pass http://127.0.0.1:53;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
}
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
}
server {
listen 443 ssl;
server_name $DOMAIN;
ssl_certificate /etc/letsencrypt/live/$DOMAIN/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/$DOMAIN/privkey.pem;
location / {
proxy_pass http://127.0.0.1:53;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
}
}
EOF
# Enable and start NGINX
ln -s /etc/nginx/sites-available/unbound /etc/nginx/sites-enabled/
systemctl restart nginx
# Set up Tor and configure strict routing (following script2 rules)
echo "Configuring Tor routing logic with strict mode and routing rules..."
# Backup current Tor config
cp /etc/tor/torrc /etc/tor/torrc.bak
cat <<EOF > /etc/tor/torrc
# Use the default Tor configuration
SocksPort 9050
Log notice stdout
RunAsDaemon 1
ExitNodes {us}
StrictNodes 1
ControlPort 9051
CookieAuthentication 1
DataDirectory /var/lib/tor
# Ensure all traffic routes through Tor
TransPort 9040
DNSPort 53
AutomapHostsOnResolve 1
DNSExitNode 1
EOF
# Restart Tor service
systemctl restart tor
# Set up Unbound to forward DNS queries to Tor
echo "Configuring Unbound to use Tor for DNS queries..."
# Update Unbound config to route DNS queries through Tor
cat <<EOF >> /etc/unbound/unbound.conf.d/tor.conf
forward-zone:
name: "."
forward-addr: 127.0.0.1@9053
EOF
# Restart Unbound
systemctl restart unbound
# Configure logs for debugging
echo "Setting up logs for debugging..."
# Create log file for Unbound
touch /var/log/unbound.log
chmod 640 /var/log/unbound.log
# Create log file for Tor
touch /var/log/tor.log
chmod 640 /var/log/tor.log
# Create log file for NGINX
touch /var/log/nginx/access.log
touch /var/log/nginx/error.log
chmod 640 /var/log/nginx/*.log
# Enable services to start on boot
systemctl enable unbound
systemctl enable tor
systemctl enable nginx
# Output success message
echo "Configuration complete. Your Unbound DNSSEC server is now running with a CA-signed certificate and Tor routing enabled."
echo "Logs for debugging are available at /var/log/unbound.log, /var/log/tor.log, and /var/log/nginx/."
# Dynamically create DNS records for your domain via Cloudflare API (A record and DS record for DNSSEC)
echo "Creating DNS records for $DOMAIN..."
# Create A record for the domain
create_dns_record "A" "$DOMAIN" "$(curl -s ifconfig.me)" 3600
# Create DS record for DNSSEC
DS_RECORD_CONTENT="your-ds-record-here" # Replace with your actual DS record
create_dns_record "DS" "$DOMAIN" "$DS_RECORD_CONTENT" 3600
echo "DNS records created in Cloudflare. Please check your domain to confirm everything is set up."
NestedB4.sh
#!/bin/bash
# Ensure the script is running as root
if [ "$(id -u)" -ne 0 ]; then
echo "This script must be run as root"
exit 1
fi
# Update the system and install dependencies
apt update && apt upgrade -y
apt install -y unbound tor nginx certbot python3-certbot-nginx
# Set up Unbound with nested, ported DNSSEC (self-signed inside CA DNSSEC)
echo "Configuring Unbound with nested, encrypted DNSSEC..."
# Backup current Unbound config
cp /etc/unbound/unbound.conf /etc/unbound/unbound.conf.bak
# Update Unbound config for nested DNSSEC
cat <<EOF > /etc/unbound/unbound.conf
server:
verbosity: 1
interface: 0.0.0.0
access-control: 0.0.0.0/0 allow
port: 53
do-ip6: no
root-hints: /var/lib/unbound/root.hints
auto-trust-anchor-file: "/var/lib/unbound/root.key"
logfile: "/var/log/unbound.log"
log-time-ascii: yes
use-syslog: yes
log-level: 2
cache-min-ttl: 3600
cache-max-ttl: 86400
edns-buffer-size: 1232
prefetch: yes
prefetch-key: yes
trust-anchor-file: "/etc/unbound/trust-anchor.pem"
include: /etc/unbound/unbound.conf.d/*.conf
# Local DNSSEC (Self-Signed, Encrypted and Tamper-Evident)
# This is your local zone's DNSSEC setup, fully encrypted and tamper-evident.
local-zone: "local." transparent
local-data: "local. IN DS 12345 8 2 56789abcdef1234567890abcdef1234567890abcdef1234567890"
local-data: "local. IN A 127.0.0.1"
# Nested DNSSEC with CA Signed Setup
# Forwarding DNS queries to Tor resolver (uses Tor's DNS port)
forward-zone:
name: "."
forward-addr: 127.0.0.1@9053
# Nested encrypted DNSSEC setup, nested into CA DNSSEC
trust-anchor: "shp://root-anchors.dnssec" # Here you specify your encrypted and tamper-evident DNSSEC anchor file for internal zones
EOF
# Fetch root hints and trust anchor
wget -O /var/lib/unbound/root.hints https://www.internic.net/domain/named.root
touch /var/lib/unbound/root.key
# Install certificate via Certbot
echo "Obtaining SSL certificate via Certbot..."
# Replace 'yourdomain.com' with your domain
certbot certonly --standalone -d yourdomain.com --agree-tos --no-eff-email --email [email protected]
# Configure NGINX to use SSL and serve Unbound DNSSEC
echo "Configuring NGINX for SSL..."
cat <<EOF > /etc/nginx/sites-available/unbound
server {
listen 80;
server_name yourdomain.com;
location / {
proxy_pass http://127.0.0.1:53;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
}
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
}
server {
listen 443 ssl;
server_name yourdomain.com;
ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem;
location / {
proxy_pass http://127.0.0.1:53;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
}
}
EOF
# Enable and start NGINX
ln -s /etc/nginx/sites-available/unbound /etc/nginx/sites-enabled/
systemctl restart nginx
# Set up Tor and configure strict routing (following script2 rules)
echo "Configuring Tor routing logic with strict mode and routing rules..."
# Backup current Tor config
cp /etc/tor/torrc /etc/tor/torrc.bak
cat <<EOF > /etc/tor/torrc
# Use the default Tor configuration
SocksPort 9050
Log notice stdout
RunAsDaemon 1
ExitNodes {us}
StrictNodes 1
ControlPort 9051
CookieAuthentication 1
DataDirectory /var/lib/tor
# Ensure all traffic routes through Tor
TransPort 9040
DNSPort 53
AutomapHostsOnResolve 1
DNSExitNode 1
EOF
# Restart Tor service
systemctl restart tor
# Set up Unbound to forward DNS queries to Tor
echo "Configuring Unbound to use Tor for DNS queries..."
# Update Unbound config to route DNS queries through Tor
cat <<EOF >> /etc/unbound/unbound.conf.d/tor.conf
forward-zone:
name: "."
forward-addr: 127.0.0.1@9053
EOF
# Restart Unbound
systemctl restart unbound
# Configure logs for debugging
echo "Setting up logs for debugging..."
# Create log file for Unbound
touch /var/log/unbound.log
chmod 640 /var/log/unbound.log
# Create log file for Tor
touch /var/log/tor.log
chmod 640 /var/log/tor.log
# Create log file for NGINX
touch /var/log/nginx/access.log
touch /var/log/nginx/error.log
chmod 640 /var/log/nginx/*.log
# Enable services to start on boot
systemctl enable unbound
systemctl enable tor
systemctl enable nginx
# Output success message
echo "Configuration complete. Your Unbound DNSSEC server is now running with nested, encrypted DNSSEC and CA-signed DNSSEC enabled."
echo "Logs for debugging are available at /var/log/unbound.log, /var/log/tor.log, and /var/log/nginx/."