Coder Social home page Coder Social logo

iptablesfs's Introduction

A fuse filesystem for managing iptables

I usually configure my system by editing files in /etc, /proc or /sys. But I can't configure my firewall like that, since it exposes no configuration filesystem. So I've decided to write my own. However, I didn't stop at merely exposing a primitive interface. I have made it actually useful, and easier to use than plain iptables.

Installation

# pip install fuse-python
# cp iptablesfs.conf.py /etc

Usage

# mkdir ipt
# python2 iptables.py ipt

Note that you might have python2 installed as python, python2.7 or somehing else. But you know your system, right?

Now, since you have successfully mounted the filesystem, how to use it.

  • The main directories are tables. You can't do anything with them, except entering them.
  • In each table, there are chains. You can create them using mkdir, delete them using rmdir, etc.. You can't remove built-in chains, of course.
  • In each chain, there are usually multiple files. They are your filters. They are fully configurable, but you can't create or delete them using your shell commands.
  • If you overwrite a filter file, like tcp, only the rules in that file will be deleted, as expected.

An example:

# cd filter/INPUT
# ls
ACCEPT DROP policy REJECT rules tcp udp
# cat rules
# echo --dport 123 -j ACCEPT > udp
# cat rules
-p udp -m udp --dport 123 -j ACCEPT
# echo --dport 321 -j DROP > tcp
# echo --dport 42 -j ACCEPT >> tcp
# cat rules
-p udp -m udp --dport 123 -j ACCEPT
-p tcp -m tcp --dport 321 -j DROP
-p tcp -m tcp --dport 42 -j ACCEPT
# cat DROP
-p tcp -m tcp --dport 321
# cat tcp
--dport 321 -j DROP
--dport 42 -j ACCEPT
# echo --dport 23 -j ACCEPT > tcp
# cat rules
-p udp -m udp --dport 123 -j ACCEPT
-p tcp -m tcp --dport 23 -j ACCEPT

Configuration

The whole configuration is a dictionary of files. Each file is a filter for iptables -t table -S chain.

The keys are file names, and the values are dictionares containing following properties (all optional):

  • match: regular expression, lines that match it will be visible in this file. opposite of exclude
  • exclude: regular expression, lines that match it will not be further processed, and won't be visible in this file
  • hide: array of regular expressions, parts of line that match them will not be displayed in the file
  • exists: a lamda taking parameters fs, table, chain. decides whether the file exists in this chain. true by default
  • chain_option: command that will be used when adding lines. -A (append) by default.
  • prepend: a string to prepend to the line, when adding it to the file.
  • append: a string to append to the line, when adding it to the file.

The fs object in lambdas is the Filesystem class. The only interesting member of this class is chains. See the default configuration for an example on how it's intended to be used.

Any suggestions, comments, and especially useful filters are appreciated.

iptablesfs's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

denzuko-archive

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.