-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEnglish_Version.py
73 lines (73 loc) · 2.86 KB
/
English_Version.py
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
import os
from shutil import copyfile
# Define the paths to the zone files and the named.conf.local file
zone_file_path = '/etc/bind/db.integris.ptt'
reverse_zone_file_path = '/etc/bind/db.192.168.183'
named_conf_local_path = '/etc/bind/named.conf.local'
# Define the content for the forward zone file
zone_file_content = f"""
$TTL 604800
@ IN SOA ns.integris.ptt. root.integris.ptt. (
2 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns.integris.ptt.
ns IN A 192.168.183.17
www IN A 192.168.183.17
@ IN A 192.168.183.17
"""
# Define the content for the reverse zone file
reverse_zone_file_content = f"""
$TTL 604800
@ IN SOA ns.integris.ptt. root.integris.ptt. (
2 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
@ IN NS ns.integris.ptt.
17.183.168.192.in-addr.arpa. IN PTR www.integris.ptt.
"""
# Define the content to be appended to named.conf.local for the new zones
named_conf_local_content = f"""
zone "integris.ptt" {{
type master;
file "{zone_file_path}";
}};
zone "183.168.192.in-addr.arpa" {{
type master;
file "{reverse_zone_file_path}";
}};
"""
# Function to create and write the zone files and named.conf.local
def create_zone_files():
with open(zone_file_path, 'w') as zone_file:
zone_file.write(zone_file_content)
with open(reverse_zone_file_path, 'w') as reverse_zone_file:
reverse_zone_file.write(reverse_zone_file_content)
with open(named_conf_local_path, 'a') as named_conf_local:
named_conf_local.write(named_conf_local_content)
# Function to restart the Bind9 service
def restart_bind9():
os.system('sudo systemctl restart bind9')
# Main function to backup existing files, create new files, and restart Bind9
def main():
# Backup original files if they exist
if os.path.exists(zone_file_path):
copyfile(zone_file_path, f"{zone_file_path}.bak")
if os.path.exists(reverse_zone_file_path):
copyfile(reverse_zone_file_path, f"{reverse_zone_file_path}.bak")
if os.path.exists(named_conf_local_path):
copyfile(named_conf_local_path, f"{named_conf_local_path}.bak")
# Create new zone files and append to named.conf.local
create_zone_files()
# Restart Bind9 to apply the new configuration
restart_bind9()
print("DNS configuration applied successfully.")
# Run the main function when the script is executed
if __name__ == "__main__":
main()