@xdev-asia/xdev-knowledge-mcp 1.0.54 → 1.0.55

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (17) hide show
  1. package/content/series/devsecops/vyos-tu-co-ban-den-nang-cao/chapters/01-vyos-tu-co-ban-den-nang-cao/lessons/01-bai-1-gioi-thieu-vyos-va-cai-dat.md +324 -0
  2. package/content/series/devsecops/vyos-tu-co-ban-den-nang-cao/chapters/01-vyos-tu-co-ban-den-nang-cao/lessons/02-bai-2-cau-hinh-interface-va-ip-co-ban.md +324 -0
  3. package/content/series/devsecops/vyos-tu-co-ban-den-nang-cao/chapters/01-vyos-tu-co-ban-den-nang-cao/lessons/03-bai-3-nat-source-nat-destination-nat-va-masquerade.md +321 -0
  4. package/content/series/devsecops/vyos-tu-co-ban-den-nang-cao/chapters/01-vyos-tu-co-ban-den-nang-cao/lessons/04-bai-4-firewall-co-ban-rules-chains-va-groups.md +386 -0
  5. package/content/series/devsecops/vyos-tu-co-ban-den-nang-cao/chapters/01-vyos-tu-co-ban-den-nang-cao/lessons/05-bai-5-zone-based-firewall.md +451 -0
  6. package/content/series/devsecops/vyos-tu-co-ban-den-nang-cao/chapters/01-vyos-tu-co-ban-den-nang-cao/lessons/06-bai-6-dhcp-server-dns-forwarding-va-ntp.md +105 -0
  7. package/content/series/devsecops/vyos-tu-co-ban-den-nang-cao/chapters/01-vyos-tu-co-ban-den-nang-cao/lessons/07-bai-7-vlans-bonding-va-bridge.md +94 -0
  8. package/content/series/devsecops/vyos-tu-co-ban-den-nang-cao/chapters/01-vyos-tu-co-ban-den-nang-cao/lessons/08-bai-8-static-routing-va-policy-based-routing.md +83 -0
  9. package/content/series/devsecops/vyos-tu-co-ban-den-nang-cao/chapters/01-vyos-tu-co-ban-den-nang-cao/lessons/09-bai-9-dynamic-routing-ospf.md +79 -0
  10. package/content/series/devsecops/vyos-tu-co-ban-den-nang-cao/chapters/01-vyos-tu-co-ban-den-nang-cao/lessons/10-bai-10-dynamic-routing-bgp.md +82 -0
  11. package/content/series/devsecops/vyos-tu-co-ban-den-nang-cao/chapters/01-vyos-tu-co-ban-den-nang-cao/lessons/11-bai-11-vpn-wireguard-va-openvpn.md +85 -0
  12. package/content/series/devsecops/vyos-tu-co-ban-den-nang-cao/chapters/01-vyos-tu-co-ban-den-nang-cao/lessons/12-bai-12-vpn-ipsec-site-to-site.md +87 -0
  13. package/content/series/devsecops/vyos-tu-co-ban-den-nang-cao/chapters/01-vyos-tu-co-ban-den-nang-cao/lessons/13-bai-13-high-availability-vrrp-va-conntrack-sync.md +61 -0
  14. package/content/series/devsecops/vyos-tu-co-ban-den-nang-cao/chapters/01-vyos-tu-co-ban-den-nang-cao/lessons/14-bai-14-wan-load-balancing-qos-va-monitoring.md +62 -0
  15. package/content/series/devsecops/vyos-tu-co-ban-den-nang-cao/chapters/01-vyos-tu-co-ban-den-nang-cao/lessons/15-bai-15-containers-automation-va-production-best-practices.md +80 -0
  16. package/content/series/devsecops/vyos-tu-co-ban-den-nang-cao/index.md +410 -0
  17. package/package.json +1 -1
