| 1 | Rust iptables |
| 2 | ============= |
| 3 | |
| 4 | [](https://crates.io/crates/iptables) [](https://docs.rs/iptables) [](https://github.com/yaa110/rust-iptables/actions/workflows/build.yml) [](https://github.com/yaa110/rust-iptables/blob/master/LICENSE) |
| 5 | |
| 6 | This crate provides bindings for [iptables](https://www.netfilter.org/projects/iptables/index.html) application in Linux (inspired by [go-iptables](https://github.com/coreos/go-iptables)). This crate uses iptables binary to manipulate chains and tables. This source code is licensed under MIT license that can be found in the LICENSE file. |
| 7 | |
| 8 | ```toml |
| 9 | [dependencies] |
| 10 | iptables = "*" |
| 11 | ``` |
| 12 | |
| 13 | ## Getting started |
| 14 | 1- Import the crate `iptables` and manipulate chains: |
| 15 | |
| 16 | ```rust |
| 17 | let ipt = iptables::new(false).unwrap(); |
| 18 | |
| 19 | assert!(ipt.new_chain("nat", "NEWCHAINNAME").is_ok()); |
| 20 | assert!(ipt.append("nat", "NEWCHAINNAME", "-j ACCEPT").is_ok()); |
| 21 | assert!(ipt.exists("nat", "NEWCHAINNAME", "-j ACCEPT").unwrap()); |
| 22 | assert!(ipt.delete("nat", "NEWCHAINNAME", "-j ACCEPT").is_ok()); |
| 23 | assert!(ipt.delete_chain("nat", "NEWCHAINNAME").is_ok()); |
| 24 | ``` |
| 25 | |
| 26 | For more information, please check the test file in `tests` folder. |