this repo has no description
1# DNS, Rsync, and Cron Services
2
3## DNS Service (BIND)
4
5### Service Name
6- `named` (most distributions)
7
8### Configuration Location
9- Ubuntu: `/etc/bind/`
10- CentOS: May be in different location
11
12### Check Service
13```bash
14systemctl status named
15```
16
17### Basic Concept
18DNS translates domain names to IP addresses (forward lookup) and IP addresses to domain names (reverse lookup).
19
20**Forward lookup**: `example.com` → `192.168.1.100`
21**Reverse lookup**: `192.168.1.100` → `example.com`
22
23### Key Files (Bind)
24- `named.conf` - Main configuration
25- Zone files - Define DNS records for domains
26
27**This is a complex service** - requires understanding of:
28- Zone files
29- DNS record types (A, PTR, CNAME, MX, etc.)
30- Forward vs reverse zones
31- DNS hierarchy
32
33---
34
35## Rsync - File Synchronization/Backup
36
37### Basic Syntax
38```bash
39rsync [options] source destination
40```
41
42### Common Options
43```bash
44-a # Archive mode (preserves permissions, timestamps, etc.)
45-v # Verbose (show what's being copied)
46-z # Compress during transfer
47-r # Recursive (copy directories)
48-h # Human-readable output
49--delete # Delete files in dest that don't exist in source
50```
51
52### Local Backup Example
53```bash
54rsync -av /home/user/stuff/ /home/user/backups/
55```
56
57**Note the trailing slash** on source - affects behavior:
58- `/source/` - copy contents of source
59- `/source` - copy source directory itself
60
61### Remote Backup via SSH
62```bash
63rsync -avz /local/path/ user@remote:/remote/path/
64```
65
66### Consistency vs. Accumulation
67
68**Consistency** (mirror - deletes old files):
69```bash
70rsync -av --delete /source/ /backup/
71```
72
73**Accumulation** (keeps all files):
74```bash
75rsync -av /source/ /backup/
76```
77
78### Check Installed
79```bash
80rsync --version
81# or just run rsync to see options
82```
83
84---
85
86## Cron - Task Automation
87
88### Service Name
89- `cron` (Ubuntu/Debian)
90- `crond` (CentOS/RHEL)
91
92### Check Service
93```bash
94systemctl status cron
95systemctl status crond # CentOS
96```
97
98### Edit Crontab
99```bash
100crontab -e # Edit current user's crontab
101```
102
103First time will ask which editor (nano recommended for beginners).
104
105### Crontab Syntax
106
107Five time fields + command:
108```
109* * * * * command
110│ │ │ │ │
111│ │ │ │ └─ Day of week (0-7, 0/7 = Sunday)
112│ │ │ └─── Month (1-12)
113│ │ └───── Day of month (1-31)
114│ └─────── Hour (0-23)
115└───────── Minute (0-59)
116```
117
118**Asterisk (*) means "every"**
119
120### Examples
121
122Every minute:
123```bash
124* * * * * /path/to/command
125```
126
127Every 5 minutes:
128```bash
129*/5 * * * * /path/to/command
130```
131
132Every day at 2:30 AM:
133```bash
13430 2 * * * /path/to/command
135```
136
137Every Monday at 5:00 PM:
138```bash
1390 17 * * 1 /path/to/command
140```
141
142First day of every month at midnight:
143```bash
1440 0 1 * * /path/to/command
145```
146
147### Automated Backup Example
148
149Run rsync backup every night at 2 AM:
150```bash
1510 2 * * * rsync -av --delete /var/www/html/ /backups/website/
152```
153
154### Redirect Output
155
156Send output to file:
157```bash
158* * * * * /path/to/command > /path/to/logfile.txt
159```
160
161Append to file:
162```bash
163* * * * * /path/to/command >> /path/to/logfile.txt
164```
165
166Suppress output:
167```bash
168* * * * * /path/to/command > /dev/null 2>&1
169```
170
171### View Crontab
172```bash
173crontab -l # List current user's crontab
174```
175
176### Remove Crontab
177```bash
178crontab -r # Remove current user's crontab
179```
180
181### System-Wide Cron
182
183User-specific: Managed via `crontab -e`
184
185System-wide cron directories:
186- `/etc/cron.daily/` - Scripts run daily
187- `/etc/cron.hourly/` - Scripts run hourly
188- `/etc/cron.weekly/` - Scripts run weekly
189- `/etc/cron.monthly/` - Scripts run monthly
190
191Place executable scripts in these directories for automatic execution.
192
193### Important Notes
194
1951. Cron uses absolute paths - always specify full path to commands
1962. Cron runs in minimal environment - may need to set PATH, etc.
1973. Test commands manually first before adding to cron
1984. Cron jobs run as the user who owns the crontab
1995. `sudo crontab -e` edits root's crontab (for privileged tasks)
200
201### Combining Rsync + Cron
202
203Automated nightly backups:
204```bash
205# In crontab -e:
2060 2 * * * rsync -avz /var/www/html/ /backups/website/
2070 3 * * * rsync -avz /etc/ /backups/configs/
208```
209
210This creates automated, scheduled backups without manual intervention.