Table of Contents

iptables

Changelog

  • 2024-11-16: Init

Introduction

Quick commands

Configuration

filter

nat

sudo sysctl -w net.ipv4.ip_forward=1
sudo iptables -A FORWARD -i wlan0 -j ACCEPT
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

mangle

Used to modify packet headers. Most common use case in marking packets for specialized routing, using the MARK target. Example1) below shows mail packets being redirected by ip-route to a different routing table mail:

# Set '1' mark on TCP packets headed to port 25
user:~$ iptables -t mangle ... -p tcp --dport 25 -j MARK --set-mark 1
 
# Create 'mail' table (with table ID 201) and add routing rule
user:~$ echo 201 mail >> /etc/iproute2/rt_tables
user:~$ ip route add default via 195.96.98.253 ... table mail
 
# Force packets with '1' mark to use the 'mail' routing table
user:~$ ip rule add fwmark 1 table mail

Other possible use cases

References