iptables
Program that allows configuration of tables, chains and rules provided by the Linux kernel firewall. More information: <https://www.netfilter.org/projects/iptables/>.
Install
- All systems
-
curl cmd.cat/iptables.sh
- Debian
-
apt-get install iptables
- Ubuntu
-
apt-get install iptables
-
Alpine
-
apk add iptables
- Arch Linux
-
pacman -S iptables
- Kali Linux
-
apt-get install iptables
- CentOS
-
yum install iptables
- Fedora
-
dnf install iptables
- Windows (WSL2)
-
sudo apt-get update
sudo apt-get install iptables
- Raspbian
-
apt-get install iptables
- Dockerfile
- dockerfile.run/iptables
- Docker
-
docker run cmd.cat/iptables iptables
powered by Commando
Program that allows configuration of tables, chains and rules provided by the Linux kernel firewall. More information: <https://www.netfilter.org/projects/iptables/>.
-
View chains, rules, and packet/byte counters for the filter table:
sudo iptables -vnL
-
Set chain policy rule:
sudo iptables -P chain rule
-
Append rule to chain policy for IP:
sudo iptables -A chain -s ip -j rule
-
Append rule to chain policy for IP considering protocol and port:
sudo iptables -A chain -s ip -p protocol --dport port -j rule
-
Add a NAT rule to translate all traffic from the `192.168.0.0/24` subnet to the host's public IP:
sudo iptables -t nat -A POSTROUTING -s 192.168.0.0/24 -j MASQUERADE
-
Delete chain rule:
sudo iptables -D chain rule_line_number
-
Save iptables configuration of a given table to a file:
sudo iptables-save -t tablename > path/to/iptables_file
-
Restore iptables configuration from a file:
sudo iptables-restore < path/to/iptables_file
© tl;dr; authors and contributors