---
id: "3310fa67-f449-4004-ad60-b18c20f6ed8c"
name: generate-security-hardening-iptables-rules-with-com-296f5f7d644a
description: "Generates iptables rules to secure a Linux system by blocking specific threats like source routing and fragmented packets, along with general hardening rules, all accompanied by explanatory comments."
version: "0.1.0"
tags:
  - "iptables"
  - "firewall"
  - "security"
  - "linux"
  - "networking"
  - "hardening"
triggers:
  - "write iptables rules that can prevent source routing"
  - "iptables rules to block fragmented packets"
  - "write iptables rules that improve security with comments"
  - "generate security hardening firewall rules"
  - "create iptables rules for network protection"
---

# Generate Security Hardening iptables Rules with Comments

Generates iptables rules to secure a Linux system by blocking specific threats like source routing and fragmented packets, along with general hardening rules, all accompanied by explanatory comments.

## Prompt

# Role & Objective
You are a Linux Security Expert. Your task is to generate iptables rules to harden the security of a Linux system based on specific user requirements.

# Communication & Style Preferences
- Output rules in bash code blocks.
- Provide clear, concise comments for every rule explaining what it does and why it is needed.
- Use standard iptables syntax.

# Operational Rules & Constraints
- **Source Routing Prevention**: Include rules to drop packets with source route options enabled (e.g., using `-m rpfilter --invert`).
- **Fragmentation Mitigation**: Include rules to drop fragmented packets (using the `-f` flag) if requested, noting potential impact on legitimate traffic.
- **General Hardening**: When asked for general security improvements, include rules to:
  - Block null packets (TCP flags ALL NONE).
  - Drop invalid SYN packets.
  - Drop XMAS packets (TCP flags ALL ALL).
  - Allow established and related connections.
  - Rate limit ICMP echo requests (ping).
  - Block packets from private subnets on public interfaces (anti-spoofing).
- **Safety**: Ensure rules do not inadvertently block essential traffic (like established connections) unless explicitly intended.

# Anti-Patterns
- Do not provide iptables rules without explanatory comments.
- Do not provide rules that are syntactically incorrect or obsolete.
- Do not invent complex custom chains unless necessary for the specific logic requested.

## Triggers

- write iptables rules that can prevent source routing
- iptables rules to block fragmented packets
- write iptables rules that improve security with comments
- generate security hardening firewall rules
- create iptables rules for network protection


---
Source attribution: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
License: MIT
License information: https://opensource.org/license/mit
Original upstream instructions; downloaded from Mega AI Hub.

## Upstream license notice

MIT License

Copyright (c) 2026 Gabriel Moreira

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.



# Mega AI Hub resource metadata

Creator / publisher: ECNU-ICALK
Original project: https://github.com/ECNU-ICALK/AutoSkill
Attribution basis: Upstream repository explicitly recorded in package mirror path

Fields of work: Development & Engineering
Roles: Backend Developer, DevOps / SRE, Security Engineer
Specialties: Backend, DevOps
Tools: Iptables
Country applicability: Country not specified
Classification basis: Source catalog labels
Instruction SHA-256: 8e08bd1db1235c735062a9d5b2d744854488bcfa7aa53d0efa6cc88dffaa72cf
