Skip to main content

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ớ

PortProtocolGiao thứcMô tả
20/21TCPFTPFile transfer (data/control)
22TCPSSHSecure remote shell
23TCPTelnetRemote shell (không mã hoá — tránh dùng)
25TCPSMTPGửi email
53TCP/UDPDNSDomain name resolution
67/68UDPDHCPIP address assignment
80TCPHTTPWeb (không mã hoá)
110TCPPOP3Nhận email
143TCPIMAPNhận email
443TCPHTTPSWeb (mã hoá TLS)
465/587TCPSMTPSGửi email mã hoá
993TCPIMAPSIMAP mã hoá
3306TCPMySQLMySQL/MariaDB
5432TCPPostgreSQLPostgreSQL
6379TCPRedisRedis cache
27017TCPMongoDBMongoDB
3389TCPRDPWindows Remote Desktop
8080/8443TCPHTTP altHTTP/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ĩaVí dụ
AIPv4 addressgoogle.com → 142.250.x.x
AAAAIPv6 addressgoogle.com → 2607:f8b0::...
CNAMEAlias → tên khácwww.company.com → company.com
MXMail servercompany.com → mail.company.com (priority 10)
TXTText dataSPF, DKIM, domain verification
NSName serverscompany.com → ns1.provider.com
PTRReverse lookup (IP → name)142.250.x.x → google.com
SOAStart of AuthorityAdmin info, serial number
SRVService 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ĩaIdempotent?
GETLấy resource
POSTTạo resource mới
PUTThay thế toàn bộ resource
PATCHCập nhật một phần
DELETEXoá resource
HEADChỉ lấy header (không có body)
OPTIONSKiểm tra methods được phép

HTTP Status Codes

RangeNhómVí dụ
2xxSuccess200 OK, 201 Created, 204 No Content
3xxRedirect301 Moved Permanently, 302 Found, 304 Not Modified
4xxClient Error400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 429 Too Many Requests
5xxServer Error500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable, 504 Gateway Timeout

HTTPS và TLS

TLS Handshake (TLS 1.3):

  1. Client gửi supported cipher suites
  2. Server chọn cipher, gửi certificate
  3. Client verify certificate (check CA, expiry, hostname)
  4. Key exchange (ECDHE) — tạo session key
  5. 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

ProtocolPortMô tả
SMTP25Gửi mail giữa servers
SMTP Submission587Client gửi mail đến server (STARTTLS)
SMTPS465SMTP over SSL
IMAP143Đọc mail, giữ trên server
IMAPS993IMAP over SSL
POP3110Download mail về local, xoá trên server
POP3S995POP3 over SSL

Các giao thức khác

FTP vs SFTP vs FTPS

FTPSFTPFTPS
Port21 (control), 20 (data)22990
Mã hoáKhôngSSH (mã hoá toàn bộ)TLS/SSL
AuthenticationUsername/passwordSSH key hoặc passwordCertificate
Dùng choLegacy, nội bộTransfer file bảo mậtWeb 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).

VersionSecurityDùng cho
SNMPv1/v2cCommunity string (text)Legacy, LAN nội bộ
SNMPv3Authentication + EncryptionProduction, 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