---
title: "UFW Application Profiles: Cài đặt chi tiết từ đầu và kiểm tra hoạt động thực tế"
description: "Hướng dẫn tạo và quản lý UFW Application Profiles trên Ubuntu/Debian VPS: gom nhóm port theo dịch vụ, mở SSH an toàn và kiểm tra rule thực tế."
canonical: "https://thuecloud.vn/ufw-application-profiles-cai-dat-chi-tiet-tu-dau-va-kiem-tra-hoat-dong-thuc-te"
markdown_url: "https://thuecloud.vn/ufw-application-profiles-cai-dat-chi-tiet-tu-dau-va-kiem-tra-hoat-dong-thuc-te.md"
locale: "vi"
kind: "article"
published_at: "2026-11-22T16:18:26.735Z"
updated_at: "2026-11-22T16:18:25.613Z"
site: "ThueCloud.Vn"
estimated_tokens: 1912
---
# UFW Application Profiles: Cài đặt chi tiết từ đầu và kiểm tra hoạt động thực tế

> Hướng dẫn tạo và quản lý UFW Application Profiles trên Ubuntu/Debian VPS: gom nhóm port theo dịch vụ, mở SSH an toàn và kiểm tra rule thực tế.

- Canonical HTML: https://thuecloud.vn/ufw-application-profiles-cai-dat-chi-tiet-tu-dau-va-kiem-tra-hoat-dong-thuc-te
- Markdown URL: https://thuecloud.vn/ufw-application-profiles-cai-dat-chi-tiet-tu-dau-va-kiem-tra-hoat-dong-thuc-te.md
- Organization: ThueCloud.Vn
- Support Email: support@thuecloud.vn
- Hotline: 03333 499 48
- Published: 2026-11-22
- Updated: 2026-11-22

## Mục lục

- Cấu trúc chuẩn của một UFW Application Profile
- Bước 1: Tạo custom UFW profile cho SSH tùy biến và Web Stack
- Bước 2: Kích hoạt profile và kiểm tra hoạt động thực tế
- Câu hỏi thường gặp (FAQ)
  - Làm sao xóa một rule được tạo từ UFW Application Profile?
  - UFW Application Profile có hỗ trợ dải port (port range) không?
  - Sửa file trong /etc/ufw/applications.d/ xong mà port mới vẫn bị chặn?

