Skip to content
Related files and scripts for home built linux router
Python
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE.md
README.md
iptables.py
iptables_template

README.md

ip-control

Related files and scripts for home built linux router

Basic implementation takes configuration from Python dict and use Jinja for the iptables templating.
Edit iptables.py -> configuration for custom settings.

Configuration Schema:

configuration = {
    # Basic Network Configuration
    "network": {
        "wan": "enp3s0", # Internet In
        "lan": "enp4s0", # Internal Network (To a switch or AP)
    },
    # List of Port Forwards
    "port_forwards": [
        {
            "comment":  "Webserver",
            "src_port": "65536",     # Open Port on Router
            "dst_ip":   "10.10.0.1", # Internal Device IP
            "dst_port": "80",        # Internal Device Port
        },
    ],
    # List of Open Ports on Router
    "open_ports": [
        {
            "comment": "SSH", 
            "port":    "22",
        },
    ]
}

To run:

# Generate rules
python iptables.py > iptables
# Apply rules
iptables-restore < iptables

Todo

  • Support for passing in configuration from file as argument
  • Support for passing in template from file as argument
  • Support to apply rules with script
  • Support to backup rules with script
  • Validation on configuration
You can’t perform that action at this time.