PHPackages                             3jy/iptables - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. 3jy/iptables

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

3jy/iptables
============

Class to manage entries in iptables.

1.2(8y ago)032MITPHP

Since Feb 11Pushed 8y ago1 watchersCompare

[ Source](https://github.com/3jy/iptables)[ Packagist](https://packagist.org/packages/3jy/iptables)[ RSS](/packages/3jy-iptables/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (1)Versions (4)Used By (0)

Parser for iptables
===================

[](#parser-for-iptables)

**iptable** library allows you to quick and easy parse and manipulate iptables records via PHP. As a main feature it parse raw iptable dump and build full objected tree with chains and rules. It moves almost all functionality which give you *iptables*.

Not all patches are implemented - for my purposes there was no need to do that - but it should be enough for most use cases.

Installation
------------

[](#installation)

The simpliest way to install iptables is by the composer.

```
composer require 3jy/iptables

```

Of course you can also download that repository and load all classes from src into your project (don't forget to load all required files).

Usage
-----

[](#usage)

Parsing raw iptables dump build chains tree connected to one of five default tables in `iptables`.

```
use plugowski\iptables\IptablesService;
use plugowski\iptables\Table\Table;
use plugowski\iptables\Table\TableFactory;

$iptables = new IptablesService();
$table = (new TableFactory())->build(Table::TABLE_MANGLE);
$table->setRaw(shell_exec('iptables -nL --line-numbers -t ' . Table::TABLE_MANGLE));

$result = $iptables->parseIptablesChains($table);
```

As result of above code you should get `Table` object with `Chain` collection:

```
$chains = $iptables->getChainsList();
```

Connections
-----------

[](#connections)

Each `Table` got `Chains` and each `Chain` got `Rules` with properties which describes all selected options. Using iptables class you can simply find specified chain and get list of all rules in it.

Example
-------

[](#example)

Some examples you can check directly in tests. But for quick review I also put it here.

Let's get that iptables settings and we want edit first record - set source to `127.0.0.1`:

```
Chain INPUT (policy DROP)
num  target     prot opt source               destination
1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
2    DROP       all  --  0.0.0.0/0            0.0.0.0/0           state INVALID
3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
4    DROP       tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:22 state NEW
5    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           MAC 00:00:00:00:11:22

```

I assume that we already have parsed table under `$result` var, so the easiest way to do that is:

```
$newRule = new Rule('ACCEPT', 'tcp', '127.0.0.1');
$cmd = $result->getChainByName('INPUT')->replaceRule($newRule, 1);
```

First rule in object has been changed and in result we got command in `$cmd`:

```
iptables -R INPUT 1 -t mangle  --proto tcp --source 127.0.0.1 --jump ACCEPT

```

Command
-------

[](#command)

Command class allows you to generate plain shell commands to manage iptables (only return as strings without execute!).

```
// To create shell comand like that:
// iptables -A INPUT -t mangle --match mac --mac-source 11:22:33:aa:bb:cc --jump RETURN

$command = new Command(Table::TABLE_MANGLE);
$cmd = $command->setMatch('mac', ['source' => '11:22:33:aa:bb:cc'])
        ->setJump('RETURN')
        ->append('INPUT');
```

Please make sure that you first set all options (setters like `setMatch()`, `setProtocol()` etc.), and after that call action method, because that methods return strings so it is imposibble to chaining.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~359 days

Total

3

Last Release

3026d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bdefcef56a943c80fc422b03a2231aed442384dcf3fc47bf6b644c995bb129fa?d=identicon)[3jy](/maintainers/3jy)

---

Top Contributors

[![plugowski](https://avatars.githubusercontent.com/u/494745?v=4)](https://github.com/plugowski "plugowski (2 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/3jy-iptables/health.svg)

```
[![Health](https://phpackages.com/badges/3jy-iptables/health.svg)](https://phpackages.com/packages/3jy-iptables)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
