-
-
05 Jul 2021 21:04:56 UTC
- Distribution: Rex
- Module version: v1.13.4
- Source (raw)
- Browse (raw)
- Changes
- Homepage
- How to Contribute
- Repository
- Issues
- Testers (711 / 4 / 2)
- Kwalitee
Bus factor: 2- 49.25% Coverage
- License: apache_2_0
- Perl: v5.10.1
- Activity
24 month- Tools
- Download (342.78KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 118 contributors-
Jan Gehring
-
A Happy User
-
Alexander Romanenko
-
Alexandr Ciornii
-
Alex Mestiashvili
-
Ali Polatel
-
alx542
-
Anders Ossowicki
-
Andrej Zverev
-
Andrew Solomon
-
Andy Beverley
-
Arnold Bechtoldt
-
Boris Däppen
-
Brian Manning
-
Cameron Daniel
-
Chris Steigmeier
-
Christophe Wolfhugel
-
Crimson Thompson
-
Daniel Bäurer
-
Daniel Cesario
-
Daniel Dico
-
Denis Silakov
-
Dmitry Kopytov
-
Dominik Schulz
-
E. Choroba
-
Eduardo J
-
Eivin Giske Skaaren
-
elisdg
-
Elmer Quintanilla
-
Eric Johnson
-
Erik Huelsmann
-
Ferenc Erki
-
Franky Van Liedekerke
-
Fran Rodriguez
-
Gabor Szabo
-
Graham Todd
-
Harm Müller
-
Hayato Imai
-
Hiroaki Nakamura
-
Hiroki Matsuo
-
iblinder
-
Ilya Pavlov
-
James D Bearden
-
jdelgado7
-
Jean Charles Passard
-
Jean-Marie Renouard
-
Jeen Lee
-
Jens Berthold
-
Joachim Bargsten
-
John Karr
-
Jon Gentle
-
Joris DE POOTER
-
Jose Luis Martinez
-
Jose Luis Perez Diez
-
Kasim Tuman
-
Keedi Kim
-
Ken Crowell
-
Kent Fredric
-
Kirill Babikhin
-
labbeduddel
-
Leah Neukirchen
-
LeMerP
-
Mario Domgoergen
-
Max E. Aubrey
-
Mitch Broadhead
-
Nathan Abu
-
Naveed Massjouni
-
necrophcodr
-
Nicolas Leclercq
-
Nigel Gregoire
-
Nikolay A. Fetisov
-
Nils Domrose
-
okaoka
-
Oleg Hardt
-
Olivier Cherrier
-
Orange
-
Paco Esteban
-
Patrick Lauer
-
Pavel Timofeev
-
perlancar
-
Peter H. Ezetta
-
Peter Manthey
-
petersonchen
-
Pierrick DINTRAT
-
Piotr Karbowski
-
Prajithp
-
Randy Lauen
-
Renée Bäcker
-
Robert Abraham
-
Roy Storey
-
Samuele Tognini
-
Sascha Askani
-
Sascha Guenther
-
Simon Bertrang
-
Solène Rapenne
-
Stephane Benoit
-
Steve Dondley
-
Sven Dowideit
-
Tamas Molnar
-
Tianon Gravi
-
Tokuhiro Matsuno
-
Tomohiro Hosaka
-
Volker Kroll
-
Walery Wysotsky
-
Yanick Champoux
-
Yegor Korablev
-
Zane C. Bowers-Hadley
-
Сергей Романов
-
范野人
-
饶琛琳
-
Cuong Manh Le
-
David Golovan
-
Dominik Danter
-
Ilya Evseev
-
Niklas Larsson
-
Qiao Liu
-
Renato CRON
-
Peter Jankovics
- Dependencies
- AWS::Signature4
- Carp
- Cwd
- Data::Dumper
- Data::Validate::IP
- Devel::Caller
- Digest::HMAC_SHA1
- Digest::MD5
- English
- Exporter
- Fcntl
- File::Basename
- File::Spec
- File::Spec::Unix
- File::Spec::Win32
- FindBin
- HTTP::Request
- HTTP::Request::Common
- Hash::Merge
- IO::File
- IO::Select
- IO::Socket
- IO::String
- IPC::Open3
- JSON::MaybeXS
- LWP::UserAgent
- List::Util
- MIME::Base64
- Net::OpenSSH::ShellQuoter
- POSIX
- Scalar::Util
- Sort::Naturally
- Storable
- Symbol
- Term::ReadKey
- Test::Builder::Module
- Text::Glob
- Text::Wrap
- Time::HiRes
- UNIVERSAL
- URI
- URI::QueryParam
- XML::Simple
- YAML
- attributes
- base
- constant
- lib
- overload
- strict
- vars
- version
- warnings
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
NAME
Rex::Commands::Iptables - Iptable Management Commands
DESCRIPTION
With this Module you can manage basic Iptables rules.
Version <= 1.0: All these functions will not be reported.
Only open_port and close_port are idempotent.
SYNOPSIS
use Rex::Commands::Iptables; task "firewall", sub { iptables_clear; open_port 22; open_port [22, 80] => { dev => "eth0", }; close_port 22 => { dev => "eth0", }; close_port "all"; redirect_port 80 => 10080; redirect_port 80 => { dev => "eth0", to => 10080, }; default_state_rule; default_state_rule dev => "eth0"; is_nat_gateway; iptables t => "nat", A => "POSTROUTING", o => "eth0", j => "MASQUERADE"; # The 'iptables' function also accepts long options, # however, options with dashes need to be quoted iptables table => "nat", accept => "POSTROUTING", "out-interface" => "eth0", jump => "MASQUERADE"; # Version of IP can be specified in the first argument # of any function: -4 or -6 (defaults to -4) iptables_clear -6; open_port -6, [22, 80]; close_port -6, "all"; redirect_port -6, 80 => 10080; default_state_rule -6; iptables -6, "flush"; iptables -6, t => "filter", A => "INPUT", i => "eth0", m => "state", state => "RELATED,ESTABLISHED", j => "ACCEPT"; };
EXPORTED FUNCTIONS
open_port($port, $option)
Open a port for inbound connections.
task "firewall", sub { open_port 22; open_port [22, 80]; open_port [22, 80], dev => "eth1"; }; task "firewall", sub { open_port 22, dev => "eth1", only_if => "test -f /etc/firewall.managed"; } ;
close_port($port, $option)
Close a port for inbound connections.
task "firewall", sub { close_port 22; close_port [22, 80]; close_port [22, 80], dev => "eth0", only_if => "test -f /etc/firewall.managed"; };
redirect_port($in_port, $option)
Redirect $in_port to another local port.
task "redirects", sub { redirect_port 80 => 10080; redirect_port 80 => { to => 10080, dev => "eth0", }; };
iptables(@params)
Write standard iptable comands.
Note that there is a short form for the iptables
--flush
option; when you pass the option of-F|"flush"
as the only argument, the commandiptables -F
is run on the connected host. With the two argument form offlush
shown in the examples below, the second argument is table you want to flush.task "firewall", sub { iptables t => "nat", A => "POSTROUTING", o => "eth0", j => "MASQUERADE"; iptables t => "filter", i => "eth0", m => "state", state => "RELATED,ESTABLISHED", j => "ACCEPT"; # automatically flushes all tables; equivalent to 'iptables -F' iptables "flush"; iptables -F; # flush only the "filter" table iptables flush => "filter"; iptables -F => "filter"; }; # Note: options with dashes "-" need to be quoted to escape them from Perl task "long_form_firewall", sub { iptables table => "nat", append => "POSTROUTING", "out-interface" => "eth0", jump => "MASQUERADE"; iptables table => "filter", "in-interface" => "eth0", match => "state", state => "RELATED,ESTABLISHED", jump => "ACCEPT"; };
is_nat_gateway
This function creates a NAT gateway for the device the default route points to.
task "make-gateway", sub { is_nat_gateway; is_nat_gateway -6; };
default_state_rule(%option)
Set the default state rules for the given device.
task "firewall", sub { default_state_rule(dev => "eth0"); };
iptables_list
List all iptables rules.
task "list-iptables", sub { print Dumper iptables_list; print Dumper iptables_list -6; };
iptables_clear
Remove all iptables rules.
task "no-firewall", sub { iptables_clear; };
Module Install Instructions
To install Rex, copy and paste the appropriate command in to your terminal.
cpanm Rex
perl -MCPAN -e shell install Rex
For more information on module installation, please visit the detailed CPAN module installation guide.