-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdns_zones_setup
More file actions
51 lines (44 loc) · 1.6 KB
/
dns_zones_setup
File metadata and controls
51 lines (44 loc) · 1.6 KB
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
#!/bin/bash
# Prompt the user for input
read -p "Enter the domain name: " domain
read -p "Enter the IP address (of name server): " ip_address
read -p "Enter the name of the user on the DNS server: " username
# Define the paths
zones_folder="/etc/bind/zones"
forward_file="$zones_folder/forward.$domain"
reverse_file="$zones_folder/reverse.$domain"
# Check if the zones folder exists, create it if not
if [ ! -d "$zones_folder" ]; then
sudo mkdir -p "$zones_folder"
fi
# Create the forward lookup file
sudo bash -c "cat <<EOF > $forward_file
\$TTL 86400
@ IN SOA $domain root (
$(date +%Y%m%d%H) ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
86400 ) ; Minimum TTL
; Name Server Information
@ IN NS $username
ns1 IN A $ip_address
www IN A $ip_address
EOF"
# Create the reverse lookup file
sudo bash -c "cat <<EOF > $reverse_file
\$TTL 86400
@ IN SOA $domain. root.$domain. (
$(date +%Y%m%d%H) ; Serial
3600 ; Refresh
1800 ; Retry
604800 ; Expire
86400 ) ; Minimum TTL
; Name Server Information
@ IN NS $username.
$(echo $ip_address | awk -F. '{print $4}') IN PTR www.$domain.
$(echo $ip_address | awk -F. '{print $4}') IN PTR ns1.$domain.
EOF"
# Display a success message
echo "Forward lookup file created successfully at $forward_file."
echo "Manual addition of subdomains is REQUIRED for both forward and reverse lookups!"