[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6P3549FQRCCEXXX5YMRG49X":3,"skill-same:01M6P3549FQRCCEXXX5YMRG49X":70},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":38,"linkOnly":39,"markdownContent":40,"markdownBody":41,"frontMatter":42,"refName":30,"commitSha":51,"skillDirectory":52,"forksCount":13,"repositoryHtmlUrl":53,"repositoryHomepageUrl":6,"ownerHtmlUrl":54,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":55,"install":56,"resources":69},"01M6P3549FQRCCEXXX5YMRG49X","firewall-config",null,"Configure iptables, nftables, and cloud firewalls. Implement network segmentation and traffic filtering. Use when securing network perimeters or implementing security zones.","duc-duy-1612\u002FOnline-Delivery-Systems-Web","duc-duy-1612","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F192231384?v=4","01M6NSDKQQDKVTHZ8DZMZ1VYY6","01M6NSDKW8DDVTQHBT1HBDDJPT",0,"MIT","https:\u002F\u002Fgithub.com\u002Fduc-duy-1612\u002FOnline-Delivery-Systems-Web\u002Fblob\u002Fmain\u002F.agents\u002Fskills_archive\u002Ffirewall-config\u002FSKILL.md",[],[18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37],"config","firewall","firewall config","implementing","security","traffic","network segmentation","relevant","scripts","scope","critical","active","main","community","only","configure","devops-security","segmentation","network","assessment","2026-11-10 10:12:30",false,"---\nname: firewall-config\ndescription: Configure iptables, nftables, and cloud firewalls. Implement network\n  segmentation and traffic filtering. Use when securing network perimeters or implementing\n  security zones.\ncategory: security\nrisk: critical\nsource: https:\u002F\u002Fgithub.com\u002FBagelHole\u002FDevOps-Security-Agent-Skills\nsource_repo: BagelHole\u002FDevOps-Security-Agent-Skills\nsource_type: community\ndate_added: '2026-09-20'\nlicense: MIT\nlicense_source: https:\u002F\u002Fgithub.com\u002FBagelHole\u002FDevOps-Security-Agent-Skills\u002Fblob\u002Fmain\u002FLICENSE\ncompatibility: Requires the relevant security tooling (scanners, vault CLIs) and an\n  authorized scope for any active assessment. Docs-only; helper scripts and templates\n  not bundled.\nmetadata:\n  author: devops-skills\n  version: '1.0'\n---\n\n# Firewall Configuration\n\nConfigure host-based and cloud firewalls for network security.\n\n## When to Use This Skill\n\nUse this skill when:\n- Setting up a new server and need to restrict network access\n- Implementing network segmentation between application tiers\n- Configuring cloud security groups for AWS, GCP, or Azure resources\n- Migrating from iptables to nftables\n- Auditing existing firewall rules for compliance\n- Responding to a security incident requiring emergency network blocks\n\n## Prerequisites\n\n- Root or sudo access on Linux hosts\n- AWS CLI configured for cloud security groups\n- Understanding of TCP\u002FIP, ports, and protocols\n- Network diagram showing required traffic flows\n\n## iptables\n\n### Basic Setup with Default Deny\n\n```bash\n# Flush existing rules\niptables -F\niptables -X\niptables -t nat -F\niptables -t mangle -F\n\n# Default policies - deny all inbound, allow outbound\niptables -P INPUT DROP\niptables -P FORWARD DROP\niptables -P OUTPUT ACCEPT\n\n# Allow established connections\niptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT\n\n# Allow loopback\niptables -A INPUT -i lo -j ACCEPT\n\n# Drop invalid packets\niptables -A INPUT -m conntrack --ctstate INVALID -j DROP\n\n# Allow SSH (restrict to management subnet)\niptables -A INPUT -p tcp --dport 22 -s 10.0.100.0\u002F24 -j ACCEPT\n\n# Allow HTTP\u002FHTTPS from anywhere\niptables -A INPUT -p tcp -m multiport --dports 80,443 -j ACCEPT\n\n# Allow ICMP (ping) with rate limiting\niptables -A INPUT -p icmp --icmp-type echo-request -m limit --limit 1\u002Fs --limit-burst 4 -j ACCEPT\n\n# Log dropped packets (rate limited to avoid log flooding)\niptables -A INPUT -m limit --limit 5\u002Fmin -j LOG --log-prefix \"IPTABLES-DROP: \" --log-level 4\n\n# Save rules (Debian\u002FUbuntu)\niptables-save > \u002Fetc\u002Fiptables\u002Frules.v4\nip6tables-save > \u002Fetc\u002Fiptables\u002Frules.v6\n```\n\n### Anti-DDoS Rules\n\n```bash\n# SYN flood protection\niptables -A INPUT -p tcp --syn -m limit --limit 25\u002Fs --limit-burst 50 -j ACCEPT\niptables -A INPUT -p tcp --syn -j DROP\n\n# Limit new connections per source IP\niptables -A INPUT -p tcp --dport 80 -m connlimit --connlimit-above 50 -j REJECT\n\n# Block port scanning (detect TCP flags abuse)\niptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP\niptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP\niptables -A INPUT -p tcp --tcp-flags ALL FIN,URG,PSH -j DROP\niptables -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j DROP\niptables -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP\n```\n\n### Application-Specific Rules\n\n```bash\n# Web server with database backend\n# Allow app servers to reach database (port 5432)\niptables -A INPUT -p tcp --dport 5432 -s 10.0.1.0\u002F24 -j ACCEPT\n\n# Allow monitoring (Prometheus node exporter)\niptables -A INPUT -p tcp --dport 9100 -s 10.0.200.0\u002F24 -j ACCEPT\n\n# DNS resolution\niptables -A INPUT -p udp --sport 53 -j ACCEPT\niptables -A INPUT -p tcp --sport 53 -j ACCEPT\n\n# NTP\niptables -A INPUT -p udp --sport 123 -j ACCEPT\n\n# Block specific IP (incident response)\niptables -I INPUT 1 -s 203.0.113.50 -j DROP\n```\n\n## UFW (Uncomplicated Firewall)\n\n```bash\n# Enable UFW with default deny\nufw default deny incoming\nufw default allow outgoing\nufw enable\n\n# Allow SSH from management network\nufw allow from 10.0.100.0\u002F24 to any port 22 proto tcp\n\n# Allow HTTP\u002FHTTPS\nufw allow 80\u002Ftcp\nufw allow 443\u002Ftcp\n\n# Allow specific application profile\nufw allow 'Nginx Full'\n\n# Rate limit SSH (max 6 connections in 30 seconds)\nufw limit ssh\n\n# Allow port range\nufw allow 8000:8080\u002Ftcp\n\n# Deny specific IP\nufw deny from 203.0.113.50\n\n# Check status\nufw status verbose\nufw status numbered\n\n# Delete a rule by number\nufw delete 3\n\n# Application profiles\nufw app list\nufw app info 'Nginx Full'\n```\n\n## nftables\n\n### Complete Server Configuration\n\n```bash\n#!\u002Fusr\u002Fsbin\u002Fnft -f\nflush ruleset\n\n# Define variables\ndefine LAN = 10.0.0.0\u002F16\ndefine MGMT = 10.0.100.0\u002F24\ndefine MONITOR = 10.0.200.0\u002F24\n\ntable inet filter {\n  # Rate limiting set\n  set rate_limit {\n    type ipv4_addr\n    flags dynamic,timeout\n    timeout 1m\n  }\n\n  chain input {\n    type filter hook input priority 0; policy drop;\n\n    # Connection tracking\n    ct state established,related accept\n    ct state invalid drop\n\n    # Loopback\n    iif \"lo\" accept\n\n    # ICMP and ICMPv6\n    ip protocol icmp icmp type { echo-request, destination-unreachable, time-exceeded } limit rate 10\u002Fsecond accept\n    ip6 nexthdr icmpv6 icmpv6 type { echo-request, nd-neighbor-solicit, nd-router-advert } accept\n\n    # SSH from management only\n    tcp dport 22 ip saddr $MGMT accept\n\n    # HTTP\u002FHTTPS from anywhere\n    tcp dport { 80, 443 } accept\n\n    # Prometheus metrics from monitoring subnet\n    tcp dport 9100 ip saddr $MONITOR accept\n\n    # Rate limit new connections\n    tcp flags syn limit rate over 25\u002Fsecond burst 50 packets drop\n\n    # Log dropped traffic\n    log prefix \"nft-drop: \" level warn limit rate 5\u002Fminute\n  }\n\n  chain forward {\n    type filter hook forward priority 0; policy drop;\n  }\n\n  chain output {\n    type filter hook output priority 0; policy accept;\n\n    # Optional: restrict outbound to known destinations\n    # tcp dport { 80, 443, 53 } accept\n    # udp dport { 53, 123 } accept\n    # ct state established,related accept\n    # drop\n  }\n}\n\n# NAT table for port forwarding\ntable ip nat {\n  chain prerouting {\n    type nat hook prerouting priority -100;\n    # Forward port 8080 to internal app server\n    tcp dport 8080 dnat to 10.0.1.10:8080\n  }\n\n  chain postrouting {\n    type nat hook postrouting priority 100;\n    oifname \"eth0\" masquerade\n  }\n}\n```\n\n### nftables Management Commands\n\n```bash\n# Load configuration\nnft -f \u002Fetc\u002Fnftables.conf\n\n# List all rules\nnft list ruleset\n\n# List specific table\nnft list table inet filter\n\n# Add a rule dynamically\nnft add rule inet filter input tcp dport 8443 accept\n\n# Insert rule at position\nnft insert rule inet filter input position 5 ip saddr 10.0.50.0\u002F24 tcp dport 3306 accept\n\n# Delete a rule by handle\nnft -a list chain inet filter input  # show handles\nnft delete rule inet filter input handle 15\n\n# Monitor in real time\nnft monitor\n```\n\n## AWS Security Groups\n\n### Terraform Configuration\n\n```hcl\n# Web tier security group\nresource \"aws_security_group\" \"web\" {\n  name_prefix = \"web-sg-\"\n  vpc_id      = aws_vpc.main.id\n  description = \"Security group for web servers\"\n\n  ingress {\n    description = \"HTTPS from internet\"\n    from_port   = 443\n    to_port     = 443\n    protocol    = \"tcp\"\n    cidr_blocks = [\"0.0.0.0\u002F0\"]\n  }\n\n  ingress {\n    description = \"HTTP redirect\"\n    from_port   = 80\n    to_port     = 80\n    protocol    = \"tcp\"\n    cidr_blocks = [\"0.0.0.0\u002F0\"]\n  }\n\n  egress {\n    description = \"All outbound\"\n    from_port   = 0\n    to_port     = 0\n    protocol    = \"-1\"\n    cidr_blocks = [\"0.0.0.0\u002F0\"]\n  }\n\n  tags = {\n    Name        = \"web-sg\"\n    Environment = \"production\"\n    ManagedBy   = \"terraform\"\n  }\n}\n\n# App tier - only accepts traffic from web tier\nresource \"aws_security_group\" \"app\" {\n  name_prefix = \"app-sg-\"\n  vpc_id      = aws_vpc.main.id\n  description = \"Security group for application servers\"\n\n  ingress {\n    description     = \"HTTP from web tier\"\n    from_port       = 8080\n    to_port         = 8080\n    protocol        = \"tcp\"\n    security_groups = [aws_security_group.web.id]\n  }\n\n  egress {\n    from_port   = 0\n    to_port     = 0\n    protocol    = \"-1\"\n    cidr_blocks = [\"0.0.0.0\u002F0\"]\n  }\n}\n\n# Database tier - only accepts from app tier\nresource \"aws_security_group\" \"db\" {\n  name_prefix = \"db-sg-\"\n  vpc_id      = aws_vpc.main.id\n  description = \"Security group for database servers\"\n\n  ingress {\n    description     = \"PostgreSQL from app tier\"\n    from_port       = 5432\n    to_port         = 5432\n    protocol        = \"tcp\"\n    security_groups = [aws_security_group.app.id]\n  }\n\n  egress {\n    from_port   = 0\n    to_port     = 0\n    protocol    = \"-1\"\n    cidr_blocks = [\"0.0.0.0\u002F0\"]\n  }\n}\n```\n\n### AWS CLI Commands\n\n```bash\n# Create security group\naws ec2 create-security-group \\\n  --group-name web-sg \\\n  --description \"Web server SG\" \\\n  --vpc-id vpc-0abc123\n\n# Add inbound rule\naws ec2 authorize-security-group-ingress \\\n  --group-id sg-0abc123 \\\n  --protocol tcp --port 443 \\\n  --cidr 0.0.0.0\u002F0\n\n# Add rule referencing another security group\naws ec2 authorize-security-group-ingress \\\n  --group-id sg-0db456 \\\n  --protocol tcp --port 5432 \\\n  --source-group sg-0app789\n\n# Remove a rule\naws ec2 revoke-security-group-ingress \\\n  --group-id sg-0abc123 \\\n  --protocol tcp --port 22 \\\n  --cidr 0.0.0.0\u002F0\n\n# Describe rules\naws ec2 describe-security-group-rules \\\n  --filters Name=group-id,Values=sg-0abc123\n```\n\n## Firewall Rule Audit Script\n\n```bash\n#!\u002Fbin\u002Fbash\n# firewall-audit.sh - Audit current firewall rules for common issues\n\necho \"=== Firewall Audit Report ===\"\necho \"Date: $(date -u +%Y-%m-%dT%H:%M:%SZ)\"\necho \"Host: $(hostname)\"\necho \"\"\n\n# Check if firewall is active\nif command -v nft &>\u002Fdev\u002Fnull; then\n    echo \"--- nftables rules ---\"\n    nft list ruleset\nelif command -v iptables &>\u002Fdev\u002Fnull; then\n    echo \"--- iptables rules ---\"\n    iptables -L -n -v --line-numbers\nfi\n\necho \"\"\necho \"--- Open ports ---\"\nss -tlnp\n\necho \"\"\necho \"--- Potential issues ---\"\n\n# Check for overly permissive rules\nif iptables -L INPUT -n 2>\u002Fdev\u002Fnull | grep -q \"0.0.0.0\u002F0.*dpt:22\"; then\n    echo \"WARNING: SSH (port 22) open to 0.0.0.0\u002F0 - restrict to management subnet\"\nfi\n\nif iptables -L INPUT -n 2>\u002Fdev\u002Fnull | grep -q \"0.0.0.0\u002F0.*dpt:3306\"; then\n    echo \"CRITICAL: MySQL (port 3306) open to 0.0.0.0\u002F0\"\nfi\n\nif iptables -L INPUT -n 2>\u002Fdev\u002Fnull | grep -q \"0.0.0.0\u002F0.*dpt:5432\"; then\n    echo \"CRITICAL: PostgreSQL (port 5432) open to 0.0.0.0\u002F0\"\nfi\n\n# Check default policies\nDEFAULT_INPUT=$(iptables -L INPUT 2>\u002Fdev\u002Fnull | head -1 | grep -oP 'policy \\K\\w+')\nif [ \"$DEFAULT_INPUT\" = \"ACCEPT\" ]; then\n    echo \"CRITICAL: Default INPUT policy is ACCEPT - should be DROP\"\nfi\n```\n\n## Troubleshooting\n\n| Problem | Cause | Solution |\n|---------|-------|----------|\n| Locked out of SSH | Rule order or default deny applied before allow | Use out-of-band console access; add SSH allow rule first |\n| Rules lost after reboot | Rules not persisted | Install `iptables-persistent` or save to `\u002Fetc\u002Fnftables.conf` |\n| Docker bypasses iptables | Docker modifies iptables FORWARD chain | Use `DOCKER-USER` chain for custom rules; set `\"iptables\": false` in daemon.json |\n| nftables and iptables conflict | Both running simultaneously | Migrate fully to nftables; remove iptables packages |\n| AWS SG rule limit reached | Max 60 inbound rules per SG | Use prefix lists or consolidate CIDR ranges |\n| Legitimate traffic blocked | Rule ordering issue | Place more specific allow rules before general deny rules |\n\n## Best Practices\n\n- Default deny policy on all chains\n- Minimal rule sets - only open what is required\n- Regular rule audits (monthly minimum)\n- Log denied traffic for security monitoring\n- Document all rules with descriptions and ticket references\n- Use connection tracking for stateful inspection\n- Rate limit inbound connections to prevent DDoS\n- Separate management traffic from application traffic\n- Test rule changes in staging before production\n- Keep persistent backups of working rule sets\n\n## Related Skills\n\n- linux-hardening (`linux-hardening`) - System security\n- aws-vpc (`aws-vpc`) - AWS networking\n- zero-trust (`zero-trust`) - Identity-based access patterns\n- vpn-setup (`vpn-setup`) - Secure tunnel configuration\n\n## Limitations\n\n- Apply guidance only within authorized scope; test destructive steps in non-production first.\n- Docs-only import: upstream scripts and templates not bundled.\n\n### Example\n\n```bash\n# Read-only first: inventory before any active step.\nwhich \u003Ctool> && \u003Ctool> --help | head -n 20\n```\n\n> Adapted from [BagelHole\u002FDevOps-Security-Agent-Skills](https:\u002F\u002Fgithub.com\u002FBagelHole\u002FDevOps-Security-Agent-Skills) (MIT); frontmatter, When to Use\u002FLimitations, and safety boundaries added for upstream compliance. Docs-only import: helper scripts and templates not bundled.\n","# Firewall Configuration\n\nConfigure host-based and cloud firewalls for network security.\n\n## When to Use This Skill\n\nUse this skill when:\n- Setting up a new server and need to restrict network access\n- Implementing network segmentation between application tiers\n- Configuring cloud security groups for AWS, GCP, or Azure resources\n- Migrating from iptables to nftables\n- Auditing existing firewall rules for compliance\n- Responding to a security incident requiring emergency network blocks\n\n## Prerequisites\n\n- Root or sudo access on Linux hosts\n- AWS CLI configured for cloud security groups\n- Understanding of TCP\u002FIP, ports, and protocols\n- Network diagram showing required traffic flows\n\n## iptables\n\n### Basic Setup with Default Deny\n\n```bash\n# Flush existing rules\niptables -F\niptables -X\niptables -t nat -F\niptables -t mangle -F\n\n# Default policies - deny all inbound, allow outbound\niptables -P INPUT DROP\niptables -P FORWARD DROP\niptables -P OUTPUT ACCEPT\n\n# Allow established connections\niptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT\n\n# Allow loopback\niptables -A INPUT -i lo -j ACCEPT\n\n# Drop invalid packets\niptables -A INPUT -m conntrack --ctstate INVALID -j DROP\n\n# Allow SSH (restrict to management subnet)\niptables -A INPUT -p tcp --dport 22 -s 10.0.100.0\u002F24 -j ACCEPT\n\n# Allow HTTP\u002FHTTPS from anywhere\niptables -A INPUT -p tcp -m multiport --dports 80,443 -j ACCEPT\n\n# Allow ICMP (ping) with rate limiting\niptables -A INPUT -p icmp --icmp-type echo-request -m limit --limit 1\u002Fs --limit-burst 4 -j ACCEPT\n\n# Log dropped packets (rate limited to avoid log flooding)\niptables -A INPUT -m limit --limit 5\u002Fmin -j LOG --log-prefix \"IPTABLES-DROP: \" --log-level 4\n\n# Save rules (Debian\u002FUbuntu)\niptables-save > \u002Fetc\u002Fiptables\u002Frules.v4\nip6tables-save > \u002Fetc\u002Fiptables\u002Frules.v6\n```\n\n### Anti-DDoS Rules\n\n```bash\n# SYN flood protection\niptables -A INPUT -p tcp --syn -m limit --limit 25\u002Fs --limit-burst 50 -j ACCEPT\niptables -A INPUT -p tcp --syn -j DROP\n\n# Limit new connections per source IP\niptables -A INPUT -p tcp --dport 80 -m connlimit --connlimit-above 50 -j REJECT\n\n# Block port scanning (detect TCP flags abuse)\niptables -A INPUT -p tcp --tcp-flags ALL NONE -j DROP\niptables -A INPUT -p tcp --tcp-flags ALL ALL -j DROP\niptables -A INPUT -p tcp --tcp-flags ALL FIN,URG,PSH -j DROP\niptables -A INPUT -p tcp --tcp-flags SYN,RST SYN,RST -j DROP\niptables -A INPUT -p tcp --tcp-flags SYN,FIN SYN,FIN -j DROP\n```\n\n### Application-Specific Rules\n\n```bash\n# Web server with database backend\n# Allow app servers to reach database (port 5432)\niptables -A INPUT -p tcp --dport 5432 -s 10.0.1.0\u002F24 -j ACCEPT\n\n# Allow monitoring (Prometheus node exporter)\niptables -A INPUT -p tcp --dport 9100 -s 10.0.200.0\u002F24 -j ACCEPT\n\n# DNS resolution\niptables -A INPUT -p udp --sport 53 -j ACCEPT\niptables -A INPUT -p tcp --sport 53 -j ACCEPT\n\n# NTP\niptables -A INPUT -p udp --sport 123 -j ACCEPT\n\n# Block specific IP (incident response)\niptables -I INPUT 1 -s 203.0.113.50 -j DROP\n```\n\n## UFW (Uncomplicated Firewall)\n\n```bash\n# Enable UFW with default deny\nufw default deny incoming\nufw default allow outgoing\nufw enable\n\n# Allow SSH from management network\nufw allow from 10.0.100.0\u002F24 to any port 22 proto tcp\n\n# Allow HTTP\u002FHTTPS\nufw allow 80\u002Ftcp\nufw allow 443\u002Ftcp\n\n# Allow specific application profile\nufw allow 'Nginx Full'\n\n# Rate limit SSH (max 6 connections in 30 seconds)\nufw limit ssh\n\n# Allow port range\nufw allow 8000:8080\u002Ftcp\n\n# Deny specific IP\nufw deny from 203.0.113.50\n\n# Check status\nufw status verbose\nufw status numbered\n\n# Delete a rule by number\nufw delete 3\n\n# Application profiles\nufw app list\nufw app info 'Nginx Full'\n```\n\n## nftables\n\n### Complete Server Configuration\n\n```bash\n#!\u002Fusr\u002Fsbin\u002Fnft -f\nflush ruleset\n\n# Define variables\ndefine LAN = 10.0.0.0\u002F16\ndefine MGMT = 10.0.100.0\u002F24\ndefine MONITOR = 10.0.200.0\u002F24\n\ntable inet filter {\n  # Rate limiting set\n  set rate_limit {\n    type ipv4_addr\n    flags dynamic,timeout\n    timeout 1m\n  }\n\n  chain input {\n    type filter hook input priority 0; policy drop;\n\n    # Connection tracking\n    ct state established,related accept\n    ct state invalid drop\n\n    # Loopback\n    iif \"lo\" accept\n\n    # ICMP and ICMPv6\n    ip protocol icmp icmp type { echo-request, destination-unreachable, time-exceeded } limit rate 10\u002Fsecond accept\n    ip6 nexthdr icmpv6 icmpv6 type { echo-request, nd-neighbor-solicit, nd-router-advert } accept\n\n    # SSH from management only\n    tcp dport 22 ip saddr $MGMT accept\n\n    # HTTP\u002FHTTPS from anywhere\n    tcp dport { 80, 443 } accept\n\n    # Prometheus metrics from monitoring subnet\n    tcp dport 9100 ip saddr $MONITOR accept\n\n    # Rate limit new connections\n    tcp flags syn limit rate over 25\u002Fsecond burst 50 packets drop\n\n    # Log dropped traffic\n    log prefix \"nft-drop: \" level warn limit rate 5\u002Fminute\n  }\n\n  chain forward {\n    type filter hook forward priority 0; policy drop;\n  }\n\n  chain output {\n    type filter hook output priority 0; policy accept;\n\n    # Optional: restrict outbound to known destinations\n    # tcp dport { 80, 443, 53 } accept\n    # udp dport { 53, 123 } accept\n    # ct state established,related accept\n    # drop\n  }\n}\n\n# NAT table for port forwarding\ntable ip nat {\n  chain prerouting {\n    type nat hook prerouting priority -100;\n    # Forward port 8080 to internal app server\n    tcp dport 8080 dnat to 10.0.1.10:8080\n  }\n\n  chain postrouting {\n    type nat hook postrouting priority 100;\n    oifname \"eth0\" masquerade\n  }\n}\n```\n\n### nftables Management Commands\n\n```bash\n# Load configuration\nnft -f \u002Fetc\u002Fnftables.conf\n\n# List all rules\nnft list ruleset\n\n# List specific table\nnft list table inet filter\n\n# Add a rule dynamically\nnft add rule inet filter input tcp dport 8443 accept\n\n# Insert rule at position\nnft insert rule inet filter input position 5 ip saddr 10.0.50.0\u002F24 tcp dport 3306 accept\n\n# Delete a rule by handle\nnft -a list chain inet filter input  # show handles\nnft delete rule inet filter input handle 15\n\n# Monitor in real time\nnft monitor\n```\n\n## AWS Security Groups\n\n### Terraform Configuration\n\n```hcl\n# Web tier security group\nresource \"aws_security_group\" \"web\" {\n  name_prefix = \"web-sg-\"\n  vpc_id      = aws_vpc.main.id\n  description = \"Security group for web servers\"\n\n  ingress {\n    description = \"HTTPS from internet\"\n    from_port   = 443\n    to_port     = 443\n    protocol    = \"tcp\"\n    cidr_blocks = [\"0.0.0.0\u002F0\"]\n  }\n\n  ingress {\n    description = \"HTTP redirect\"\n    from_port   = 80\n    to_port     = 80\n    protocol    = \"tcp\"\n    cidr_blocks = [\"0.0.0.0\u002F0\"]\n  }\n\n  egress {\n    description = \"All outbound\"\n    from_port   = 0\n    to_port     = 0\n    protocol    = \"-1\"\n    cidr_blocks = [\"0.0.0.0\u002F0\"]\n  }\n\n  tags = {\n    Name        = \"web-sg\"\n    Environment = \"production\"\n    ManagedBy   = \"terraform\"\n  }\n}\n\n# App tier - only accepts traffic from web tier\nresource \"aws_security_group\" \"app\" {\n  name_prefix = \"app-sg-\"\n  vpc_id      = aws_vpc.main.id\n  description = \"Security group for application servers\"\n\n  ingress {\n    description     = \"HTTP from web tier\"\n    from_port       = 8080\n    to_port         = 8080\n    protocol        = \"tcp\"\n    security_groups = [aws_security_group.web.id]\n  }\n\n  egress {\n    from_port   = 0\n    to_port     = 0\n    protocol    = \"-1\"\n    cidr_blocks = [\"0.0.0.0\u002F0\"]\n  }\n}\n\n# Database tier - only accepts from app tier\nresource \"aws_security_group\" \"db\" {\n  name_prefix = \"db-sg-\"\n  vpc_id      = aws_vpc.main.id\n  description = \"Security group for database servers\"\n\n  ingress {\n    description     = \"PostgreSQL from app tier\"\n    from_port       = 5432\n    to_port         = 5432\n    protocol        = \"tcp\"\n    security_groups = [aws_security_group.app.id]\n  }\n\n  egress {\n    from_port   = 0\n    to_port     = 0\n    protocol    = \"-1\"\n    cidr_blocks = [\"0.0.0.0\u002F0\"]\n  }\n}\n```\n\n### AWS CLI Commands\n\n```bash\n# Create security group\naws ec2 create-security-group \\\n  --group-name web-sg \\\n  --description \"Web server SG\" \\\n  --vpc-id vpc-0abc123\n\n# Add inbound rule\naws ec2 authorize-security-group-ingress \\\n  --group-id sg-0abc123 \\\n  --protocol tcp --port 443 \\\n  --cidr 0.0.0.0\u002F0\n\n# Add rule referencing another security group\naws ec2 authorize-security-group-ingress \\\n  --group-id sg-0db456 \\\n  --protocol tcp --port 5432 \\\n  --source-group sg-0app789\n\n# Remove a rule\naws ec2 revoke-security-group-ingress \\\n  --group-id sg-0abc123 \\\n  --protocol tcp --port 22 \\\n  --cidr 0.0.0.0\u002F0\n\n# Describe rules\naws ec2 describe-security-group-rules \\\n  --filters Name=group-id,Values=sg-0abc123\n```\n\n## Firewall Rule Audit Script\n\n```bash\n#!\u002Fbin\u002Fbash\n# firewall-audit.sh - Audit current firewall rules for common issues\n\necho \"=== Firewall Audit Report ===\"\necho \"Date: $(date -u +%Y-%m-%dT%H:%M:%SZ)\"\necho \"Host: $(hostname)\"\necho \"\"\n\n# Check if firewall is active\nif command -v nft &>\u002Fdev\u002Fnull; then\n    echo \"--- nftables rules ---\"\n    nft list ruleset\nelif command -v iptables &>\u002Fdev\u002Fnull; then\n    echo \"--- iptables rules ---\"\n    iptables -L -n -v --line-numbers\nfi\n\necho \"\"\necho \"--- Open ports ---\"\nss -tlnp\n\necho \"\"\necho \"--- Potential issues ---\"\n\n# Check for overly permissive rules\nif iptables -L INPUT -n 2>\u002Fdev\u002Fnull | grep -q \"0.0.0.0\u002F0.*dpt:22\"; then\n    echo \"WARNING: SSH (port 22) open to 0.0.0.0\u002F0 - restrict to management subnet\"\nfi\n\nif iptables -L INPUT -n 2>\u002Fdev\u002Fnull | grep -q \"0.0.0.0\u002F0.*dpt:3306\"; then\n    echo \"CRITICAL: MySQL (port 3306) open to 0.0.0.0\u002F0\"\nfi\n\nif iptables -L INPUT -n 2>\u002Fdev\u002Fnull | grep -q \"0.0.0.0\u002F0.*dpt:5432\"; then\n    echo \"CRITICAL: PostgreSQL (port 5432) open to 0.0.0.0\u002F0\"\nfi\n\n# Check default policies\nDEFAULT_INPUT=$(iptables -L INPUT 2>\u002Fdev\u002Fnull | head -1 | grep -oP 'policy \\K\\w+')\nif [ \"$DEFAULT_INPUT\" = \"ACCEPT\" ]; then\n    echo \"CRITICAL: Default INPUT policy is ACCEPT - should be DROP\"\nfi\n```\n\n## Troubleshooting\n\n| Problem | Cause | Solution |\n|---------|-------|----------|\n| Locked out of SSH | Rule order or default deny applied before allow | Use out-of-band console access; add SSH allow rule first |\n| Rules lost after reboot | Rules not persisted | Install `iptables-persistent` or save to `\u002Fetc\u002Fnftables.conf` |\n| Docker bypasses iptables | Docker modifies iptables FORWARD chain | Use `DOCKER-USER` chain for custom rules; set `\"iptables\": false` in daemon.json |\n| nftables and iptables conflict | Both running simultaneously | Migrate fully to nftables; remove iptables packages |\n| AWS SG rule limit reached | Max 60 inbound rules per SG | Use prefix lists or consolidate CIDR ranges |\n| Legitimate traffic blocked | Rule ordering issue | Place more specific allow rules before general deny rules |\n\n## Best Practices\n\n- Default deny policy on all chains\n- Minimal rule sets - only open what is required\n- Regular rule audits (monthly minimum)\n- Log denied traffic for security monitoring\n- Document all rules with descriptions and ticket references\n- Use connection tracking for stateful inspection\n- Rate limit inbound connections to prevent DDoS\n- Separate management traffic from application traffic\n- Test rule changes in staging before production\n- Keep persistent backups of working rule sets\n\n## Related Skills\n\n- linux-hardening (`linux-hardening`) - System security\n- aws-vpc (`aws-vpc`) - AWS networking\n- zero-trust (`zero-trust`) - Identity-based access patterns\n- vpn-setup (`vpn-setup`) - Secure tunnel configuration\n\n## Limitations\n\n- Apply guidance only within authorized scope; test destructive steps in non-production first.\n- Docs-only import: upstream scripts and templates not bundled.\n\n### Example\n\n```bash\n# Read-only first: inventory before any active step.\nwhich \u003Ctool> && \u003Ctool> --help | head -n 20\n```\n\n> Adapted from [BagelHole\u002FDevOps-Security-Agent-Skills](https:\u002F\u002Fgithub.com\u002FBagelHole\u002FDevOps-Security-Agent-Skills) (MIT); frontmatter, When to Use\u002FLimitations, and safety boundaries added for upstream compliance. Docs-only import: helper scripts and templates not bundled.\n",{"name":5,"risk":28,"source":43,"license":14,"category":22,"metadata":44,"date_added":47,"description":7,"source_repo":48,"source_type":31,"compatibility":49,"license_source":50},"https:\u002F\u002Fgithub.com\u002FBagelHole\u002FDevOps-Security-Agent-Skills",{"author":45,"version":46},"devops-skills","1.0","2026-09-20","BagelHole\u002FDevOps-Security-Agent-Skills","Requires the relevant security tooling (scanners, vault CLIs) and an authorized scope for any active assessment. Docs-only; helper scripts and templates not bundled.","https:\u002F\u002Fgithub.com\u002FBagelHole\u002FDevOps-Security-Agent-Skills\u002Fblob\u002Fmain\u002FLICENSE","f3312ba749561b6159f477dbfc9313c875d40a56",".agents\u002Fskills_archive\u002Ffirewall-config","https:\u002F\u002Fgithub.com\u002Fduc-duy-1612\u002FOnline-Delivery-Systems-Web","https:\u002F\u002Fgithub.com\u002Fduc-duy-1612","2026-10-25 23:50:58",{"source":8,"skillName":5,"commands":57,"prompt":67,"zipAvailable":68},[58,61,64],{"tool":59,"command":60},"npx","npx skills add duc-duy-1612\u002FOnline-Delivery-Systems-Web --skill firewall-config",{"tool":62,"command":63},"bunx","bunx skills add duc-duy-1612\u002FOnline-Delivery-Systems-Web --skill firewall-config",{"tool":65,"command":66},"pnpm","pnpm dlx skills add duc-duy-1612\u002FOnline-Delivery-Systems-Web --skill firewall-config","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fduc-duy-1612\u002FOnline-Delivery-Systems-Web\u002Fblob\u002Fmain\u002F.agents\u002Fskills_archive\u002Ffirewall-config\u002FSKILL.md",true,[],[71,84,108,133,150,170],{"skillNo":72,"name":73,"nameZh":6,"description":74,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":75,"categories":76,"keywords":77,"publishedAt":38},"01M6Q0FA5FZ410Z33Z3TFQ4DBA","zero-trust","Implement zero-trust network architecture. Configure identity-based access, micro-segmentation, and continuous verification. Use when implementing modern security architectures.","https:\u002F\u002Fgithub.com\u002Fduc-duy-1612\u002FOnline-Delivery-Systems-Web\u002Fblob\u002Fmain\u002F.agents\u002Fskills_archive\u002Fzero-trust\u002FSKILL.md",[],[78,79,80,81,37,82,73,35,34,83,33,32,31,30,29,28,27,26,25,21],"ZeRO","trust","zero trust","architecture","verification","access",{"skillNo":85,"name":86,"nameZh":6,"description":87,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":88,"categories":89,"keywords":90,"publishedAt":38},"01M6Q0F1YZJW3KX5FBKEVZ8CV4","zcode-delegate","Delegate coding tasks to the Z.AI ZCode CLI only when the user explicitly requests it, while the orchestrator retains review and landing responsibility.","https:\u002F\u002Fgithub.com\u002Fduc-duy-1612\u002FOnline-Delivery-Systems-Web\u002Fblob\u002Fmain\u002F.agents\u002Fskills_archive\u002Fzcode-delegate\u002FSKILL.md",[],[91,92,93,94,95,96,97,98,99,100,101,102,103,32,104,31,105,106,28,107],"delegate","zcode","zcode delegate","review","cli","orchestration","tasks","run","Bash","model","node","read","orchestrator","files","desktop app","app","agent-orchestration",{"skillNo":109,"name":110,"nameZh":6,"description":111,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":112,"categories":113,"keywords":114,"publishedAt":38},"01M6Q0ETK41VGNMYEXW0T00AJN","youtube-transcript","Fetch YouTube transcripts through DeepAPI or local fallback tooling and save clean text output.","https:\u002F\u002Fgithub.com\u002Fduc-duy-1612\u002FOnline-Delivery-Systems-Web\u002Fblob\u002Fmain\u002F.agents\u002Fskills_archive\u002Fyoutube-transcript\u002FSKILL.md",[],[115,116,117,118,119,120,121,122,123,124,125,126,127,31,30,128,129,130,131,132],"transcript","youtube transcript","youtube","safe","github","codex","research","license","https","text","fetch","tooling","clean","local","output","deepapi","youtube transcripts","blob",{"skillNo":134,"name":135,"nameZh":6,"description":136,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":137,"categories":138,"keywords":139,"publishedAt":38},"01M6Q0EPPH2PVMDW40017F8WX0","youtube-transcript-skills","Fetch YouTube video transcripts, search videos\u002Fchannels, browse channels, and extract playlists via the getyoutubetranscript.com API - free tier, no card required.","https:\u002F\u002Fgithub.com\u002Fduc-duy-1612\u002FOnline-Delivery-Systems-Web\u002Fblob\u002Fmain\u002F.agents\u002Fskills_archive\u002Fyoutube-transcript-skills\u002FSKILL.md",[],[115,116,117,140,118,141,119,120,122,142,143,144,145,125,146,31,30,147,148,149],"youtube transcript skills","gemini","search","api","Video","browse","api-integration","free","card","channels",{"skillNo":151,"name":152,"nameZh":6,"description":153,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":154,"categories":155,"keywords":156,"publishedAt":38},"01M6Q0EAB96PX83W5PTE8A0R8D","youtube-notetaker","Turn YouTube talks into local study notes with slides, transcripts, editable annotations, and a markdown-backed viewer.","https:\u002F\u002Fgithub.com\u002Fduc-duy-1612\u002FOnline-Delivery-Systems-Web\u002Fblob\u002Fmain\u002F.agents\u002Fskills_archive\u002Fyoutube-notetaker\u002FSKILL.md",[],[117,157,158,95,118,159,160,161,162,122,144,163,164,165,166,30,167,128,168,169],"youtube notetaker","notetaker","workflow","official","notes","code","markdown","slides","annotations","README","study","dair-academy","viewer",{"skillNo":171,"name":172,"nameZh":6,"description":173,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":174,"categories":175,"keywords":176,"publishedAt":38},"01M6Q0E55F0GW5MX48V8HXS8B5","youtube-full","Fetch YouTube transcripts, search videos, browse channels, and extract playlists via TranscriptAPI — no yt-dlp, no Google API key, works from any cloud server.","https:\u002F\u002Fgithub.com\u002Fduc-duy-1612\u002FOnline-Delivery-Systems-Web\u002Fblob\u002Fmain\u002F.agents\u002Fskills_archive\u002Fyoutube-full\u002FSKILL.md",[],[177,117,178,179,118,141,142,180,181,143,144,145,125,182,146,31,30,147,183,131],"youtube full","full","google","server","dlp","credits","automatic"]