iptables to UFW Command Converter & Batch Translator

Convert raw Linux iptables CLI commands and multi-line iptables-save rule dumps into clean, executable ufw (Uncomplicated Firewall) scripts with automated anti-lockout safeguards.

How to Convert iptables Rules to UFW

1

Paste iptables Rules

Paste raw iptables CLI commands or full iptables-save rule exports into the editor.

2

Configure Safeguards

Ensure SSH anti-lockout protection and baseline default policies are selected to protect remote server access.

3

Execute Migration Script

Click "Convert to UFW Commands" to generate a ready-to-run bash script or copy individual sudo ufw commands.

Tool Options

SSH Anti-Lockout Protection

Automatically prepends sudo ufw allow 22/tcp to prevent administrators from inadvertently severing SSH terminal sessions.

CIDR, Interface & Port Mapping

Accurately converts port ranges (8000:8080), source/dest CIDRs, in/out network interfaces, and drop/reject targets.

NAT & Routing Edge-Case Alerts

Identifies advanced NAT and port-forwarding rules that require direct placement inside /etc/ufw/before.rules.

Your Data Privacy

Web Tool
Privacy-First Architecture
Most of our web tools process your data entirely in-browser. Where server processing is technically required, payloads are evaluated statelessly in-memory and are never stored, saved, or logged.
REST API
Stateless In-Memory Processing
When you use our API endpoints, your requests are processed strictly in-memory without persistent database storage, disk logging, or data retention.
Want to learn more about how we safeguard your information and infrastructure?
Read our full Privacy Policy for detailed security standards, data retention principles, and compliance guarantees.

What does the iptables to UFW Command Converter & Batch Translator do?

The iptables to UFW Command Converter & Batch Translator translates raw Linux iptables CLI commands and multi-line iptables-save dumps into clean, modern ufw (Uncomplicated Firewall) rules and ready-to-run bash migration scripts. It accurately maps ports, CIDR subnets, network interfaces, and targets (ACCEPT, DROP, REJECT), while providing explicit edge-case alerts for NAT / port-forwarding rules and automated anti-lockout SSH safeguards.

Core Concepts

Understanding firewall translation from low-level iptables to ufw:

  • Syntax Simplification: Transforms verbose kernel Netfilter chains (iptables -A INPUT -s 192.168.1.50 -p tcp --dport 3306 -j ACCEPT) into readable UFW commands (ufw allow from 192.168.1.50 to any port 3306 proto tcp).
  • Anti-Lockout Safeguards: Remote server migrations risk disconnecting active SSH sessions if incoming port 22 isn't explicitly permitted prior to firewall activation. The tool automatically injects sudo ufw allow 22/tcp before ufw enable.
  • Advanced NAT & Packet Mangling Detection: The UFW CLI does not natively manage NAT (-t nat), PREROUTING, or MASQUERADE directives. The tool flags these rules with explicit instructions to append them into /etc/ufw/before.rules.

How to use the tool?

  1. Paste iptables Rules: Paste single CLI commands or multi-line iptables-save exports into the input box or click Load Sample.
  2. Toggle Migration Safeguards: Ensure SSH Anti-Lockout (allow 22/tcp) and baseline policy options are configured.
  3. Convert & Execute: Click Convert to UFW Commands to generate the .sh migration script. Click Copy or Download to save ufw-migration.sh.

Related Developer Utilities

If you work with Linux servers, network administration, and firewall security, explore these complementary tools:

REST API Integration

Blueutils provides a free REST API endpoint (POST https://blueutils.com/api/linux/iptables-to-ufw) to programmatically convert iptables rules into ufw commands and executable migration scripts.

API Request Parameters

Name Type Description Example
rawText String Multi-line iptables CLI commands or iptables-save dump. "iptables -A INPUT -p tcp --dport 80 -j ACCEPT"
options.enableSshSafeguard Boolean Prepend ufw allow 22/tcp safeguard. Default: true. true
options.includeDefaultPolicies Boolean Include deny incoming / allow outgoing defaults. Default: true. true
options.enableUfwAtEnd Boolean Append ufw --force enable at end. Default: true. true

API Request Payload Examples

cURL

curl -X POST https://blueutils.com/api/linux/iptables-to-ufw \
  -H "Content-Type: application/json" \
  -d '{
    "rawText": "iptables -A INPUT -p tcp --dport 22 -j ACCEPT\niptables -A INPUT -p tcp --dport 80 -j ACCEPT\niptables -A INPUT -s 10.0.0.0/8 -j DROP",
    "options": {
      "enableSshSafeguard": true,
      "includeDefaultPolicies": true,
      "enableUfwAtEnd": true
    }
  }'

Python

import requests

url = "https://blueutils.com/api/linux/iptables-to-ufw"
payload = {
    "rawText": "iptables -A INPUT -p tcp --dport 22 -j ACCEPT\niptables -A INPUT -p tcp --dport 80 -j ACCEPT",
    "options": {
        "enableSshSafeguard": True,
        "includeDefaultPolicies": True,
        "enableUfwAtEnd": True
    }
}
headers = {"Content-Type": "application/json"}
response = requests.post(url, json=payload, headers=headers)
print(response.json())