Khi quản trị [Cloud VPS Việt Nam](https://thuecloud.vn/vps-viet-nam) chạy nhiều dịch vụ như Nginx, Node.js, Redis hay WireGuard, việc mở port rời rạc bằng số (`ufw allow 80`, `ufw allow 443`, `ufw allow 2222`) dễ khiến rule firewall trở nên lộn xộn và khó kiểm soát khi cần tắt một dịch vụ. **UFW Application Profiles** cho phép bạn đóng gói tên dịch vụ, mô tả và dải port vào một file chuẩn trong `/etc/ufw/applications.d/`, giúp bật/tắt tường lửa chỉ bằng một tên gọi rõ nghĩa.

> **Tóm tắt nhanh (TL;DR):**
> - File profile đặt tại `/etc/ufw/applications.d/<ten-app>`, sử dụng cú pháp INI đơn giản gồm `[TenProfile]`, `title`, `description`, `ports`.
> - Lệnh `ufw app list` liệt kê toàn bộ profile hiện có; `ufw app info 'TenProfile'` xem chi tiết port trước khi mở.
> - Khi sửa file profile đang hoạt động, bắt buộc phải chạy `ufw app update <TenProfile>` thì rule mới có hiệu lực.
> - *Cập nhật: 11/2026*

## Cấu trúc chuẩn của một UFW Application Profile

Nhiều gói phần mềm phổ biến (như OpenSSH, Nginx, Postfix) tự động cài sẵn profile khi bạn chạy `apt install`. Tuy nhiên, với các dịch vụ tự build hoặc đổi port SSH mặc định, bạn nên tự định nghĩa profile riêng.

| Trường khai báo | Ý nghĩa | Ví dụ thực tế |
| :--- | :--- | :--- |
| `[Section Name]` | Tên dùng trong lệnh `ufw allow` | `[ThueCloud-API]` |
| `title=` | Tiêu đề ngắn gọn | `ThueCloud Go API & Metrics` |
| `description=` | Mô tả mục đích mở port | `Allow HTTPS API and internal healthcheck` |
| `ports=` | Danh sách port/giao thức | `80,443/tcp|8080/tcp` |

Để bảo vệ lớp ứng dụng phía sau firewall, bạn cũng có thể kết hợp với [Nodriver CDP automation](https://thuecloud.vn/nodriver-cdp-bypass-cai-dat-chi-tiet-tu-dau-va-kiem-tra-hoat-dong-thuc-te) hoặc thiết lập [giám sát cảnh báo Ketama](https://thuecloud.vn/consistent-hashing-ketama-tang-cuong-bao-mat-phan-quyen-va-thiet-lap-giam-sat-canh-bao).

## Bước 1: Tạo custom UFW profile cho SSH tùy biến và Web Stack

Giả sử bạn đổi cổng SSH sang `2222` và chạy web app trên cổng `80, 443`. Tạo file `/etc/ufw/applications.d/custom-stack`:

```ini
[Custom-SSH]
title=Hardened SSH Port
description=SSH service listening on custom port 2222
ports=2222/tcp

[Web-Production]
title=Nginx Web HTTPS
description=HTTP and HTTPS ports for production web
ports=80,443/tcp
```

Kiểm tra xem UFW đã nhận diện đúng profile vừa tạo chưa:

```bash
sudo ufw app list
sudo ufw app info 'Custom-SSH'
```

## Bước 2: Kích hoạt profile và kiểm tra hoạt động thực tế

**Quan trọng:** Luôn cho phép profile SSH trước khi chạy `ufw enable` để tránh tự khóa mình khỏi VPS:

```bash
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw limit 'Custom-SSH'
sudo ufw allow 'Web-Production'
sudo ufw enable
```

Lệnh `ufw limit` tự động giới hạn kết nối (rate-limit) nếu một IP thử đăng nhập quá 6 lần trong 30 giây, giảm thiểu tấn công brute-force hiệu quả.

**Kiểm tra thực tế sau khi cấu hình:**
1. Chạy `sudo ufw status verbose` để xác nhận profile hiển thị trạng thái `ALLOW IN` hoặc `LIMIT IN`.
2. Từ máy tính cá nhân, dùng `nc -zv IP_VPS 2222` (thành công) và `nc -zv IP_VPS 8080` (timeout/bị chặn) để chứng minh firewall lọc đúng port.
3. Nếu sau này bạn thêm port vào file `/etc/ufw/applications.d/custom-stack`, chạy `sudo ufw app update Web-Production` để áp dụng ngay.

Xem thêm các lưu ý về cấu hình mạng và tường lửa tại [trang Câu hỏi thường gặp (FAQ)](https://thuecloud.vn/faq).

> **Trải nghiệm VPS Linux sạch, bảo mật cao tại ThueCloud.Vn:**
> Toàn bộ máy chủ ảo **KVM Enterprise NVMe tại `vn-hn`** đều cấp full quyền root để bạn chủ động thiết lập UFW/iptables theo chuẩn riêng. Khởi tạo nhanh gói **VPS VN 1** (`45.000đ`/`60.000đ`) hoặc **VPS VN 2** (`78.000đ`/`90.000đ`), **VAT 0%**, **SLA 99,9%** và **hoàn tiền 07 ngày**. Xem chi tiết tại [bảng giá ThueCloud](https://thuecloud.vn/pricing).

## Câu hỏi thường gặp (FAQ)

### Làm sao xóa một rule được tạo từ UFW Application Profile?
Bạn chạy `sudo ufw status numbered` để xem số thứ tự của rule, sau đó gõ `sudo ufw delete <so-thu-tu>`, hoặc chạy trực tiếp `sudo ufw delete allow 'Web-Production'`.

### UFW Application Profile có hỗ trợ dải port (port range) không?
Có. Bạn dùng dấu hai chấm `:` trong trường `ports`, ví dụ `ports=30000:30100/tcp|51820/udp`. Lưu ý khi dùng dải port bắt buộc phải ghi rõ giao thức `/tcp` hoặc `/udp` ở cuối.

### Sửa file trong `/etc/ufw/applications.d/` xong mà port mới vẫn bị chặn?
UFW không tự động theo dõi thay đổi file theo thời gian thực. Bạn phải chạy lệnh `sudo ufw app update <TenProfile>` (hoặc `sudo ufw app update all`) rồi kiểm tra lại bằng `sudo ufw status`.

## References / Sources

- https://manpages.ubuntu.com/manpages/noble/man8/ufw.8.html
- https://help.ubuntu.com/community/UFW

---

## Navigation & Machine-Readable Endpoints

- [Site Summary (llms.txt)](https://thuecloud.vn/llms.txt)
- [Full Technical Reference (llms-full.txt)](https://thuecloud.vn/llms-full.txt)
- [Pricing Catalog (Markdown)](https://thuecloud.vn/pricing.md)
- [Blog & Technical Guides (Markdown)](https://thuecloud.vn/blog.md)
- [XML Sitemap](https://thuecloud.vn/sitemap.xml)
