Giao thức mạng phổ biến
Port và Protocol cơ bản
Port là số từ 0–65535, xác định ứng dụng nào nhận dữ liệu trên máy:
Bảng port quan trọng cần nhớ
| Port | Protocol | Giao thức | Mô tả |
|---|---|---|---|
| 20/21 | TCP | FTP | File transfer (data/control) |
| 22 | TCP | SSH | Secure remote shell |
| 23 | TCP | Telnet | Remote shell (không mã hoá — tránh dùng) |
| 25 | TCP | SMTP | Gửi email |
| 53 | TCP/UDP | DNS | Domain name resolution |
| 67/68 | UDP | DHCP | IP address assignment |
| 80 | TCP | HTTP | Web (không mã hoá) |
| 110 | TCP | POP3 | Nhận email |
| 143 | TCP | IMAP | Nhận email |
| 443 | TCP | HTTPS | Web (mã hoá TLS) |
| 465/587 | TCP | SMTPS | Gửi email mã hoá |
| 993 | TCP | IMAPS | IMAP mã hoá |
| 3306 | TCP | MySQL | MySQL/MariaDB |
| 5432 | TCP | PostgreSQL | PostgreSQL |
| 6379 | TCP | Redis | Redis cache |
| 27017 | TCP | MongoDB | MongoDB |
| 3389 | TCP | RDP | Windows Remote Desktop |
| 8080/8443 | TCP | HTTP alt | HTTP/HTTPS alternative ports |
DNS — Domain Name System
DNS dịch tên miền (google.com) thành địa chỉ IP.
Quy trình phân giải DNS
Các loại DNS Record
| Record | Ý nghĩa | Ví dụ |
|---|---|---|
| A | IPv4 address | google.com → 142.250.x.x |
| AAAA | IPv6 address | google.com → 2607:f8b0::... |
| CNAME | Alias → tên khác | www.company.com → company.com |
| MX | Mail server | company.com → mail.company.com (priority 10) |
| TXT | Text data | SPF, DKIM, domain verification |
| NS | Name servers | company.com → ns1.provider.com |
| PTR | Reverse lookup (IP → name) | 142.250.x.x → google.com |
| SOA | Start of Authority | Admin info, serial number |
| SRV | Service location | _http._tcp.company.com |
# Tra cứu DNS thực hành
dig google.com # A record
dig google.com AAAA # IPv6
dig google.com MX # Mail server
dig google.com TXT # TXT records
dig +short google.com # chỉ IP
dig @8.8.8.8 google.com # dùng DNS server cụ thể
nslookup google.com
nslookup -type=MX google.com
host google.com
DHCP — Dynamic Host Configuration Protocol
DHCP tự động cấp phát IP cho máy khi kết nối vào mạng.
DHCP Options quan trọng:
- Option 3: Default Gateway
- Option 6: DNS Servers
- Option 15: Domain Name
- Option 51: Lease Time
- Option 66/67: TFTP server (dùng cho PXE boot)
HTTP / HTTPS
HTTP Request/Response
HTTP Methods
| Method | Ý nghĩa | Idempotent? |
|---|---|---|
| GET | Lấy resource | ✅ |
| POST | Tạo resource mới | ❌ |
| PUT | Thay thế toàn bộ resource | ✅ |
| PATCH | Cập nhật một phần | ❌ |
| DELETE | Xoá resource | ✅ |
| HEAD | Chỉ lấy header (không có body) | ✅ |
| OPTIONS | Kiểm tra methods được phép | ✅ |
HTTP Status Codes
| Range | Nhóm | Ví dụ |
|---|---|---|
| 2xx | Success | 200 OK, 201 Created, 204 No Content |
| 3xx | Redirect | 301 Moved Permanently, 302 Found, 304 Not Modified |
| 4xx | Client Error | 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 429 Too Many Requests |
| 5xx | Server Error | 500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable, 504 Gateway Timeout |
HTTPS và TLS
TLS Handshake (TLS 1.3):
- Client gửi supported cipher suites
- Server chọn cipher, gửi certificate
- Client verify certificate (check CA, expiry, hostname)
- Key exchange (ECDHE) — tạo session key
- Encrypted communication bắt đầu
# Kiểm tra TLS certificate
openssl s_client -connect google.com:443 -servername google.com
curl -vI https://google.com 2>&1 | grep -E "SSL|TLS|cert|expire"
echo | openssl s_client -connect google.com:443 2>/dev/null | openssl x509 -noout -dates
Email Protocols
| Protocol | Port | Mô tả |
|---|---|---|
| SMTP | 25 | Gửi mail giữa servers |
| SMTP Submission | 587 | Client gửi mail đến server (STARTTLS) |
| SMTPS | 465 | SMTP over SSL |
| IMAP | 143 | Đọc mail, giữ trên server |
| IMAPS | 993 | IMAP over SSL |
| POP3 | 110 | Download mail về local, xoá trên server |
| POP3S | 995 | POP3 over SSL |
Các giao thức khác
FTP vs SFTP vs FTPS
| FTP | SFTP | FTPS | |
|---|---|---|---|
| Port | 21 (control), 20 (data) | 22 | 990 |
| Mã hoá | Không | SSH (mã hoá toàn bộ) | TLS/SSL |
| Authentication | Username/password | SSH key hoặc password | Certificate |
| Dùng cho | Legacy, nội bộ | Transfer file bảo mật | Web hosting legacy |
# SFTP thực hành
sftp user@host # kết nối interactive
sftp> put local_file.txt /remote/ # upload
sftp> get /remote/file.txt ./ # download
sftp> ls /remote/ # liệt kê
# rsync over SSH (tốt hơn SFTP cho sync)
rsync -avz ./src/ user@host:/dest/
SNMP — Network Monitoring
SNMP (Simple Network Management Protocol) dùng để monitor thiết bị mạng (router, switch, server).
| Version | Security | Dùng cho |
|---|---|---|
| SNMPv1/v2c | Community string (text) | Legacy, LAN nội bộ |
| SNMPv3 | Authentication + Encryption | Production, recommended |
# Check SNMP
snmpwalk -v2c -c public 192.168.1.1 # walk OID tree
snmpget -v2c -c public 192.168.1.1 sysDescr.0 # system description