Skip to main content

iptables-graph

Visualize iptables packet flow as Graphviz diagrams. Convert iptables-save output to DOT, SVG, or PNG formats.

Inspired by AChingYo/iptables-graph

PyPI Docker License

Features

  • 📊 Visualize packet flow through all iptables tables (raw, mangle, nat, filter)
  • 🎨 Color-coded tables and chains for easy understanding
  • 🔗 Show custom chains and jump targets
  • 📤 Multiple output formats: DOT, SVG, PNG
  • 🐳 Docker-based (no host dependencies!)
  • 📦 PyPI package (pipx install)

Quick Start

Option 1: Docker (Recommended)

No installation required! Just pull and run:

# Pull from Docker Hub
docker pull sanghaklee/iptables-graph

# Use it
sudo iptables-save | docker run --rm -i sanghaklee/iptables-graph

# Generate SVG
sudo iptables-save | docker run --rm -i sanghaklee/iptables-graph -f svg > graph.svg

# Generate PNG
sudo iptables-save | docker run --rm -i sanghaklee/iptables-graph -f png > example.png

Create an alias for convenience:

# Add to ~/.bashrc or ~/.zshrc
alias iptables-graph='docker run --rm -i sanghaklee/iptables-graph'

# Now use it like a regular command
sudo iptables-save | iptables-graph
sudo iptables-save | iptables-graph -f svg > graph.svg

Option 2: PyPI Package

Install via pip:

pipx install iptables-graph

Use it:

# Generate DOT format
sudo iptables-save | iptables-graph > graph.dot

# Generate SVG (requires graphviz installed)
sudo iptables-save | iptables-graph -f svg > graph.svg

# Generate PNG (requires graphviz installed)
sudo iptables-save | iptables-graph -f png > example.png

Note: For SVG/PNG conversion, you need to install graphviz:

# Debian/Ubuntu
sudo apt-get install graphviz

# RHEL/CentOS
sudo yum install graphviz

# macOS
brew install graphviz

Usage

Basic DOT Output

sudo iptables-save | iptables-graph

Output:

digraph {
    graph [pad="0.5", nodesep="0.5", ranksep="2"];
    node [shape=plain]
    rankdir=LR;
    ...
}

Generate SVG Diagram

sudo iptables-save | iptables-graph -f svg > graph.svg

Generate PNG Image

sudo iptables-save | iptables-graph -f png > example.png

Read from File

# Save iptables rules to file
sudo iptables-save > rules.txt

# Generate diagram
cat rules.txt | iptables-graph -f svg > diagram.svg

Using with Docker Volumes

# For file input/output with Docker
docker run --rm sanghaklee/iptables-graph \
  -v $(pwd):/data
  -i /data/iptables-save.txt 
  -f svg 
  -o /data/diagram.svg

Command Line Options

usage: iptables-graph [-h] [-i INPUT] [-o OUTPUT] [-f {dot,svg,png}]

iptables-save output → Graphviz converter (dot/svg/png)

optional arguments:
  -h, --help            show this help message and exit
  -i INPUT, --input INPUT
                        Input file (default: stdin)
  -o OUTPUT, --output OUTPUT
                        Output file (default: stdout)
  -f {dot,svg,png}, --format {dot,svg,png}
                        Output format: dot (default), svg, or png

Example Output

example.png

Color Scheme

  • 🔴 raw table: Red (#FA7070)
  • 🔵 mangle table: Blue (#AEE2FF)
  • 🟣 nat table: Purple (#E5D1FA)
  • 🟢 filter table: Green (#BEF0CB)

How It Works

  1. Parse iptables-save output to extract rules, chains, and policies
  2. Generate Graphviz DOT format with color-coded tables
  3. Convert (optional) to SVG or PNG using graphviz

Requirements

Docker Method

  • Docker only

PyPI Method

  • Python 3.7+
  • Graphviz (optional, for SVG/PNG conversion)

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for development setup, building, and release process.

License

MIT License

Links

Release files for iptables-graph 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for iptables-graph 1.0.0
File Size Uploaded
iptables_graph-1.0.0.tar.gz 7.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for iptables-graph 1.0.0
File Interpreter ABI Platform
iptables_graph-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size:14.9 kB

Release files / iptables_graph-1.0.0.tar.gz

Download URL iptables_graph-1.0.0.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
d8659345a5ddf6af5be67d215827f2943887b2df7a3bc1bf265e672c9a687958
BLAKE2b-256 checksum
How to use checksums
6d03814f31de10833fe96a4743bd8f4750bd88e08c38fae855ae85f2831913f9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.10

Release files / iptables_graph-1.0.0-py3-none-any.whl

Download URL iptables_graph-1.0.0-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
66ffbbd8c088a2d0ea4a651cd40cba3b3883a6f525efb578da09044496a2868d
BLAKE2b-256 checksum
How to use checksums
bc1a72a4506fb6c7aafe6be49ecb4163d210754f2ebcfc6f02fa0700f036f83d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.8.10

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page