Java

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        String jsonPayload = """
            {
                "rawText": "iptables -A INPUT -p tcp --dport 80 -j ACCEPT"
            }
            """;

        HttpClient client = HttpClient.newHttpClient();
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://blueutils.com/api/linux/iptables-to-ufw"))
            .header("Content-Type", "application/json")
            .POST(HttpRequest.BodyPublishers.ofString(jsonPayload))
            .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.body());
    }
}

API Response Parameters

Name Type Description Example
isValid Boolean Indicates whether translation succeeded. true
totalRulesParsed Number Total lines evaluated in source input. 4
translatedRulesCount Number Count of unique UFW commands generated. 2
ufwCommands Array Array of individual translated sudo ufw ... strings. ["sudo ufw allow 22/tcp", "sudo ufw allow 80/tcp"]
shellScript String Complete executable bash migration script. "#!/usr/bin/env bash\n..."
warnings Array Advanced rules requiring /etc/ufw/before.rules. [{ "line": 4, "reason": "..." }]

API Response Payload Examples

Success Response (HTTP 200 OK)

{
  "isValid": true,
  "totalRulesParsed": 2,
  "translatedRulesCount": 2,
  "ufwCommands": [
    "sudo ufw allow 22/tcp",
    "sudo ufw allow 80/tcp"
  ],
  "shellScript": "#!/usr/bin/env bash\nset -e\nsudo ufw allow 22/tcp\nsudo ufw default deny incoming\nsudo ufw default allow outgoing\nsudo ufw allow 22/tcp\nsudo ufw allow 80/tcp\nsudo ufw --force enable\nsudo ufw status verbose"
}

Validation Failure Response (HTTP 400 Bad Request)

{
  "isValid": false,
  "error": "No translatable iptables rules found in provided input. Expected syntax: iptables -A INPUT ..."
}

Rate Limit Exceeded Response (HTTP 429 Too Many Requests)

{
  "error": "API rate limit exceeded. Please wait or contact support@blueutils.com."
}

Why use an API to convert iptables to UFW?

Integrating the iptables to UFW Translation API into server migration scripts, Ansible playbooks, or AI agent tool calling provides key benefits:

  • Automated Infrastructure Migration: Translates legacy firewall initialization dumps directly into idempotent UFW configuration commands during server upgrades.
  • Optimized Token Efficiency for AI Agents: LLMs frequently confuse UFW syntax rules regarding port ranges and from ... to any port ... clauses. Calling the API produces verified shell scripts deterministically.
  • Deterministic Security Safeguards: Prevents SSH terminal lockouts by enforcing anti-lockout rules before firewall enablement.

Native Usage

How to manage and verify firewall migrations natively in Linux:

Linux / Unix (Bash)

# Export active iptables rules
sudo iptables-save > /tmp/iptables.rules

# Enable UFW baseline policies
sudo ufw default deny incoming
sudo ufw default allow outgoing

# Allow SSH before enabling
sudo ufw allow 22/tcp

# Enable and inspect UFW status
sudo ufw --force enable
sudo ufw status numbered

Windows (PowerShell)

# Copy generated migration script to remote server and execute
scp ufw-migration.sh user@server:/tmp/
ssh -t user@server "chmod +x /tmp/ufw-migration.sh && sudo /tmp/ufw-migration.sh"

Windows (Command Prompt)

:: Copy generated migration script to remote server and execute
scp ufw-migration.sh user@server:/tmp/
ssh -t user@server "chmod +x /tmp/ufw-migration.sh && sudo /tmp/ufw-migration.sh"

Python

Using Python:

import re

def convert_simple_iptables(rule):
    match = re.search(r'--dport\s+(\d+)\s+-j\s+(ACCEPT|DROP)', rule)
    if match:
        port, action = match.group(1), match.group(2)
        ufw_act = 'allow' if action == 'ACCEPT' else 'deny'
        return f"sudo ufw {ufw_act} {port}/tcp"
    return "# Manual translation required"

print(convert_simple_iptables("iptables -A INPUT -p tcp --dport 443 -j ACCEPT"))

Java

Using Java:

public class IptablesToUfwExample {
    public static void main(String[] args) {
        String iptablesRule = "iptables -A INPUT -p tcp --dport 80 -j ACCEPT";
        if (iptablesRule.contains("--dport 80") && iptablesRule.contains("ACCEPT")) {
            System.out.println("sudo ufw allow 80/tcp");
        }
    }
}

Frequently Asked Questions (FAQ)

How do I convert iptables rules into UFW commands?

Paste your raw iptables CLI commands or iptables-save file into the input box and click Convert to UFW Commands. The tool maps ports, IP addresses, CIDR ranges, and interfaces into clean sudo ufw commands.

How does the tool prevent SSH lockout?

When SSH Anti-Lockout is checked, the tool automatically prepends sudo ufw allow 22/tcp before any default deny policies or ufw enable commands to ensure remote administration is preserved.

How are NAT and port-forwarding rules handled?

Because the basic UFW CLI does not manage kernel NAT or PREROUTING tables, the converter automatically detects these rules and displays explicit instructions on how to append them to /etc/ufw/before.rules.

Rate Limits

UI Limits
100 uses per 15 minutes
Max payload size: 5 MB
API Limits
5 requests per 60 minutes
Max payload size: 256 KB
Need higher API rate limits, increased payload sizes, or custom developer solutions?
Contact our engineering team at support@blueutils.com for custom rate limit increases, higher quota allocations, or tailored enterprise integrations.