firewall-config
它能做什么
这个技能可以帮助你在计算机和云端设置、管理防火墙。它控制哪些网络连接被允许,哪些被阻止,从而保护你的系统。
适用场景
- ✓当你新建服务器,需要为它加固安全时。
- ✓当你需要将网络的不同部分隔离开,以提升安全性时。
- ✓当你需要在 AWS、Google Cloud 或 Azure 等云服务中调整安全规则时。
技能链接
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/firewall-config/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“帮我配置服务器的防火墙:只允许来自我的管理网络的 SSH 连接,HTTP 和 HTTPS 连接则允许来自任何地方。”
每周 5 个新技能,1 分钟读完。
工作原理
你可以针对不同类型的防火墙使用特定命令(如 iptables、UFW、nftables),也可以在云服务商那里配置安全组。核心目标是明确规定哪些流量可以进入和离开系统。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Firewall Configuration
Configure host-based and cloud firewalls for network security.
When to Use This Skill
Use this skill when:
- Setting up a new server and need to restrict network access
- Implementing network segmentation between application tiers
- Configuring cloud security groups for AWS, GCP, or Azure resources
- Migrating from iptables to nftables
- Auditing existing firewall rules for compliance
- Responding to a security incident requiring emergency network blocks
Prerequisites
- Root or sudo access on Linux hosts
- AWS CLI configured for cloud security groups
- Understanding of TCP/IP, ports, and protocols
- Network diagram showing required traffic flows
iptables
Basic Setup with Default Deny
# Flush existing rules
iptables -F
iptables -X
iptables -t nat -F
iptables -t mangle -F
# Default policies - deny all inbound, allow outbound
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
# Allow established connections
iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
# Allow loopback
iptables -A INPUT -i lo -j ACCEPT
# Drop invalid packets
iptables -A INPUT -m conntrack --ctstate INVALID -j DROP
# Allow SSH (restrict to management subnet)
iptables -A INPUT -p tcp --dport 22 -s 10.0.100.0/24 -j ACCEPT
# Allow HTTP/HTTPS from anywhere
iptables -A INPUT -p tcp -m multiport --dports 80,443 -j ACCEPT
# Allow ICMP (ping) with rate limiting
iptables -A INPUT -p icmp --icmp-type echo-request -m limit --limit 1/s --limit-burst 4 -j ACCEPT
# Log dropped packets (rate limited to avoid log flooding)
iptables -A INPUT -m limit --limit 5/min -j LOG --log-prefix "IPTABLES-DROP: " --log-level 4
# Save rules (Debian/Ubuntu)
iptables-save > /etc/iptables/rules.v4
ip6tables-save > /etc/iptables/rules.v6
Anti-DDoS Rules
# SYN flood protection
iptables -A INPUT -p tcp --syn -m limit --limit 25/s --limit-burst 50 -j ACCEPT
iptables -A INPUT -p tcp --syn -j DROP
# Limit new connections per source IP
iptables -A INPUT -p tcp --dport 80 -m connlimit --connlimit-above 50 -j REJECT
# Block port scanning (detect TCP flags abuse)
iptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP
iptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP
iptables -A INPUT -p tcp --tcp-flags ALL FIN,URG,PSH -j DROP
iptables -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j DROP
iptables -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP
Application-Specific Rules
# Web server with database backend
# Allow app servers to reach database (port 5432)
iptables -A INPUT -p tcp --dport 5432 -s 10.0.1.0/24 -j ACCEPT
# Allow monitoring (Prometheus node exporter)
iptables -A INPUT -p tcp --dport 9100 -s 10.0.200.0/24 -j ACCEPT
# DNS resolution
iptables -A INPUT -p udp --sport 53 -j ACCEPT
iptables -A INPUT -p tcp --sport 53 -j ACCEPT
# NTP
iptables -A INPUT -p udp --sport 123 -j ACCEPT
# Block specific IP (incident response)
iptables -I INPUT 1 -s 203.0.113.50 -j DROP
UFW (Uncomplicated Firewall)
# Enable UFW with default deny
ufw default deny incoming
ufw default allow outgoing
ufw enable
# Allow SSH from management network
ufw allow from 10.0.100.0/24 to any port 22 proto tcp
# Allow HTTP/HTTPS
ufw allow 80/tcp
ufw allow 443/tcp
# Allow specific application profile
ufw allow 'Nginx Full'
# Rate limit SSH (max 6 connections in 30 seconds)
ufw limit ssh
# Allow port range
ufw allow 8000:8080/tcp
# Deny specific IP
ufw deny from 203.0.113.50
# Check status
ufw status verbose
ufw status numbered
# Delete a rule by number
ufw delete 3
# Application profiles
ufw app list
ufw app info 'Nginx Full'
nftables
Complete Server Configuration
#!/usr/sbin/nft -f
flush ruleset
# Define variables
define LAN = 10.0.0.0/16
define MGMT = 10.0.100.0/24
define MONITOR = 10.0.200.0/24
table inet filter {
# Rate limiting set
set rate_limit {
type ipv4_addr
flags dynamic,timeout
timeout 1m
}
chain input {
type filter hook input priority 0; policy drop;
# Connection tracking
ct state established,related accept
ct state invalid drop
# Loopback
iif "lo" accept
# ICMP and ICMPv6
ip protocol icmp icmp type { echo-request, destination-unreachable, time-exceeded } limit rate 10/second accept
ip6 nexthdr icmpv6 icmpv6 type { echo-request, nd-neighbor-solicit, nd-router-advert } accept
# SSH from management only
tcp dport 22 ip saddr $MGMT accept
…
常见问题
什么是“端口”和“协议”?
端口就像服务器上的房间号,每种服务(比如网页或邮件)都使用特定的端口。协议则是通信规则,比如 TCP 和 UDP,它们规定了数据如何传输。
“默认拒绝”是什么意思?
意思是防火墙会阻止所有没有被明确允许的连接。这是一种很强的安全措施,能确保只有必要的流量可以通过。
我可以阻止某个特定的 IP 地址吗?
可以。你可以添加规则,阻止来自你认为有恶意或不需要的特定 IP 地址的流量。
详情
作者的原始描述
Configure iptables, nftables, and cloud firewalls. Implement network segmentation and traffic filtering. Use when securing network perimeters or implementing security zones.
热度
- GitHub 星标
- 48k
- 排名
- #4623
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …
同一仓库的更多技能
00-andruia-consultant
48k帮你的智能体启动或改进 AI 项目。它可以分析代码、推荐工具,并用西班牙语制定行动计划。
007
48k让你的智能体执行安全审计和威胁建模。它有助于保护项目免受攻击和漏洞的威胁。
10-andruia-skill-smith
48k帮你的智能体创建或改进 AI 工具。它可以定义工具的工作方式、编写文档,并验证其结构。
20-andruia-niche-intelligence
48k让你的智能体创建某个特定行业的摘要。它有助于借助可靠的信息来源,了解项目的背景、规则、使用模式和风险。