@@ -0,0 +1,451 @@
1
+ ---
2
+ id: 019d65ef-d36f-773e-bf0a-9e3347cefe91
3
+ title: 'Bài 5: Zone-based Firewall'
4
+ slug: bai-5-zone-based-firewall
5
+ description: >-
6
+ Tìm hiểu zone-based firewall trên VyOS: thiết kế zones LAN/WAN/DMZ/GUEST,
7
+ inter-zone rules, so sánh với interface-based firewall và lab thực hành 3 zones.
8
+ duration_minutes: 160
9
+ is_free: true
10
+ video_url: null
11
+ sort_order: 5
12
+ section_title: "VyOS từ Cơ bản đến Nâng cao"
13
+ course:
14
+ id: 019d65ef-d36f-773e-bf0a-9e2efc5e19df
15
+ title: VyOS từ Cơ bản đến Nâng cao
16
+ slug: vyos-tu-co-ban-den-nang-cao
17
+ ---
18
+
19
+ <h2>Zone-based Firewall là gì?</h2>
20
+
21
+ <p>Trong bài trước, chúng ta cấu hình firewall theo <strong>interface-based</strong> — gán rules trực tiếp vào từng interface với inbound/outbound direction. Phương pháp này hoạt động tốt nhưng trở nên phức tạp khi mạng có nhiều interfaces.</p>
22
+
23
+ <p><strong>Zone-based firewall</strong> là phương pháp tổ chức firewall theo <em>vùng mạng</em> (zones). Thay vì nghĩ về interfaces, bạn nghĩ về <strong>traffic flow giữa các zones</strong>. Đây là mô hình được Cisco, Juniper và nhiều enterprise firewall sử dụng.</p>
24
+
25
+ <h3>Nguyên tắc cơ bản</h3>
26
+
27
+ <ul>
28
+ <li>Mỗi interface thuộc về <strong>đúng một zone</strong></li>
29
+ <li>Traffic giữa các zones bị <strong>deny by default</strong> — phải tạo rule cho phép rõ ràng</li>
30
+ <li>Traffic trong cùng zone (same-zone) mặc định được allow</li>
31
+ <li>VyOS router bản thân là zone đặc biệt: <strong>local zone</strong></li>
32
+ </ul>
33
+
34
+ <h2>Zone-based vs Interface-based Firewall</h2>
35
+
36
+ <pre><code class="language-bash"># Interface-based: phải xác định direction trên mỗi interface
37
+ # → Phức tạp khi có 4-5 interfaces
38
+ #
39
+ # set firewall ipv4 forward filter rule X inbound-interface eth0
40
+ # set firewall ipv4 forward filter rule X outbound-interface eth1
41
+ # set firewall ipv4 forward filter rule Y inbound-interface eth0
42
+ # set firewall ipv4 forward filter rule Y outbound-interface eth2
43
+ # ... rất nhiều rules
44
+
45
+ # Zone-based: nhóm interfaces vào zones, viết policy giữa zones
46
+ # → Rõ ràng, dễ quản lý
47
+ #
48
+ # zone WAN: eth0
49
+ # zone LAN: eth1
50
+ # zone DMZ: eth2
51
+ # policy: WAN→LAN: drop, LAN→WAN: accept, WAN→DMZ: allow HTTP only</code></pre>
52
+
53
+ <p>Ưu điểm của zone-based:</p>
54
+
55
+ <ul>
56
+ <li><strong>Dễ hiểu</strong>: Mỗi policy mô tả rõ "traffic từ zone A đến zone B"</li>
57
+ <li><strong>Scalable</strong>: Thêm interface mới chỉ cần gán vào zone có sẵn</li>
58
+ <li><strong>Audit dễ</strong>: Xem nhanh ai được phép giao tiếp với ai</li>
59
+ <li><strong>Best practice</strong>: Phù hợp với mô hình bảo mật enterprise</li>
60
+ </ul>
61
+
62
+ <h2>Thiết kế Zones</h2>
63
+
64
+ <p>Một mạng home/office điển hình có thể chia thành các zones sau:</p>
65
+
66
+ <pre><code class="language-bash"> INTERNET
67
+
68
+ ┌──────┴──────┐
69
+ │ ZONE: WAN │
70
+ │ eth0 │
71
+ └──────┬──────┘
72
+
73
+ ┌──────┴──────┐
74
+ │ VyOS Router │ ← ZONE: LOCAL (router itself)
75
+ └──┬────┬──┬──┘
76
+ │ │ │
77
+ ┌────────┘ │ └────────┐
78
+ │ │ │
79
+ ┌──────┴──────┐ ┌───┴────┐ ┌────┴─────┐
80
+ │ ZONE: LAN │ │ DMZ │ │ GUEST │
81
+ │ eth1 │ │ eth2 │ │ eth3 │
82
+ └─────────────┘ └────────┘ └──────────┘
83
+ Trusted Servers Untrusted
84
+ 192.168.1.0/24 10.0.1.0/24 192.168.10.0/24</code></pre>
85
+
86
+ <h3>Các zone phổ biến</h3>
87
+
88
+ <ul>
89
+ <li><strong>WAN</strong>: Kết nối Internet — untrusted, tất cả inbound bị block trừ khi cho phép</li>
90
+ <li><strong>LAN</strong>: Mạng nội bộ — trusted, được phép ra Internet và truy cập DMZ</li>
91
+ <li><strong>DMZ</strong>: Vùng chứa servers public (web, mail) — semi-trusted</li>
92
+ <li><strong>GUEST</strong>: WiFi khách — chỉ được ra Internet, không truy cập LAN/DMZ</li>
93
+ <li><strong>LOCAL</strong>: VyOS router chính nó — quản lý SSH, DNS, DHCP services</li>
94
+ </ul>
95
+
96
+ <h2>Cấu hình Zone-based Firewall trên VyOS</h2>
97
+
98
+ <h3>Bước 1: Tạo firewall rule sets (ipv4 name)</h3>
99
+
100
+ <p>Trước tiên, tạo các bộ rules cho mỗi cặp zone. VyOS 1.4+ sử dụng <code>firewall ipv4 name</code> để định nghĩa named rule sets:</p>
101
+
102
+ <pre><code class="language-bash">configure
103
+
104
+ # === WAN → LAN: Block tất cả (chỉ allow established) ===
105
+ set firewall ipv4 name WAN-TO-LAN default-action 'drop'
106
+ set firewall ipv4 name WAN-TO-LAN rule 10 action 'accept'
107
+ set firewall ipv4 name WAN-TO-LAN rule 10 state 'established'
108
+ set firewall ipv4 name WAN-TO-LAN rule 10 state 'related'
109
+ set firewall ipv4 name WAN-TO-LAN rule 20 action 'drop'
110
+ set firewall ipv4 name WAN-TO-LAN rule 20 state 'invalid'
111
+
112
+ # === LAN → WAN: Allow tất cả ===
113
+ set firewall ipv4 name LAN-TO-WAN default-action 'accept'
114
+
115
+ # === WAN → DMZ: Chỉ allow HTTP/HTTPS ===
116
+ set firewall ipv4 name WAN-TO-DMZ default-action 'drop'
117
+ set firewall ipv4 name WAN-TO-DMZ rule 10 action 'accept'
118
+ set firewall ipv4 name WAN-TO-DMZ rule 10 state 'established'
119
+ set firewall ipv4 name WAN-TO-DMZ rule 10 state 'related'
120
+ set firewall ipv4 name WAN-TO-DMZ rule 20 action 'drop'
121
+ set firewall ipv4 name WAN-TO-DMZ rule 20 state 'invalid'
122
+ set firewall ipv4 name WAN-TO-DMZ rule 100 action 'accept'
123
+ set firewall ipv4 name WAN-TO-DMZ rule 100 protocol 'tcp'
124
+ set firewall ipv4 name WAN-TO-DMZ rule 100 destination port '80,443'
125
+
126
+ # === LAN → DMZ: Allow tất cả ===
127
+ set firewall ipv4 name LAN-TO-DMZ default-action 'accept'
128
+
129
+ # === DMZ → LAN: Block (servers không được truy cập LAN) ===
130
+ set firewall ipv4 name DMZ-TO-LAN default-action 'drop'
131
+ set firewall ipv4 name DMZ-TO-LAN rule 10 action 'accept'
132
+ set firewall ipv4 name DMZ-TO-LAN rule 10 state 'established'
133
+ set firewall ipv4 name DMZ-TO-LAN rule 10 state 'related'
134
+
135
+ # === DMZ → WAN: Allow (servers cần update, fetch data) ===
136
+ set firewall ipv4 name DMZ-TO-WAN default-action 'accept'
137
+
138
+ commit</code></pre>
139
+
140
+ <h3>Bước 2: Tạo zone-policy và gán interfaces</h3>
141
+
142
+ <pre><code class="language-bash"># Tạo zone WAN
143
+ set zone-policy zone WAN interface 'eth0'
144
+ set zone-policy zone WAN description 'Internet / Untrusted'
145
+
146
+ # Tạo zone LAN
147
+ set zone-policy zone LAN interface 'eth1'
148
+ set zone-policy zone LAN description 'Internal / Trusted'
149
+
150
+ # Tạo zone DMZ
151
+ set zone-policy zone DMZ interface 'eth2'
152
+ set zone-policy zone DMZ description 'DMZ / Servers'
153
+
154
+ # LOCAL zone (VyOS router)
155
+ set zone-policy zone LOCAL local-zone
156
+ set zone-policy zone LOCAL description 'VyOS Router'
157
+
158
+ commit</code></pre>
159
+
160
+ <h3>Bước 3: Gán firewall policies cho inter-zone traffic</h3>
161
+
162
+ <pre><code class="language-bash"># WAN → LAN
163
+ set zone-policy zone LAN from WAN firewall name 'WAN-TO-LAN'
164
+
165
+ # LAN → WAN
166
+ set zone-policy zone WAN from LAN firewall name 'LAN-TO-WAN'
167
+
168
+ # WAN → DMZ
169
+ set zone-policy zone DMZ from WAN firewall name 'WAN-TO-DMZ'
170
+
171
+ # LAN → DMZ
172
+ set zone-policy zone DMZ from LAN firewall name 'LAN-TO-DMZ'
173
+
174
+ # DMZ → LAN
175
+ set zone-policy zone LAN from DMZ firewall name 'DMZ-TO-LAN'
176
+
177
+ # DMZ → WAN
178
+ set zone-policy zone WAN from DMZ firewall name 'DMZ-TO-WAN'
179
+
180
+ commit
181
+ save</code></pre>
182
+
183
+ <h2>LOCAL Zone — Bảo vệ Router</h2>
184
+
185
+ <p>LOCAL zone kiểm soát traffic đến/từ chính VyOS router (SSH, DNS, DHCP, NTP...):</p>
186
+
187
+ <pre><code class="language-bash"># === WAN → LOCAL: Rất hạn chế ===
188
+ set firewall ipv4 name WAN-TO-LOCAL default-action 'drop'
189
+ set firewall ipv4 name WAN-TO-LOCAL rule 10 action 'accept'
190
+ set firewall ipv4 name WAN-TO-LOCAL rule 10 state 'established'
191
+ set firewall ipv4 name WAN-TO-LOCAL rule 10 state 'related'
192
+ set firewall ipv4 name WAN-TO-LOCAL rule 20 action 'drop'
193
+ set firewall ipv4 name WAN-TO-LOCAL rule 20 state 'invalid'
194
+
195
+ # === LAN → LOCAL: Cho phép SSH, DNS, DHCP ===
196
+ set firewall ipv4 name LAN-TO-LOCAL default-action 'drop'
197
+ set firewall ipv4 name LAN-TO-LOCAL rule 10 action 'accept'
198
+ set firewall ipv4 name LAN-TO-LOCAL rule 10 state 'established'
199
+ set firewall ipv4 name LAN-TO-LOCAL rule 10 state 'related'
200
+ set firewall ipv4 name LAN-TO-LOCAL rule 100 action 'accept'
201
+ set firewall ipv4 name LAN-TO-LOCAL rule 100 protocol 'tcp'
202
+ set firewall ipv4 name LAN-TO-LOCAL rule 100 destination port '22'
203
+ set firewall ipv4 name LAN-TO-LOCAL rule 100 description 'Allow SSH'
204
+ set firewall ipv4 name LAN-TO-LOCAL rule 110 action 'accept'
205
+ set firewall ipv4 name LAN-TO-LOCAL rule 110 protocol 'udp'
206
+ set firewall ipv4 name LAN-TO-LOCAL rule 110 destination port '53'
207
+ set firewall ipv4 name LAN-TO-LOCAL rule 110 description 'Allow DNS'
208
+ set firewall ipv4 name LAN-TO-LOCAL rule 120 action 'accept'
209
+ set firewall ipv4 name LAN-TO-LOCAL rule 120 protocol 'udp'
210
+ set firewall ipv4 name LAN-TO-LOCAL rule 120 destination port '67,68'
211
+ set firewall ipv4 name LAN-TO-LOCAL rule 120 description 'Allow DHCP'
212
+ set firewall ipv4 name LAN-TO-LOCAL rule 130 action 'accept'
213
+ set firewall ipv4 name LAN-TO-LOCAL rule 130 protocol 'icmp'
214
+ set firewall ipv4 name LAN-TO-LOCAL rule 130 description 'Allow Ping'
215
+
216
+ # === LOCAL → WAN: Cho phép (router cần NTP, DNS, updates) ===
217
+ set firewall ipv4 name LOCAL-TO-WAN default-action 'accept'
218
+
219
+ # === LOCAL → LAN: Cho phép ===
220
+ set firewall ipv4 name LOCAL-TO-LAN default-action 'accept'
221
+
222
+ # Gán vào zone-policy
223
+ set zone-policy zone LOCAL from WAN firewall name 'WAN-TO-LOCAL'
224
+ set zone-policy zone LOCAL from LAN firewall name 'LAN-TO-LOCAL'
225
+ set zone-policy zone WAN from LOCAL firewall name 'LOCAL-TO-WAN'
226
+ set zone-policy zone LAN from LOCAL firewall name 'LOCAL-TO-LAN'
227
+
228
+ commit
229
+ save</code></pre>
230
+
231
+ <h2>Best Practices cho Zone-based Firewall</h2>
232
+
233
+ <ul>
234
+ <li><strong>Nguyên tắc least privilege</strong>: Default-action luôn là <code>drop</code>, chỉ mở những gì cần thiết</li>
235
+ <li><strong>State policy trước tiên</strong>: Rule 10 luôn là accept established/related</li>
236
+ <li><strong>Đánh số rule cách nhau</strong>: 10, 20, 100, 110... để dễ chèn thêm</li>
237
+ <li><strong>Sử dụng groups</strong>: Dùng address-group, port-group cho dễ quản lý</li>
238
+ <li><strong>Đặt tên rõ ràng</strong>: Rule set name theo format <code>SRC-TO-DST</code></li>
239
+ <li><strong>Dùng commit-confirm</strong>: Đặc biệt khi cấu hình qua SSH</li>
240
+ <li><strong>Document</strong>: Thêm description cho mỗi rule và zone</li>
241
+ <li><strong>Log dropped traffic</strong>: Bật default-log cho các chain drop để monitoring</li>
242
+ </ul>
243
+
244
+ <h2>Thêm GUEST Zone</h2>
245
+
246
+ <p>GUEST zone cho WiFi khách — chỉ cho ra Internet, không cho truy cập LAN/DMZ/router:</p>
247
+
248
+ <pre><code class="language-bash">configure
249
+
250
+ # GUEST → WAN: Allow (khách vào Internet)
251
+ set firewall ipv4 name GUEST-TO-WAN default-action 'accept'
252
+
253
+ # GUEST → LAN: Block completely
254
+ set firewall ipv4 name GUEST-TO-LAN default-action 'drop'
255
+
256
+ # GUEST → DMZ: Block
257
+ set firewall ipv4 name GUEST-TO-DMZ default-action 'drop'
258
+
259
+ # GUEST → LOCAL: Chỉ DHCP và DNS
260
+ set firewall ipv4 name GUEST-TO-LOCAL default-action 'drop'
261
+ set firewall ipv4 name GUEST-TO-LOCAL rule 10 action 'accept'
262
+ set firewall ipv4 name GUEST-TO-LOCAL rule 10 state 'established'
263
+ set firewall ipv4 name GUEST-TO-LOCAL rule 10 state 'related'
264
+ set firewall ipv4 name GUEST-TO-LOCAL rule 100 action 'accept'
265
+ set firewall ipv4 name GUEST-TO-LOCAL rule 100 protocol 'udp'
266
+ set firewall ipv4 name GUEST-TO-LOCAL rule 100 destination port '53,67,68'
267
+ set firewall ipv4 name GUEST-TO-LOCAL rule 100 description 'Allow DNS and DHCP'
268
+
269
+ # Tạo zone và gán interface
270
+ set zone-policy zone GUEST interface 'eth3'
271
+ set zone-policy zone GUEST description 'Guest WiFi / Untrusted'
272
+
273
+ # Gán policies
274
+ set zone-policy zone WAN from GUEST firewall name 'GUEST-TO-WAN'
275
+ set zone-policy zone LAN from GUEST firewall name 'GUEST-TO-LAN'
276
+ set zone-policy zone DMZ from GUEST firewall name 'GUEST-TO-DMZ'
277
+ set zone-policy zone LOCAL from GUEST firewall name 'GUEST-TO-LOCAL'
278
+
279
+ commit
280
+ save</code></pre>
281
+
282
+ <h2>Lab thực hành: Zone-policy 3 Zones cho Home Network</h2>
283
+
284
+ <p>Xây dựng mạng 3 zones hoàn chỉnh từ đầu:</p>
285
+
286
+ <pre><code class="language-bash"> Internet
287
+
288
+ ┌──────┴──────┐
289
+ │ WAN (eth0) │
290
+ │ DHCP │
291
+ └──────┬──────┘
292
+
293
+ ┌──────┴──────┐
294
+ │ VyOS Router │ LOCAL zone
295
+ └──┬───────┬──┘
296
+ │ │
297
+ ┌─────────┘ └─────────┐
298
+ │ │
299
+ ┌─────┴─────┐ ┌─────┴─────┐
300
+ │ LAN (eth1)│ │ DMZ (eth2)│
301
+ │ 10.0.1.0 │ │ 10.0.2.0 │
302
+ └───────────┘ └───────────┘
303
+ Trusted Web Server
304
+ 10.0.2.100</code></pre>
305
+
306
+ <h3>Bước 1: Interfaces</h3>
307
+
308
+ <pre><code class="language-bash">configure
309
+
310
+ set interfaces ethernet eth0 address dhcp
311
+ set interfaces ethernet eth0 description 'WAN'
312
+ set interfaces ethernet eth1 address '10.0.1.1/24'
313
+ set interfaces ethernet eth1 description 'LAN'
314
+ set interfaces ethernet eth2 address '10.0.2.1/24'
315
+ set interfaces ethernet eth2 description 'DMZ'
316
+
317
+ commit</code></pre>
318
+
319
+ <h3>Bước 2: NAT</h3>
320
+
321
+ <pre><code class="language-bash"># Masquerade cho cả LAN và DMZ ra Internet
322
+ set nat source rule 100 outbound-interface name 'eth0'
323
+ set nat source rule 100 source address '10.0.0.0/8'
324
+ set nat source rule 100 translation address masquerade
325
+
326
+ # Port forward HTTP/HTTPS vào DMZ web server
327
+ set nat destination rule 10 inbound-interface name 'eth0'
328
+ set nat destination rule 10 protocol 'tcp'
329
+ set nat destination rule 10 destination port '80,443'
330
+ set nat destination rule 10 translation address '10.0.2.100'
331
+
332
+ commit</code></pre>
333
+
334
+ <h3>Bước 3: Firewall rule sets</h3>
335
+
336
+ <pre><code class="language-bash"># WAN-TO-LAN
337
+ set firewall ipv4 name WAN-TO-LAN default-action 'drop'
338
+ set firewall ipv4 name WAN-TO-LAN rule 10 action 'accept'
339
+ set firewall ipv4 name WAN-TO-LAN rule 10 state 'established'
340
+ set firewall ipv4 name WAN-TO-LAN rule 10 state 'related'
341
+
342
+ # LAN-TO-WAN
343
+ set firewall ipv4 name LAN-TO-WAN default-action 'accept'
344
+
345
+ # WAN-TO-DMZ
346
+ set firewall ipv4 name WAN-TO-DMZ default-action 'drop'
347
+ set firewall ipv4 name WAN-TO-DMZ rule 10 action 'accept'
348
+ set firewall ipv4 name WAN-TO-DMZ rule 10 state 'established'
349
+ set firewall ipv4 name WAN-TO-DMZ rule 10 state 'related'
350
+ set firewall ipv4 name WAN-TO-DMZ rule 100 action 'accept'
351
+ set firewall ipv4 name WAN-TO-DMZ rule 100 protocol 'tcp'
352
+ set firewall ipv4 name WAN-TO-DMZ rule 100 destination port '80,443'
353
+ set firewall ipv4 name WAN-TO-DMZ rule 100 description 'Allow HTTP/HTTPS to DMZ'
354
+
355
+ # DMZ-TO-WAN
356
+ set firewall ipv4 name DMZ-TO-WAN default-action 'accept'
357
+
358
+ # LAN-TO-DMZ
359
+ set firewall ipv4 name LAN-TO-DMZ default-action 'accept'
360
+
361
+ # DMZ-TO-LAN
362
+ set firewall ipv4 name DMZ-TO-LAN default-action 'drop'
363
+ set firewall ipv4 name DMZ-TO-LAN rule 10 action 'accept'
364
+ set firewall ipv4 name DMZ-TO-LAN rule 10 state 'established'
365
+ set firewall ipv4 name DMZ-TO-LAN rule 10 state 'related'
366
+
367
+ # WAN-TO-LOCAL
368
+ set firewall ipv4 name WAN-TO-LOCAL default-action 'drop'
369
+ set firewall ipv4 name WAN-TO-LOCAL rule 10 action 'accept'
370
+ set firewall ipv4 name WAN-TO-LOCAL rule 10 state 'established'
371
+ set firewall ipv4 name WAN-TO-LOCAL rule 10 state 'related'
372
+
373
+ # LAN-TO-LOCAL
374
+ set firewall ipv4 name LAN-TO-LOCAL default-action 'drop'
375
+ set firewall ipv4 name LAN-TO-LOCAL rule 10 action 'accept'
376
+ set firewall ipv4 name LAN-TO-LOCAL rule 10 state 'established'
377
+ set firewall ipv4 name LAN-TO-LOCAL rule 10 state 'related'
378
+ set firewall ipv4 name LAN-TO-LOCAL rule 100 action 'accept'
379
+ set firewall ipv4 name LAN-TO-LOCAL rule 100 protocol 'tcp'
380
+ set firewall ipv4 name LAN-TO-LOCAL rule 100 destination port '22'
381
+ set firewall ipv4 name LAN-TO-LOCAL rule 110 action 'accept'
382
+ set firewall ipv4 name LAN-TO-LOCAL rule 110 protocol 'udp'
383
+ set firewall ipv4 name LAN-TO-LOCAL rule 110 destination port '53,67,68'
384
+ set firewall ipv4 name LAN-TO-LOCAL rule 120 action 'accept'
385
+ set firewall ipv4 name LAN-TO-LOCAL rule 120 protocol 'icmp'
386
+
387
+ # LOCAL-TO-WAN, LOCAL-TO-LAN, LOCAL-TO-DMZ
388
+ set firewall ipv4 name LOCAL-TO-WAN default-action 'accept'
389
+ set firewall ipv4 name LOCAL-TO-LAN default-action 'accept'
390
+ set firewall ipv4 name LOCAL-TO-DMZ default-action 'accept'
391
+
392
+ commit</code></pre>
393
+
394
+ <h3>Bước 4: Zone-policy</h3>
395
+
396
+ <pre><code class="language-bash"># Zones
397
+ set zone-policy zone WAN interface 'eth0'
398
+ set zone-policy zone LAN interface 'eth1'
399
+ set zone-policy zone DMZ interface 'eth2'
400
+ set zone-policy zone LOCAL local-zone
401
+
402
+ # Inter-zone policies
403
+ set zone-policy zone LAN from WAN firewall name 'WAN-TO-LAN'
404
+ set zone-policy zone WAN from LAN firewall name 'LAN-TO-WAN'
405
+ set zone-policy zone DMZ from WAN firewall name 'WAN-TO-DMZ'
406
+ set zone-policy zone WAN from DMZ firewall name 'DMZ-TO-WAN'
407
+ set zone-policy zone DMZ from LAN firewall name 'LAN-TO-DMZ'
408
+ set zone-policy zone LAN from DMZ firewall name 'DMZ-TO-LAN'
409
+ set zone-policy zone LOCAL from WAN firewall name 'WAN-TO-LOCAL'
410
+ set zone-policy zone LOCAL from LAN firewall name 'LAN-TO-LOCAL'
411
+ set zone-policy zone WAN from LOCAL firewall name 'LOCAL-TO-WAN'
412
+ set zone-policy zone LAN from LOCAL firewall name 'LOCAL-TO-LAN'
413
+ set zone-policy zone DMZ from LOCAL firewall name 'LOCAL-TO-DMZ'
414
+
415
+ commit
416
+ save</code></pre>
417
+
418
+ <h3>Bước 5: Kiểm tra</h3>
419
+
420
+ <pre><code class="language-bash">exit
421
+
422
+ # Xem zone-policy
423
+ show zone-policy
424
+
425
+ # Xem firewall
426
+ show firewall ipv4 name WAN-TO-DMZ
427
+ show firewall ipv4 name LAN-TO-WAN
428
+
429
+ # Test cases:
430
+ # 1. LAN client ping 8.8.8.8 → OK (LAN→WAN: accept)
431
+ # 2. LAN client SSH vào router → OK (LAN→LOCAL: port 22 accept)
432
+ # 3. Internet truy cập web server :80 → OK (WAN→DMZ: port 80 accept)
433
+ # 4. Internet SSH vào router → BLOCKED (WAN→LOCAL: drop)
434
+ # 5. DMZ server truy cập LAN → BLOCKED (DMZ→LAN: drop)
435
+ # 6. DMZ server cập nhật từ Internet → OK (DMZ→WAN: accept)</code></pre>
436
+
437
+ <h2>Tổng kết</h2>
438
+
439
+ <p>Trong bài này, bạn đã nắm được:</p>
440
+
441
+ <ul>
442
+ <li><strong>Zone-based firewall</strong>: Tổ chức firewall theo vùng mạng thay vì theo interface — rõ ràng, scalable</li>
443
+ <li>Các zone phổ biến: WAN, LAN, DMZ, GUEST, LOCAL và vai trò của từng zone</li>
444
+ <li>Cách tạo <strong>named firewall rule sets</strong> với format SRC-TO-DST</li>
445
+ <li>Cấu hình <code>zone-policy</code> để gán interfaces vào zones và áp dụng inter-zone policies</li>
446
+ <li><strong>LOCAL zone</strong>: Bảo vệ chính VyOS router khỏi truy cập trái phép</li>
447
+ <li>Best practices: least privilege, state policy, commit-confirm, logging</li>
448
+ <li>Lab thực hành: Xây dựng hệ thống 3 zones (WAN/LAN/DMZ) hoàn chỉnh</li>
449
+ </ul>
450
+
451
+ <p>Đến đây bạn đã có nền tảng vững chắc về VyOS: từ cài đặt, cấu hình interface, NAT, firewall cơ bản đến zone-based firewall. Các bài tiếp theo sẽ đi vào các chủ đề nâng cao hơn như DHCP/DNS services, VPN (IPsec, WireGuard), routing protocols (OSPF, BGP) và High Availability.</p>
@@ -0,0 +1,105 @@
1
+ ---
2
+ id: 019d65ef-d36f-773e-bf0a-9e34d7b36e63
3
+ title: 'Bài 6: DHCP Server, DNS Forwarding và NTP'
4
+ slug: bai-6-dhcp-server-dns-forwarding-va-ntp
5
+ description: >-
6
+ Cấu hình DHCP Server, DNS Forwarding và NTP trên VyOS, bao gồm các ví dụ thực tế, lab thực hành và tổng kết kiến thức.
7
+ duration_minutes: 130
8
+ is_free: true
9
+ video_url: null
10
+ sort_order: 6
11
+ section_title: "VyOS từ Cơ bản đến Nâng cao"
12
+ course:
13
+ id: 019d65ef-d36f-773e-bf0a-9e2efc5e19df
14
+ title: VyOS từ Cơ bản đến Nâng cao
15
+ slug: vyos-tu-co-ban-den-nang-cao
16
+ ---
17
+ <h2>Giới thiệu về DHCP Server, DNS Forwarding và NTP trên VyOS</h2>
18
+ <p>Trong bài học này, bạn sẽ tìm hiểu cách cấu hình <strong>DHCP Server</strong>, <strong>DNS Forwarding</strong> và <strong>NTP</strong> trên VyOS phiên bản 1.4.x/1.5 rolling release. Đây là các dịch vụ nền tảng giúp tự động cấp phát địa chỉ IP, chuyển tiếp truy vấn DNS và đồng bộ thời gian cho hệ thống mạng.</p>
19
+
20
+ <h3>1. Cấu hình DHCP Server trên VyOS</h3>
21
+ <p>DHCP Server giúp tự động cấp phát địa chỉ IP, gateway, DNS cho các thiết bị trong mạng LAN.</p>
22
+ <ul>
23
+ <li><strong>Khởi tạo DHCP Server cho mạng LAN:</strong></li>
24
+ </ul>
25
+ <pre><code class="language-bash">set service dhcp-server shared-network-name LAN subnet 192.168.10.0/24 default-router 192.168.10.1
26
+ set service dhcp-server shared-network-name LAN subnet 192.168.10.0/24 dns-server 8.8.8.8
27
+ set service dhcp-server shared-network-name LAN subnet 192.168.10.0/24 range 0 start 192.168.10.100
28
+ set service dhcp-server shared-network-name LAN subnet 192.168.10.0/24 range 0 stop 192.168.10.200
29
+ </code></pre>
30
+ <ul>
31
+ <li><strong>Gán IP tĩnh cho thiết bị dựa trên MAC:</strong></li>
32
+ </ul>
33
+ <pre><code class="language-bash">set service dhcp-server shared-network-name LAN subnet 192.168.10.0/24 static-mapping PC1 ip-address 192.168.10.50
34
+ set service dhcp-server shared-network-name LAN subnet 192.168.10.0/24 static-mapping PC1 mac-address 00:11:22:33:44:55
35
+ </code></pre>
36
+ <ul>
37
+ <li><strong>Cấu hình DHCPv6 (IPv6):</strong></li>
38
+ </ul>
39
+ <pre><code class="language-bash">set service dhcpv6-server shared-network-name LAN6 subnet 2001:db8:1::/64 range 0 start 2001:db8:1::100
40
+ set service dhcpv6-server shared-network-name LAN6 subnet 2001:db8:1::/64 range 0 stop 2001:db8:1::200
41
+ set service dhcpv6-server shared-network-name LAN6 subnet 2001:db8:1::/64 name-server 2001:4860:4860::8888
42
+ </code></pre>
43
+ <ul>
44
+ <li><strong>DHCP Relay:</strong> Chuyển tiếp yêu cầu DHCP tới server khác.</li>
45
+ </ul>
46
+ <pre><code class="language-bash">set service dhcp-relay interface eth1
47
+ set service dhcp-relay server 192.168.20.10
48
+ </code></pre>
49
+
50
+ <h3>2. Cấu hình DNS Forwarding</h3>
51
+ <p>DNS Forwarding giúp các thiết bị trong mạng LAN truy vấn DNS thông qua VyOS.</p>
52
+ <pre><code class="language-bash">set service dns forwarding listen-address 192.168.10.1
53
+ set service dns forwarding allow-from 192.168.10.0/24
54
+ set service dns forwarding cache-size 1000
55
+ set service dns forwarding name-server 8.8.8.8
56
+ set service dns forwarding static-host-mapping host-name server1.intra inet 192.168.10.10
57
+ </code></pre>
58
+ <ul>
59
+ <li><strong>Kiểm tra trạng thái DNS Forwarding:</strong></li>
60
+ </ul>
61
+ <pre><code class="language-bash">show service dns forwarding
62
+ </code></pre>
63
+
64
+ <h3>3. Cấu hình NTP (Network Time Protocol)</h3>
65
+ <p>NTP giúp đồng bộ thời gian hệ thống với các máy chủ chuẩn.</p>
66
+ <pre><code class="language-bash">set service ntp server 0.pool.ntp.org
67
+ set service ntp server 1.pool.ntp.org
68
+ set service ntp listen-address 192.168.10.1
69
+ </code></pre>
70
+ <ul>
71
+ <li><strong>Kiểm tra trạng thái NTP:</strong></li>
72
+ </ul>
73
+ <pre><code class="language-bash">show ntp
74
+ </code></pre>
75
+
76
+ <h3>4. Ví dụ thực tế & sơ đồ mạng</h3>
77
+ <p>Giả sử bạn có sơ đồ mạng như sau:</p>
78
+ <pre><code>+-------------------+ +-------------------+
79
+ | VyOS Router |------| Switch LAN |
80
+ | 192.168.10.1/24 | | |
81
+ +-------------------+ +-------------------+
82
+ | |
83
+ DHCP, DNS, NTP Các PC, IoT
84
+ </code></pre>
85
+
86
+ <h3>5. Lab thực hành: Cấu hình DHCP, DNS, NTP</h3>
87
+ <ol>
88
+ <li>Đăng nhập vào VyOS qua SSH hoặc console.</li>
89
+ <li>Thực hiện các lệnh cấu hình DHCP, DNS, NTP như trên.</li>
90
+ <li>Commit và save cấu hình:</li>
91
+ </ol>
92
+ <pre><code class="language-bash">commit
93
+ save
94
+ </code></pre>
95
+ <ol start="4">
96
+ <li>Kết nối một PC vào mạng LAN, kiểm tra nhận IP, DNS, NTP tự động.</li>
97
+ <li>Kiểm tra trạng thái dịch vụ:</li>
98
+ </ol>
99
+ <pre><code class="language-bash">show dhcp server leases
100
+ show service dns forwarding
101
+ show ntp
102
+ </code></pre>
103
+
104
+ <h3>6. Tổng kết</h3>
105
+ <p>Bạn đã nắm được cách cấu hình DHCP Server, DNS Forwarding và NTP trên VyOS, giúp tự động hóa cấp phát IP, truy vấn DNS và đồng bộ thời gian cho hệ thống mạng.</p>
@@ -0,0 +1,94 @@
1
+ ---
2
+ id: 019d65ef-d36f-773e-bf0a-9e354f8246f3
3
+ title: 'Bài 7: VLANs, Bonding và Bridge'
4
+ slug: bai-7-vlans-bonding-va-bridge
5
+ description: >-
6
+ Cấu hình VLANs, Bonding và Bridge trên VyOS, thực hành phân đoạn mạng, lab và tổng kết kiến thức.
7
+ duration_minutes: 150
8
+ is_free: true
9
+ video_url: null
10
+ sort_order: 7
11
+ section_title: "VyOS từ Cơ bản đến Nâng cao"
12
+ course:
13
+ id: 019d65ef-d36f-773e-bf0a-9e2efc5e19df
14
+ title: VyOS từ Cơ bản đến Nâng cao
15
+ slug: vyos-tu-co-ban-den-nang-cao
16
+ ---
17
+ <h2>Giới thiệu về VLANs, Bonding và Bridge trên VyOS</h2>
18
+ <p>Bài học này hướng dẫn cấu hình <strong>VLANs (802.1Q)</strong>, <strong>Bonding</strong> (gộp nhiều interface vật lý) và <strong>Bridge</strong> (cầu nối mạng) trên VyOS 1.4.x/1.5 rolling release. Đây là các kỹ thuật quan trọng để phân đoạn, tối ưu và mở rộng mạng LAN.</p>
19
+
20
+ <h3>1. Cấu hình VLANs (802.1Q)</h3>
21
+ <p>VLAN giúp phân chia mạng vật lý thành nhiều mạng logic, tăng bảo mật và hiệu quả quản lý.</p>
22
+ <pre><code class="language-bash">set interfaces ethernet eth0 vif 10 address 192.168.10.1/24
23
+ set interfaces ethernet eth0 vif 20 address 192.168.20.1/24
24
+ </code></pre>
25
+ <ul>
26
+ <li><strong>Router-on-a-stick (Inter-VLAN Routing):</strong></li>
27
+ </ul>
28
+ <pre><code class="language-bash">set interfaces ethernet eth0 vif 30 address 192.168.30.1/24
29
+ </code></pre>
30
+ <p>Trên switch, cấu hình trunk port cho eth0, access port cho các VLAN.</p>
31
+
32
+ <h3>2. Cấu hình Bonding (Gộp nhiều interface)</h3>
33
+ <p>Bonding giúp tăng băng thông và dự phòng bằng cách gộp nhiều interface vật lý.</p>
34
+ <pre><code class="language-bash">set interfaces bonding bond0 mode 802.3ad
35
+ set interfaces bonding bond0 member interface eth1
36
+ set interfaces bonding bond0 member interface eth2
37
+ set interfaces bonding bond0 address 10.10.10.1/24
38
+ </code></pre>
39
+ <p>Chế độ <strong>802.3ad (LACP)</strong> yêu cầu switch hỗ trợ LACP.</p>
40
+
41
+ <h3>3. Cấu hình Bridge Interface</h3>
42
+ <p>Bridge giúp kết nối nhiều interface vật lý hoặc VLAN thành một mạng logic.</p>
43
+ <pre><code class="language-bash">set interfaces bridge br0 member interface eth3
44
+ set interfaces bridge br0 member interface eth4
45
+ set interfaces bridge br0 address 192.168.50.1/24
46
+ </code></pre>
47
+
48
+ <h3>4. Kết hợp VLANs với Bridge và Firewall Zones</h3>
49
+ <p>Có thể kết hợp bridge với các VLAN để phân vùng mạng, ví dụ:</p>
50
+ <pre><code class="language-bash">set interfaces bridge br1 member interface eth0.10
51
+ set interfaces bridge br1 member interface eth5
52
+ set interfaces bridge br1 address 192.168.60.1/24
53
+ </code></pre>
54
+ <p>Kết hợp với firewall zone để kiểm soát truy cập giữa các phân đoạn.</p>
55
+
56
+ <h3>5. Thực hành: Phân đoạn LAN/GUEST/IoT</h3>
57
+ <pre><code>+-------------------+
58
+ | VyOS Router |
59
+ | |
60
+ | eth0 (trunk) |
61
+ +--------+----------+
62
+ |
63
+ +-----+-----+
64
+ | Switch |
65
+ +-----+-----+
66
+ |
67
+ +-----+-----+
68
+ | PC LAN | (VLAN 10)
69
+ +-----------+
70
+ | PC Guest| (VLAN 20)
71
+ +-----------+
72
+ | IoT Dev | (VLAN 30)
73
+ +-----------+
74
+ </code></pre>
75
+
76
+ <h3>6. Lab thực hành: Cấu hình VLAN, Bonding, Bridge</h3>
77
+ <ol>
78
+ <li>Đăng nhập VyOS, xác định các interface vật lý.</li>
79
+ <li>Cấu hình VLANs, bonding, bridge như trên.</li>
80
+ <li>Commit và save cấu hình:</li>
81
+ </ol>
82
+ <pre><code class="language-bash">commit
83
+ save
84
+ </code></pre>
85
+ <ol start="4">
86
+ <li>Cấu hình switch trunk/access phù hợp.</li>
87
+ <li>Kiểm tra kết nối giữa các VLAN, bridge.</li>
88
+ </ol>
89
+ <pre><code class="language-bash">show interfaces
90
+ show bridge br0
91
+ </code></pre>
92
+
93
+ <h3>7. Tổng kết</h3>
94
+ <p>Bạn đã biết cách cấu hình VLANs, bonding và bridge trên VyOS, ứng dụng vào phân đoạn mạng, tăng dự phòng và tối ưu hệ thống.</p>