以声明的方式使用iptables

declarative-iptables的Python项目详细描述


简单表格

在linux上管理iptables的简单接口

管理iptables最困难的部分是,它们是从许多不同方向不断变化的数据的中心部分。因为它的状态无法保证,所以对它进行简单的修改可能会产生不希望的后果。该项目旨在通过制作另一个iptables接口来解决这个问题。

此接口旨在声明性。这个包定义了所需的状态,而不是直接发布对iptables的更改。重要的是,在任何给定的时间,表的外观都不重要,相反,目标是最终得到它应该是什么样子

另外,由于不知道其他系统做了什么更改,所以未声明的任何表和规则都将保持不变

示例

import iptables

plan = iptables.Plan()

# this will delete an existing table and create it from scratch
berto_chain = plan.add_chain('OPENVPN_BERTO')

# rules are added with a default priority of 50
berto_chain.add_rule(iptables.Rule('-o tun0 -s 192.168.2.2 -d 192.168.1.1 -j ACCEPT'))

# this will get an existing table and create it if it does not exist
openvpn_chain = plan.get_chain('OPENVPN')

# rules with higher number priority get added to the chain first
# when updating an existing chain, rules already in the chain get a priority of 70.
# being added is compared to existing rules and will be added if missing or left alone.
openvpn_chain.add_rule(iptables.Rule('-o ! tun0 -j RETURN', priority=100))
openvpn_chain.add_rule(berto_chain.jump)

# make necessary changes to achieve the desired outcome
plan_execute()

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
Java Square类   java Android RecyclerView内部视图寻呼机   java类变量:公共访问只读,但私有访问r/w   java不兼容ClassChangeError java8   安卓java on on参数,如参数iNIT.C++C++   java如何在下面的代码中根据我的喜好设置JTextArea和JTextField的大小?   java使用CustomAdapter更改ListView的显示方式   jakarta ee什么是Java Servlet?   传递给Javasocket程序的参数   java为什么我的计划任务在这两者之间有很长的延迟   Java“迭代器”关键字   java获取数据库SQLite Android中插入行的行ID   网络如何在Java应用程序中设置H2嵌入式数据库,以便在小型网络中使用?   数组Java:写出所有包含K1的Nbit序列   java返回随机字符串键的整数值   在java中解析到日期的字符串时保留时区   java如何修复“运行配置错误:[在SDK中找不到Rails]”?   Java包装器OutofMemory