Chương 3
⚙️ Cấu hình cơ bản MikroTik
IP, DHCP Server, NAT Masquerade, DNS – bước A-Z từ router mới reset.
⏱ 25 phút🔧 Thực hành🎯 Bắt buộc
🔒
3.1 Bảo mật ban đầu (Initial Hardening)
Việc đầu tiên khi có router mới: đổi mật khẩu và tạo user riêng trước khi làm bất kỳ thứ gì khác.
# Đổi hostname
/system identity set name=MK-OFFICE-01
# Đổi mật khẩu admin
/user set admin password="P@ssw0rd2025!"
# Tạo user quản trị riêng (best practice)
/user add name=netadmin password="Str0ng@Pass!" group=full comment="Network Admin"
# Disable user admin mặc định (tùy chọn – sau khi test netadmin OK)
# /user disable admin🌐
3.2 Cấu hình WAN (ether1)
# Cách 1: Gán IP tĩnh WAN (ISP cấp IP cố định)
/ip address add address=203.162.10.2/30 interface=ether1 comment="WAN-ISP"
/ip route add dst-address=0.0.0.0/0 gateway=203.162.10.1 comment="Default-GW"
# Cách 2: DHCP Client (ISP cấp IP động – phổ biến hơn)
/ip dhcp-client add interface=ether1 disabled=no add-default-route=yes
# Cấu hình DNS
/ip dns set servers=8.8.8.8,1.1.1.1 allow-remote-requests=no⚠️ allow-remote-requests=no trên DNS giúp tránh router bị dùng làm DNS resolver công khai.
🔗
3.3 Cấu hình LAN Bridge
Bridge gộp nhiều physical port thành một switch logic, giúp các máy cùng VLAN giao tiếp trực tiếp.
# Tạo bridge LAN gộp ether2, ether3, ether4
/interface bridge add name=bridge-lan comment="LAN Bridge"
/interface bridge port add bridge=bridge-lan interface=ether2
/interface bridge port add bridge=bridge-lan interface=ether3
/interface bridge port add bridge=bridge-lan interface=ether4
# Gán IP cho bridge LAN
/ip address add address=192.168.10.1/24 interface=bridge-lan comment="LAN-Gateway" 📡
3.4 Cấu hình DHCP Server
# Tạo IP Pool
/ip pool add name=pool-lan ranges=192.168.10.100-192.168.10.200
# Tạo DHCP Server
/ip dhcp-server add name=dhcp-lan interface=bridge-lan address-pool=pool-lan disabled=no
# Cấu hình DHCP Network (gateway + DNS cho client)
/ip dhcp-server network add \
address=192.168.10.0/24 \
gateway=192.168.10.1 \
dns-server=8.8.8.8,8.8.4.4 \
comment="LAN Network" 🔄
3.5 Cấu hình NAT Masquerade
NAT Masquerade thay thế IP nguồn của gói tin từ LAN bằng IP WAN khi đi ra Internet.
# NAT Masquerade – cho phép LAN ra Internet qua WAN IP
/ip firewall nat add \
chain=srcnat \
out-interface=ether1 \
action=masquerade \
comment="LAN-to-WAN NAT Masquerade" ℹ️ Sau khi cấu hình NAT, test bằng cách ping 8.8.8.8 từ PC trong LAN. Nếu được = NAT đang hoạt động.
✅
3.6 Kiểm tra & Verify
# Kiểm tra địa chỉ IP
/ip address print
# Kiểm tra routing table
/ip route print
# Ping ra Internet từ router
/ping 8.8.8.8 count=4
# Kiểm tra DNS
/ip dns cache print
# Xem DHCP leases (client đã nhận IP)
/ip dhcp-server lease print
# Monitor traffic real-time
/interface monitor-traffic ether1 once📌
3.7 Nâng cao: DHCP Static Lease & Config Backup
# Gán IP tĩnh cho 1 máy cụ thể qua MAC
/ip dhcp-server lease add \
mac-address=AA:BB:CC:DD:EE:FF \
address=192.168.10.10 \
server=dhcp-lan \
comment="Server-01-Static" # Export toàn bộ config ra file
/export file=backup-config-2025
# Xem file vừa export
/file print
# Download file về máy: dùng Winbox → Files → kéo file ra desktop💡 Luôn export config trước khi thay đổi lớn trên production. File .rsc là text thuần, có thể mở bằng Notepad.
| Lệnh | Mô tả |
|---|---|
| /ip address print | Xem tất cả IP trên router |
| /ip route print | Xem bảng routing |
| /ping 8.8.8.8 | Ping từ router ra Internet |
| /ip dhcp-server lease print | Xem danh sách IP đã cấp |
| /ip firewall nat print | Xem NAT rules |
| /export file=backup | Export config ra file |
| /system reboot | Reboot router |