-
-
Notifications
You must be signed in to change notification settings - Fork 6.4k
Create ufw.md #636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Create ufw.md #636
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# ufw | ||
|
||
ubuntu防火墙管理工具 | ||
|
||
## 概要 | ||
|
||
```shell | ||
sudo ufw [选项] [规则/命令] | ||
``` | ||
|
||
## 主要用途 | ||
|
||
- 管理Ubuntu系统防火墙规则,简化`iptables`操作。 | ||
- 启用或禁用防火墙,查看当前防火墙状态。 | ||
- 快速配置允许/拒绝端口、服务或特定IP的访问。 | ||
|
||
## 参数 | ||
|
||
### 常用操作命令 | ||
|
||
- `enable`: 启用防火墙并设置开机自启。 | ||
- `disable`: 关闭防火墙。 | ||
- `reload`: 重新加载防火墙规则(不中断现有连接)。 | ||
- `reset`: 重置所有规则到初始状态。 | ||
- `allow <rule>`: 允许指定规则(如端口、服务)。 | ||
- `deny <rule>`: 拒绝指定规则。 | ||
- `status`: 显示防火墙状态和规则列表。 | ||
|
||
### 规则格式 | ||
|
||
- `<port>`: 端口号(如 `22`、`80/tcp`)。 | ||
- `<protocol>`: 协议类型(`tcp` 或 `udp`)。 | ||
- `comment <text>`: 为规则添加注释(需配合 `allow`/`deny` 使用)。 | ||
|
||
### 选项 | ||
|
||
- `--dry-run`: 仅显示规则变更,不实际应用。 | ||
|
||
------ | ||
|
||
## 返回值 | ||
|
||
- 成功执行返回 `0`。 | ||
- 错误或无效参数返回非零值。 | ||
|
||
------ | ||
|
||
## 示例 | ||
|
||
### 基础操作 | ||
|
||
``` | ||
# 启用防火墙 | ||
sudo ufw enable | ||
|
||
# 关闭防火墙 | ||
sudo ufw disable | ||
|
||
# 查看防火墙状态 | ||
sudo ufw status | ||
``` | ||
|
||
### 规则配置 | ||
|
||
``` | ||
# 允许SSH默认端口(22/tcp) | ||
sudo ufw allow ssh | ||
|
||
# 允许TCP协议的8080端口并添加注释 | ||
sudo ufw allow 8080/tcp comment "Web Server" | ||
|
||
# 拒绝来自192.168.1.5的访问 | ||
sudo ufw deny from 192.168.1.5 | ||
|
||
# 拒绝UDP协议的53端口 | ||
sudo ufw deny 53/udp | ||
``` | ||
|
||
### 高级操作 | ||
|
||
``` | ||
# 显示带编号的规则列表(便于删除) | ||
sudo ufw status numbered | ||
|
||
# 删除第3条规则 | ||
sudo ufw delete 3 | ||
|
||
# 重置所有规则 | ||
sudo ufw reset | ||
``` | ||
|
||
------ | ||
|
||
## 注意 | ||
|
||
1. **权限要求**:需使用 `sudo` 执行命令。 | ||
2. **默认策略**:首次启用时默认阻止所有入站流量,允许所有出站流量。 | ||
3. **规则优先级**: | ||
规则按顺序匹配,先拒绝后允许可能导致冲突 | ||
4. **日志记录**: | ||
可通过 `sudo ufw logging on` 启用日志,日志路径为 `/var/log/ufw.log` | ||
5. **服务名称支持**: | ||
支持 `/etc/services` 中定义的服务名(如 `http`、`ssh`) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
linux-command/CONTRIBUTING.md
Lines 19 to 23 in 6fcaf53
命令的标题需要用
===
,因为这是脚本获取标题的方法ufw ===
linux-command/scripts/build.mjs
Line 152 in 6fcaf53
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@li7355608 感谢贡献,需要稍微修改一下
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
抱歉,md格式直接贴过来了,我修改一下
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
文档修改完毕,烦请再次审查