هیچ محصولی در سبد خرید نیست.

OPENWRT IPTABLES

iptables  چیست و چگونه کار می کند؟

به بیان ساده ، iptables یک برنامه فایروال برای لینوکس و OPenwrt است. با استفاده از جدول های درون آن ، میزان ترافیک ورودی و خروجی سرور شما کنترل می شود. این جدول ها شامل مجموعه ای از قوانین (rule) است که به آن ها Chain گفته می شود ، که packet های داده ورودی و خروجی را فیلتر می کند.

هنگامی که یک packet با یک rule مطابقت دارد یکی از عملیات های از پیش تعیین شده بر روی آن پیاده سازی می شود:

مشخصات برنامه IPTABLE openwrt

Name:iptablesVersion:۱.۸.۷-۱Description:IP firewall administration tool.\\ \\ Matches: \\ – icmp\\ – tcp\\ – udp\\ – comment\\ – conntrack\\ – limit\\ – mac\\ – mark\\ – multiport\\ – set\\ – state\\ – time\\ \\ Targets: \\ – ACCEPT\\ – CT\\ – DNAT\\ – DROP\\ – REJECT\\ – FLOWOFFLOAD\\ – LOG\\ – MARK\\ – MASQUERADE\\ – REDIRECT\\ – SET\\ – SNAT\\ – TCPMSS\\ \\ Tables: \\ – filter\\ – mangle\\ – nat\\ – raw\\ \\ \\Installed size:۲۳kBDependencies:libclibrtlibpthreadkmod-ipt-corelibip4tc2libip6tc2libxtables12Categories:openwrtRepositories:baseOpenWrt release:OpenWrt-21.02.0File size:۲۴kBLicense:GPL-2.0Maintainer:OpenWrt teamBug report:Bug reportsSource code:Sources

لیست Action ها در فایروال :

Accept : اجازه عبور packet داده می شود.

Drop : اجازه عبور packet داده نمی شود.

Return : اجازه عبور packet داده نمی شود  و packet به Chain قبلی برگردانده می شود.باعث ادامه پردازش یک بسته در زنجیرهٔ فراخواننده می‌شود.

در این آموزش iptables قصد داریم با یکی از جداول پیش فرض به نام filter کار کنیم.

جدول filter از سه chain تشکیل شده است:

  INPUT: بسته های ورودی به سرور را کنترل می کند.

 FORWARD : بسته های ورودی را که به جایی دیگر ارسال می شوند فیلتر می کند.

 OUTPUT : بسته هایی را که از سرور شما خارج می شوند فیلتر می کند.

پیش از شروع آموزش ابتدا مطمئن شوید که دسترسی SSH root و یا دسترسی sudo به سرور مجازی اوبونتو دارید.

Rule های iptables تنها برای IPv4 اعمال می شود. اگر می خواهید برای پروتکل IPv6 تنظیم کنید می بایست از ip6tables استفاده کنید.

زنجیره (Chain):

یک زنجیره یک مجموعهٔ قانون است که بر روی بسته‌هایی که زنجیره را می‌پیمایند، اعمال می‌شود. هر زنجیره یک هدف خاص دارد. هر جدول یک مجموعهٔ زنجیره توکار دارد اما کاربر نیز می‌تواند زنجیره‌هایی را تعریف کند.

شکل۱. ساختار IPTables

مهم‌ترین زنجیره‌های توکار عبارتند از INPUT, OUTPUT و FORWARD

 INPUT: این زنجیره توسط بسته‌هایی پیمایش می‌شود که به شبکهٔ محلی وارد می‌شوند. البته بعد از این‌که در هسته عمل مسیریابی آن‌ها انجام شود.
 OUTPUT: برای بسته‌هایی است که در سیستم لینوکس تولید می‌شوند.
 FORWARD: وقتی دیواره آتش برای متصل‌کردن یک شبکه به شبکهٔ دیگر استفاده می‌شود، بسته‌ها باید در دیواره آتش مسیریابی شوند که در این مورد این زنجیره به‌کار می‌رود.
دو زنجیرهٔ دیگر عبارتند از PREROUTING و POSTROUTING که اصلاح سرآیند بسته‌ها را قبل و بعد از عمل مسیریابی توسط هسته، انجام می‌دهند.

عبارات و اصطلاحات IP Tables

در ادامه این بخش، تعدادی از عبارات و اصطلاحاتی که بیشترین کاربرد را دارند و برای درک مطالب بعدی لازم هستند، شرح داده می‌شوند.

انطباق:

این کلمه با دو معنی مختلف به‌کار می‌رود. معنی اول: یک انطباق منفرد که به یک قانون می‌گوید که یک سرآیند باید محتوی چه اطلاعاتی باشد. مثلاً انطباق—source به ما می‌گوید که آدرس منبع باید یک میزبان خاص یا محدوده خاصی از شبکه باشد. هر قانون از یک یا چندین انطباق تشکیل شده‌است. معنی دوم: اگر کل یک قانون در مورد یک بسته صدق کند می‌گوییم بسته با قانون انطباق یافته‌است. چند نمونه از پرکاربردترین انطباق‌ها در ادامه آورده شده‌اند:

 (--source (-s: یک آدرس IP مبدأ یا شبکه را انطباق می‌دهد.
 (--destination (-d: یک آدرس IP مقصد یا شبکه را انطباق می‌دهد.
 (--protocol (-p: روی یک IP انطباق انجام می‌دهد.
 (--in-interface (-i: یک رابط ورودی ایجاد می‌کند.
 interface: یک رابط خروجی ایجاد می‌کند.
 --state: روی مجموعه‌ای از حالات اتصال انطباق می‌دهد.
 --string: روی رشته‌ای از بایت‌های داده لایهٔ کاربردی، انطباق انجام می‌دهد.

مرحله اول – نصب iptables

Iptables به صورت پیشفرض در بیشتر توزیع های لینوکس نصب می باشد.اما اگر در سرور شما به صورت پیشفرض نصب نمی باشد مراحل زیر را در ادامه انجام دهید:

ابتدا از طریق SSH به سرور خود متصل شوید برای این کار می توانید از نرم افزار putty استفاده نمایید.

سپس دستورات زیر را به ترتیب اجرا نمایید.

opkg apt-get update
opkg  install iptables

سپس وضعیت پیکربندی فعلی iptables را با استفاده از دستور زیر بررسی نمایید:

 iptables -L -v

در این دستور –L برای لیست کردن همه rule ها و –V برای نمایش اطلاعات به صورت دقیق تر می باشد.

Categories:openwrt

اضافه کردن به فایل /etc/sysctl.conf  و دائم شدن با دستور
Sysctl -p
sysctl -w net.ipv4.ip_forward=۱
ارگیری مجدد تنظیمات از فایل های پیکربندی sysctl –system
مشاهده دستورات Nat اجرا شده در iptables iptables -t nat -L -n -v | grep ‘something
اضافه کردن د/etc/sysctl.conf sysctl -p
iptables -t nat -L -n -v
ip rule show
مشاهده دستورات mangle اجرا شده iptables -t mangle -L -n -v
ذخیره دستورات فایر وال در فایل /etc/config/firewall
uci commit firewall
اجرای فرامین start stop disable enabe resrtart /etc/init.d/firewall restart
ذخیره کردن فایل iptables-save >/etc/iptables/iptables1
بازیابی iptables-restore /etc/iptables/iptables1


fw3 در openwrt چیست ؟

OpenWrt از fw4برنامه سازنده قوانین netfilter/nftables firewall4 ( ) استفاده می کند. در فضای کاربر اجرا می‌شود تا یک فایل پیکربندی را در مجموعه‌ای از nftablesقوانین تجزیه کند و هر کدام را به ماژول‌های netfilter هسته ارسال کند.

/etc/init.d/firewall

هدف

مجموعه قوانین netfilter می تواند برای یک روتر معمولی بسیار پیچیده باشد. این بنا به ضرورت است؛ هر قانون برای یک قابلیت گسسته ارائه شده توسط روتر برای محافظت از شبکه های پشتیبانی شده خود، ارائه NAT برای حفظ آدرس های IPv4 کمیاب ، حتی mangleبسته ها در طول مسیریابی، تنظیم شده است. یک روتر معمولی بیش از ۱۰۰ قانون طراحی شده برای پشتیبانی از مسیریابی بسته دارد.

این fw4برنامه توسط OpenWRT برای ایجاد “ایمن” یک مجموعه قوانین در حالی که بسیاری از جزئیات را پنهان می کند استفاده می شود.

هنگام بررسی مجموعه قوانین netfilter با استفاده از fw4 print، تعدادی از قوانین netfilter/nftables را مشاهده خواهید کرد که یا به صراحت در فایل های پیکربندی فایروال تعریف نشده اند، یا درک آن دشوارتر است (خدا را شکر برای –commentمطابقت!) قوانین netfilter عبارتند از:

  • تعدادی زنجیره (به اشتباه _rule) برای هر هدف و منطقه خاص.
  • INPUT و OUTPUT برای رابط Loopback اغلب فراموش شده.
  • option syn_flood 1یا هر option mtu_fix 1کدام به قوانین پیچیده nftable ترجمه می شوند.
  • به هدف option masq 1“-j MASQUERADE” برای NAT ترجمه می شود.
  • mangleقوانینی که بیت ها را در سرآیند TCP بسته ها مطابقت می دهند و سپس بسته را تغییر می دهند.

پیکربندی فایروال نسبتاً مستقیم است و به طور خودکار یک مجموعه قوانین پایه از قوانین و یک فایل پیکربندی قابل درک برای قوانین اضافی را در اختیار روتر قرار می دهد.

به دلیل ماهیت دقیق نت فیلتر، درک قوانین مصرف شده توسط نت فیلتر در بهترین حالت دشوار است. با این حال، هر قانون قابلیت مورد نظر را فراهم می کند یا قابلیت مخرب را مسدود می کند و بنابراین ضروری است.

fw4معمولاً با فراخوانی اسکریپت پوسته مدیریت می شود /etc/init.d/firewall. اسکریپت پوسته مجموعه آرگومان های زیر را می پذیرد:

مدیرت سرویس فایروال

 /etc/init.d/firewall

  • boot: این در هنگام راه اندازی سیستم فراخوانی می شود (بوتاپ)
  • start: فایل های پیکربندی را تجزیه کنید و در ماژول های هسته نت فیلتر بنویسید
  • stop: قوانین پیکربندی را از ماژول های هسته تخلیه کنید (آنها تخلیه نمی شوند)
  • restartreload: قوانین netfilter را از هسته بخوانید، با استفاده از فایل های پیکربندی جایگزین کنید و دوباره به ماژول های هسته netfilter بنویسید.
  • flush: (خطرناک) همه قوانین را حذف کنید، زنجیره های غیر پیش فرض را حذف کنید و سیاست های پیش فرض را به ACCEPT.

فایل کانفیگ فایروال

فایل کانفیگ فایروال لینوکس اپن دبلیو آر تی در پوشه زیر قرار دادر

Firewall configuration /etc/config/firewall

دستور config include در دفایروال

در فایروال میتوان با دستور زیر از فایل جانبی در فایروال هر برنامه نیز استفاده کرد .

config include ‘v2ray’
option type ‘script’
option path ‘/etc/firewall.v2ray’
option family ‘any’
option reload ‘1’

هدف


iptables یک برنامه فایروال قدرتمند است که می توانید از آن برای امنیت سرور لینوکس و یا سرور مجازی  VPS استفاده کنید. شما می توانید بر اساس نیاز خود rule های مختلفی را تعریف کنید.

اگر به دنبال یک آموزش جامع درباره iptables هستید ، پیشنهاد می کنیم در ادامه همراه ما باشید. در این مقاله نحوه نصب و استفاده از iptables در سیستم اوبونتو را به شما آموزش خواهیم داد.

با یادگیری این ابزار فایروال لینوکس ، می توانید سرور مجازی لینوکس (Linux VPS) خود را از طریق کامند لاین سرور ایمن کنید.

در این آموزش نحوه نصب iptables و استفاده از ابزارهای آن را یاد خواهید گرفت.پس از این آموزش ، شما می توانید مجموعه ای rule های مورد نیاز خود را برای مدیریت و فیلتر کردن packet های ورودی و خروجی تعریف کنید.

همچنین این آموزش برای اوبونتو سرور ۱۶.۰۴ و نسخه های بالاتر می باشد، ما در این مقاله بر روی سرورمجازی اوبونتو ۱۸.۰۴ آموزش داده ایم.

iptables  چیست و چگونه کار می کند؟

به بیان ساده ، iptables یک برنامه فایروال برای لینوکس است. با استفاده از جدول های درون آن ، میزان ترافیک ورودی و خروجی سرور شما کنترل می شود. این جدول ها شامل مجموعه ای از قوانین (rule) است که به آن ها Chain گفته می شود ، که packet های داده ورودی و خروجی را فیلتر می کند.

هنگامی که یک packet با یک rule مطابقت دارد یکی از عملیات های از پیش تعیین شده بر روی آن پیاده سازی می شود:

Accept : اجازه عبور packet داده می شود.

Drop : اجازه عبور packet داده نمی شود.

Return : اجازه عبور packet داده نمی شود  و packet به Chain قبلی برگردانده می شود.

در این آموزش iptables قصد داریم با یکی از جداول پیش فرض به نام filter کار کنیم.

جدول filter از سه chain تشکیل شده است:

  INPUT: بسته های ورودی به سرور را کنترل می کند.

 FORWARD : بسته های ورودی را که به جایی دیگر ارسال می شوند فیلتر می کند.

 OUTPUT : بسته هایی را که از سرور شما خارج می شوند فیلتر می کند.

پیش از شروع آموزش ابتدا مطمئن شوید که دسترسی SSH root و یا دسترسی sudo به سرور مجازی اوبونتو دارید.

Rule های iptables تنها برای IPv4 اعمال می شود. اگر می خواهید برای پروتکل IPv6 تنظیم کنید می بایست از ip6tables استفاده کنید.

آموزش نصب و استفاده از iptables linux firewall

این آموزش به سه مرحله تقسیم می شود.

ابتدا نحوه نصب در سرور مجازی اوبونتو را آموزش خواهیم داد.

سپس در مرحله نحوه تعریف rule ها را آموزش خواهیم داد.

و در آخر به شما آموزش خواهیم داد که چگونه تغییرات و بروز رسانی های مورد نظر خود را اعمال کنید.

مرحله اول – نصب iptables

Iptables به صورت پیشفرض در بیشتر توزیع های لینوکس نصب می باشد.اما اگر در سرور شما به صورت پیشفرض نصب نمی باشد مراحل زیر را در ادامه انجام دهید:

ابتدا از طریق SSH به سرور خود متصل شوید برای این کار می توانید از نرم افزار putty استفاده نمایید.

سپس دستورات زیر را به ترتیب اجرا نمایید.

sudo apt-get update
sudo apt-get install iptables

سپس وضعیت پیکربندی فعلی iptables را با استفاده از دستور زیر بررسی نمایید:

sudo iptables -L -v

در این دستور –L برای لیست کردن همه rule ها و –V برای نمایش اطلاعات به صورت دقیق تر می باشد.

خروجی این دستور مشابه تصویر زیر می باشد .

اکنون فایروال لینوکس بر روی سرور شما نصب شده است. توجه داشته باشید که در این مرحله تمام rule ها روی ACCEPT تنظیم شده اند و هیچ policy اعمال نمی شود و در این شرایط سرور شما امن نیست زیرا هر packet می تواند بدون فیلتر وارد سرور شود.

پس در ادامه همراه ما باشید تا نحوه اعمال rule های فایروال را به شما آموزش دهیم.

مرحله دوم – تعریف Chain rule ها

برای تعریف rule جدید دستور زیر را وارد نمایید. قرار دادن A- بلافاصله بعد از iptables به معنای اضافه شدن این rule به chain می باشد.

i- (interfaces):اینترفیسی می باشد که می خواهید rule نوشته شده بر روی آن اعمال شود. مانند eth0 ، ppp0 و ….

البته می توانید همه پروتکل ها را برای رول خود انتخاب نمایید.

p- (interfaces): پروتکل شبکه می باشد که شما می خواهید عملیات فیلتر بر روی آن پروتکل اعمال شود. مانند پروتکل های  tcp ، udp ، icmp ، sctp و …..

s- (interfaces) : ادرس مبدا packet می باشد . میتوانید آدرس IP و یا hostname مبدا را وارد نمایید.

dport- (interfaces) : شماره پورت مقصد پروتکل می باشد .مانند ۲۲ برای پروتکل SSH و یا ۴۴۳  برای پروتکل https . علاوه پورت های well known تمامی پورتهای دیگر نیز قابل استفاده می باشند.

j- (interfaces) : نام هدف می باشد (ACCEPT,DROP,RETURN) ، در هر rule که ایجاد می کنید می بایست این فاکتور را نیز برای آن مشخص نمایید.

حال می توانید با توجه به نوع rule مورد نظر خود فاکتورهای موردنیاز را وارد نمایید ، درصورت استفاده همه فاکتورها با هم rule شما به صورت زیر خواهد بود:

sudo iptables -A <chain> -i <interface> -p <protocol (tcp/udp) > -s <source> --dport <port no.>  -j <target>

پس از آشنایی با قواعد اصلی موردنیاز برای نوشتن rule ، می توانید پیکربندی فایروال را آغاز کنید، تا امنیت بیشتری به سرور خود بدهید.

برای این آموزش iptables ، ما قصد داریم به عنوان نمونه یک input chain ایجاد کنیم.

فعال کردن ترافیک در localhost

برای اجازه دادن به ترافیک local دستور زیر را وارد نمایید:

sudo iptables -A INPUT -i lo -j ACCEPT

برای این آموزش ، از اینترفیس مجازی lo (loopback) استفاده می کنیم.این اینترفیس برای تمام ارتباطات local مورد استفاده قرار می گیرد.

اینترفیس loopback درواقع یک اینترفیس مجازی است که برای بررسی ارتباطات local شبکه مورد استفاده قرار می گیرد.

حال با دستور زیر بررسی می کنیم که rule نوشته شده به iptables اضافه شده است:

دستور مشاهده rule های iptables

 iptables -L –v

درصورت تمایل میتوانید در rule نوشته شده اینترفیس فیزیکی سرور خود را اعمال نمایید.

فعال کردن ارتباطات بر روی پورت های SSH , HTTP , SSL

در مرحله بعد ، می خواهیم ارتباط های http (پورت ۸۰) ، https  (پورت ۴۴۳ ( و ssh (پورت ۲۲) را فعال کنیم تا این سرویس ها بتوانند  بر روی سرور کار خود را انجام دهند.. برای این کار ، باید پروتکل (-p) و پورت مربوطه  (-dport) را مشخص کنیم. می توانید این دستورات را یک به یک اجرا کنید:

دستور اول مربوط به SSH می باشد .(پورت ۲۲)

دستور دوم مربوط به HTTP می باشد .(پورت ۸۰)

دستور سوم مربوط به HTTPS می باشد .(پورت ۴۴۳)

 iptables -A INPUT -p tcp --dport 22 -j ACCEPT
 iptables -A INPUT -p tcp --dport 80 -j ACCEPT
 iptables -A INPUT -p tcp --dport 443 -j ACCEPT

حال با دستور زیر که با آن آشنا شده اید ، بررسی می کنیم که rule ها اعمال شده باشند.

دائمی کردن تغییرات در IPTABLES

sudo /sbin/iptables-save

غیرفعال کردن سرویس iptables

sudo iptables -F
sudo /sbin/iptables-save

منبع دستور https://linux.die.net/man/8/iptables

iptables

iptables(8) – Linux man page

Name

iptables – administration tool for IPv4 packet filtering and NAT

iptables [-t table] -[AD] chain rule-specification [options]
iptables [-t table] -I
 chain [rulenum] rule-specification [options]
iptables [-t table] -R
 chain rulenum rule-specification [options]
iptables [-t table] -D
 chain rulenum [options]
iptables [-t table] -[LFZ]
 [chain] [options]
iptables [-t table] -N
 chain
iptables [-t table] -X
 [chain]
iptables [-t table] -P
 chain target [options]
iptables [-t table] -E
 old-chain-name new-chain-name

Description

Iptables is used to set up, maintain, and inspect the tables of IP packet filter rules in the Linux kernel. Several different tables may be defined. Each table contains a number of built-in chains and may also contain user-defined chains.

Each chain is a list of rules which can match a set of packets. Each rule specifies what to do with a packet that matches. This is called a ‘target’, which may be a jump to a user-defined chain in the same table.

Targets

A firewall rule specifies criteria for a packet, and a target. If the packet does not match, the next rule in the chain is the examined; if it does match, then the next rule is specified by the value of the target, which can be the name of a user-defined chain or one of the special values ACCEPTDROPQUEUE, or RETURN.

ACCEPT means to let the packet through. DROP means to drop the packet on the floor. QUEUE means to pass the packet to userspace. (How the packet can be received by a userspace process differs by the particular queue handler. 2.4.x and 2.6.x kernels up to 2.6.13 include the ip_queue queue handler. Kernels 2.6.14 and later additionally include the nfnetlink_queue queue handler. Packets with a target of QUEUE will be sent to queue number ‘0’ in this case. Please also see the NFQUEUE target as described later in this man page.) RETURN means stop traversing this chain and resume at the next rule in the previous (calling) chain. If the end of a built-in chain is reached or a rule in a built-in chain with target RETURN is matched, the target specified by the chain policy determines the fate of the packet.

Tables

There are currently three independent tables (which tables are present at any time depends on the kernel configuration options and which modules are present).-t, –tabletableThis option specifies the packet matching table which the command should operate on. If the kernel is configured with automatic module loading, an attempt will be made to load the appropriate module for that table if it is not already there.

The tables are as follows:filter:This is the default table (if no -t option is passed). It contains the built-in chains INPUT (for packets destined to local sockets), FORWARD (for packets being routed through the box), and OUTPUT (for locally-generated packets).nat:This table is consulted when a packet that creates a new connection is encountered. It consists of three built-ins: PREROUTING (for altering packets as soon as they come in), OUTPUT (for altering locally-generated packets before routing), and POSTROUTING (for altering packets as they are about to go out).mangle:This table is used for specialized packet alteration. Until kernel 2.4.17 it had two built-in chains: PREROUTING (for altering incoming packets before routing) and OUTPUT (for altering locally-generated packets before routing). Since kernel 2.4.18, three other built-in chains are also supported: INPUT (for packets coming into the box itself), FORWARD (for altering packets being routed through the box), and POSTROUTING (for altering packets as they are about to go out).raw:This table is used mainly for configuring exemptions from connection tracking in combination with the NOTRACK target. It registers at the netfilter hooks with higher priority and is thus called before ip_conntrack, or any other IP tables. It provides the following built-in chains: PREROUTING (for packets arriving via any network interface) OUTPUT (for packets generated by local processes)

Options

The options that are recognized by iptables can be divided into several different groups.

COMMANDSThese options specify the specific action to perform. Only one of them can be specified on the command line unless otherwise specified below. For all the long versions of the command and option names, you need to use only enough letters to ensure that iptables can differentiate it from all other options.-A, –appendchain rule-specificationAppend one or more rules to the end of the selected chain. When the source and/or destination names resolve to more than one address, a rule will be added for each possible address combination.-D, –deletechain rule-specification-D, –deletechain rulenumDelete one or more rules from the selected chain. There are two versions of this command: the rule can be specified as a number in the chain (starting at 1 for the first rule) or a rule to match.-I, –insertchain [rulenumrule-specificationInsert one or more rules in the selected chain as the given rule number. So, if the rule number is 1, the rule or rules are inserted at the head of the chain. This is also the default if no rule number is specified.-R, –replacechain rulenum rule-specificationReplace a rule in the selected chain. If the source and/or destination names resolve to multiple addresses, the command will fail. Rules are numbered starting at 1.-L, –list [chain]List all rules in the selected chain. If no chain is selected, all chains are listed. As every other iptables command, it applies to the specified table (filter is the default), so NAT rules get listed by

iptables -t nat -n -L

Please note that it is often used with the -n option, in order to avoid long reverse DNS lookups. It is legal to specify the -Z (zero) option as well, in which case the chain(s) will be atomically listed and zeroed. The exact output is affected by the other arguments given. The exact rules are suppressed until you use

iptables -L -v

-F, –flush [chain]Flush the selected chain (all the chains in the table if none is given). This is equivalent to deleting all the rules one by one.-Z, –zero [chain]Zero the packet and byte counters in all chains. It is legal to specify the -L, –list (list) option as well, to see the counters immediately before they are cleared. (See above.)-N, –new-chainchainCreate a new user-defined chain by the given name. There must be no target of that name already.-X, –delete-chain [chain]Delete the optional user-defined chain specified. There must be no references to the chain. If there are, you must delete or replace the referring rules before the chain can be deleted. The chain must be empty, i.e. not contain any rules. If no argument is given, it will attempt to delete every non-builtin chain in the table.-P, –policychain targetSet the policy for the chain to the given target. See the section TARGETS for the legal targets. Only built-in (non-user-defined) chains can have policies, and neither built-in nor user-defined chains can be policy targets.-E, –rename-chainold-chain new-chainRename the user specified chain to the user supplied name. This is cosmetic, and has no effect on the structure of the table.-h

Help. Give a (currently very brief) description of the command syntax.

PARAMETERSThe following parameters make up a rule specification (as used in the add, delete, insert, replace and append commands).-p, –protocol [!] protocolThe protocol of the rule or of the packet to check. The specified protocol can be one of tcpudpicmp, or all, or it can be a numeric value, representing one of these protocols or a different one. A protocol name from /etc/protocols is also allowed. A “!” argument before the protocol inverts the test. The number zero is equivalent to all. Protocol all will match with all protocols and is taken as default when this option is omitted.-s, –source [!] address[/mask]Source specification. Address can be either a network name, a hostname (please note that specifying any name to be resolved with a remote query such as DNS is a really bad idea), a network IP address (with /mask), or a plain IP address. The mask can be either a network mask or a plain number, specifying the number of 1’s at the left side of the network mask. Thus, a mask of ۲۴ is equivalent to ۲۵۵.۲۵۵.۲۵۵.۰. A “!” argument before the address specification inverts the sense of the address. The flag –src is an alias for this option.-d, –destination [!] address[/mask]Destination specification. See the description of the -s (source) flag for a detailed description of the syntax. The flag –dst is an alias for this option.-j, –jumptargetThis specifies the target of the rule; i.e., what to do if the packet matches it. The target can be a user-defined chain (other than the one this rule is in), one of the special builtin targets which decide the fate of the packet immediately, or an extension (see EXTENSIONS below). If this option is omitted in a rule (and -g is not used), then matching the rule will have no effect on the packet’s fate, but the counters on the rule will be incremented.-g, –gotochainThis specifies that the processing should continue in a user specified chain. Unlike the –jump option return will not continue processing in this chain but instead in the chain that called us via –jump.-i, –in-interface [!] nameName of an interface via which a packet was received (only for packets entering the INPUTFORWARD and PREROUTING chains). When the “!” argument is used before the interface name, the sense is inverted. If the interface name ends in a “+”, then any interface which begins with this name will match. If this option is omitted, any interface name will match.-o, –out-interface [!] nameName of an interface via which a packet is going to be sent (for packets entering the FORWARDOUTPUT and POSTROUTING chains). When the “!” argument is used before the interface name, the sense is inverted. If the interface name ends in a “+”, then any interface which begins with this name will match. If this option is omitted, any interface name will match.[!] -f, –fragmentThis means that the rule only refers to second and further fragments of fragmented packets. Since there is no way to tell the source or destination ports of such a packet (or ICMP type), such a packet will not match any rules which specify them. When the “!” argument precedes the “-f” flag, the rule will only match head fragments, or unfragmented packets.-c, –set-countersPKTS BYTESThis enables the administrator to initialize the packet and byte counters of a rule (during INSERT, APPEND, REPLACE operations).

OTHER OPTIONSThe following additional options can be specified:-v, –verboseVerbose output. This option makes the list command show the interface name, the rule options (if any), and the TOS masks. The packet and byte counters are also listed, with the suffix ‘K’, ‘M’ or ‘G’ for 1000, 1,000,000 and 1,000,000,000 multipliers respectively (but see the -x flag to change this). For appending, insertion, deletion and replacement, this causes detailed information on the rule or rules to be printed.-n, –numericNumeric output. IP addresses and port numbers will be printed in numeric format. By default, the program will try to display them as host names, network names, or services (whenever applicable).-x, –exactExpand numbers. Display the exact value of the packet and byte counters, instead of only the rounded number in K’s (multiples of 1000) M’s (multiples of 1000K) or G’s (multiples of 1000M). This option is only relevant for the -L command.–line-numbersWhen listing rules, add line numbers to the beginning of each rule, corresponding to that rule’s position in the chain.–modprobe=commandWhen adding or inserting rules into a chain, use command to load any necessary modules (targets, match extensions, etc).

Match Extensions

iptables can use extended packet matching modules. These are loaded in two ways: implicitly, when -p or –protocol is specified, or with the -m or –match options, followed by the matching module name; after these, various extra command line options become available, depending on the specific module. You can specify multiple extended match modules in one line, and you can use the -h or –help options after the module has been specified to receive help specific to that module.

The following are included in the base package, and most of these can be preceded by a ! to invert the sense of the match.

accountAccount traffic for all hosts in defined network/netmask.

Features:

– long (one counter per protocol TCP/UDP/IMCP/Other) and short statistics

– one iptables rule for all hosts in network/netmask

– loading/saving counters (by reading/writting to procfs entries)–aaddrnetwork/netmaskdefines network/netmask for which make statistics.–anamenamedefines name of list where statistics will be kept. If no is specified DEFAULT will be used.–ashorttable will colect only short statistics (only total counters without splitting it into protocols.Example usage:

account traffic for/to 192.168.0.0/24 network into table mynetwork:

# iptables -A FORWARD -m account –aname mynetwork –aaddr 192.168.0.0/24

account traffic for/to WWW serwer for 192.168.0.0/24 network into table mywwwserver:

# iptables -A INPUT -p tcp –dport 80 -m account –aname mywwwserver –aaddr 192.168.0.0/24 –ashort

# iptables -A OUTPUT -p tcp –sport 80 -m account –aname mywwwserver –aaddr 192.168.0.0/24 –ashort

read counters:

# cat /proc/net/ipt_account/mynetwork # cat /proc/net/ipt_account/mywwwserver

set counters:

# echo “ip = 192.168.0.1 packets_src = 0” > /proc/net/ipt_account/mywwserver

Webpage: http://www.barbara.eu.org/~quaker/ipt_account/

addrtypeThis module matches packets based on their address type. Address types are used within the kernel networking stack and categorize addresses into various groups. The exact definition of that group depends on the specific layer three protocol.The following address types are possible:UNSPEC

an unspecified address (i.e. 0.0.0.0) UNICAST an unicast address LOCAL a local address BROADCAST a broadcast address ANYCAST an anycast packet MULTICAST a multicast address BLACKHOLE a blackhole address UNREACHABLE an unreachable address PROHIBIT a prohibited address THROW FIXME NAT FIXME XRESOLVE FIXME–src-typetypeMatches if the source address is of given type–dst-typetypeMatches if the destination address is of given type

ahThis module matches the SPIs in Authentication header of IPsec packets.–ahspi [!] spi[:spi]

childlevelThis is an experimental module. It matches on whether the packet is part of a master connection or one of its children (or grandchildren, etc). For instance, most packets are level 0. FTP data transfer is level 1.–childlevel [!] level

commentAllows you to add comments (up to 256 characters) to any rule.–commentcommentExample:iptables -A INPUT -s 192.168.0.0/16 -m comment –comment “A privatized IP block”

conditionThis matches if a specific /proc filename is ‘0’ or ‘1’.–condition[!] filenameMatch on boolean value stored in /proc/net/ipt_condition/filename file

connbytesMatch by how many bytes or packets a connection (or one of the two flows constituting the connection) have tranferred so far, or by average bytes per packet.

The counters are 64bit and are thus not expected to overflow 😉

The primary use is to detect long-lived downloads and mark them to be scheduled using a lower priority band in traffic control.

The transfered bytes per connection can also be viewed through /proc/net/ip_conntrack and accessed via ctnetlink[!–connbytesfrom:[to]match packets from a connection whose packets/bytes/average packet size is more than FROM and less than TO bytes/packets. if TO is omitted only FROM check is done. “!” is used to match packets not falling in the range.–connbytes-dir [original|reply|both]which packets to consider–connbytes-mode [packets|bytes|avgpkt]whether to check the amount of packets, number of bytes transferred or the average size (in bytes) of all packets received so far. Note that when “both” is used together with “avgpkt”, and data is going (mainly) only in one direction (for example HTTP), the average packet size will be about half of the actual data packets.Example:iptables .. -m connbytes –connbytes 10000:100000 –connbytes-dir both –connbytes-mode bytes …

connlimitAllows you to restrict the number of parallel TCP connections to a server per client IP address (or address block).[!–connlimit-abovenmatch if the number of existing tcp connections is (not) above n–connlimit-maskbitsgroup hosts using maskExamples:# allow 2 telnet connections per client hostiptables -p tcp –syn –dport 23 -m connlimit –connlimit-above 2 -j REJECT# you can also match the other way around:iptables -p tcp –syn –dport 23 -m connlimit ! –connlimit-above 2 -j ACCEPT# limit the nr of parallel http requests to 16 per class C sized network (24 bit netmask)iptables -p tcp –syn –dport 80 -m connlimit –connlimit-above 16 –connlimit-mask 24 -j REJECT

connmarkThis module matches the netfilter mark field associated with a connection (which can be set using the CONNMARK target below).–markvalue[/mask]Matches packets in connections with the given mark value (if a mask is specified, this is logically ANDed with the mark before the comparison).

connrateThis module matches the current transfer rate in a connection.–connrate[!] [from]:[to]Match against the current connection transfer rate being within ‘from’ and ‘to’ bytes per second. When the “!” argument is used before the range, the sense of the match is inverted.

conntrackThis module, when combined with connection tracking, allows access to more connection tracking information than the “state” match. (this module is present only if iptables was compiled under a kernel supporting this feature)–ctstatestateWhere state is a comma separated list of the connection states to match. Possible states are INVALID meaning that the packet is associated with no known connection, ESTABLISHED meaning that the packet is associated with a connection which has seen packets in both directions, NEW meaning that the packet has started a new connection, or otherwise associated with a connection which has not seen packets in both directions, and RELATED meaning that the packet is starting a new connection, but is associated with an existing connection, such as an FTP data transfer, or an ICMP error. SNAT A virtual state, matching if the original source address differs from the reply destination. DNAT A virtual state, matching if the original destination differs from the reply source.–ctprotoprotoProtocol to match (by number or name)–ctorigsrc[!] address[/mask]Match against original source address–ctorigdst[!] address[/mask]Match against original destination address–ctreplsrc[!] address[/mask]Match against reply source address–ctrepldst[!] address[/mask]Match against reply destination address–ctstatus[NONE|EXPECTED|SEEN_REPLY|ASSURED][,…]Match against internal conntrack states–ctexpiretime[:time]Match remaining lifetime in seconds against given value or range of values (inclusive)

dccp–source-port,–sport [!port[:port]–destination-port,–dport [!port[:port]–dccp-types [!maskMatch when the DCCP packet type is one of ‘mask’. ‘mask’ is a comma-separated list of packet types. Packet types are: REQUEST RESPONSE DATA ACK DATAACK CLOSEREQ CLOSE RESET SYNC SYNCACK INVALID.–dccp-option [!numberMatch if DCP option set.

dscpThis module matches the 6 bit DSCP field within the TOS field in the IP header. DSCP has superseded TOS within the IETF.–dscpvalueMatch against a numeric (decimal or hex) value [0-63].–dscp-classDiffServ ClassMatch the DiffServ class. This value may be any of the BE, EF, AFxx or CSx classes. It will then be converted into it’s according numeric value.

dstlimitThis module allows you to limit the packet per second (pps) rate on a per destination IP or per destination port base. As opposed to the ‘limit’ match, every destination ip / destination port has it’s own limit.THIS MODULE IS DEPRECATED AND HAS BEEN REPLACED BY ”hashlimit”–dstlimitavgMaximum average match rate (packets per second unless followed by /sec /minute /hour /day postfixes).–dstlimit-modemodeThe limiting hashmode. Is the specified limit per dstip, dstip-dstport tuple, srcip-dstip tuple, or per srcipdstip-dstport tuple.–dstlimit-namenameName for /proc/net/ipt_dstlimit/* file entry[–dstlimit-burstburst]Number of packets to match in a burst. Default: 5[–dstlimit-htable-sizesize]Number of buckets in the hashtable[–dstlimit-htable-maxmax]Maximum number of entries in the hashtable[–dstlimit-htable-gcintervalinterval]Interval between garbage collection runs of the hashtable (in miliseconds). Default is 1000 (1 second).[–dstlimit-htable-expiretimeAfter which time are idle entries expired from hashtable (in miliseconds)? Default is 10000 (10 seconds).

ecnThis allows you to match the ECN bits of the IPv4 and TCP header. ECN is the Explicit Congestion Notification mechanism as specified in RFC3168–ecn-tcp-cwrThis matches if the TCP ECN CWR (Congestion Window Received) bit is set.–ecn-tcp-eceThis matches if the TCP ECN ECE (ECN Echo) bit is set.–ecn-ip-ectnumThis matches a particular IPv4 ECT (ECN-Capable Transport). You have to specify a number between ‘0’ and ‘3’.

espThis module matches the SPIs in ESP header of IPsec packets.–espspi [!] spi[:spi]

fuzzyThis module matches a rate limit based on a fuzzy logic controller [FLC]–lower-limitnumberSpecifies the lower limit (in packets per second).–upper-limitnumberSpecifies the upper limit (in packets per second).

hashlimitThis patch adds a new match called ‘hashlimit’. The idea is to have something like ‘limit’, but either per destination-ip or per (destip,destport) tuple.

It gives you the ability to express’1000 packets per second for every host in 192.168.0.0/16′

‘۱۰۰ packets per second for every service of 192.168.1.1’with a single iptables rule.–hashlimitrateA rate just like the limit match–hashlimit-burstnumBurst value, just like limit match–hashlimit-modedestip | destip-destportLimit per IP or per port–hashlimit-namefooThe name for the /proc/net/ipt_hashlimit/foo entry–hashlimit-htable-sizenumThe number of buckets of the hash table–hashlimit-htable-maxnumMaximum entries in the hash–hashlimit-htable-expirenumAfter how many miliseconds do hash entries expire–hashlimit-htable-gcintervalnumHow many miliseconds between garbage collection intervals

helperThis module matches packets related to a specific conntrack-helper.–helperstringMatches packets related to the specified conntrack-helper.string can be “ftp” for packets related to a ftp-session on default port. For other ports append -portnr to the value, ie. “ftp-2121”.

Same rules apply for other conntrack-helpers.

icmpThis extension is loaded if ‘–protocol icmp’ is specified. It provides the following option:–icmp-type [!] typenameThis allows specification of the ICMP type, which can be a numeric ICMP type, or one of the ICMP type names shown by the command

iptables -p icmp -h

iprangeThis matches on a given arbitrary range of IPv4 addresses[!]–src-rangeip-ipMatch source IP in the specified range.[!]–dst-rangeip-ipMatch destination IP in the specified range.

ipv4optionsMatch on IPv4 header options like source routing, record route, timestamp and router-alert.–ssrr

To match packets with the flag strict source routing.

–lsrr

To match packets with the flag loose source routing.–no-srrTo match packets with no flag for source routing.[!–rrTo match packets with the RR flag.[!–tsTo match packets with the TS flag.[!–raTo match packets with the router-alert option.[!–any-optTo match a packet with at least one IP option, or no IP option at all if ! is chosen.Examples:$ iptables -A input -m ipv4options –rr -j DROPwill drop packets with the record-route flag.$ iptables -A input -m ipv4options –ts -j DROPwill drop packets with the timestamp flag.

lengthThis module matches the length of a packet against a specific value or range of values.–length [!] length[:length]

limitThis module matches at a limited rate using a token bucket filter. A rule using this extension will match until this limit is reached (unless the ‘!’ flag is used). It can be used in combination with the LOG target to give limited logging, for example.–limitrateMaximum average matching rate: specified as a number, with an optional ‘/second’, ‘/minute’, ‘/hour’, or ‘/day’ suffix; the default is 3/hour.–limit-burstnumberMaximum initial number of packets to match: this number gets recharged by one every time the limit specified above is not reached, up to this number; the default is 5.

mac–mac-source [!] addressMatch source MAC address. It must be of the form XX:XX:XX:XX:XX:XX. Note that this only makes sense for packets coming from an Ethernet device and entering the PREROUTINGFORWARD or INPUT chains.

markThis module matches the netfilter mark field associated with a packet (which can be set using the MARK target below).–markvalue[/mask]Matches packets with the given unsigned mark value (if a mask is specified, this is logically ANDed with the mask before the comparison).

mportThis module matches a set of source or destination ports. Up to 15 ports can be specified. It can only be used in conjunction with -p tcp or -p udp.–source-portsport[,port[,port…]]Match if the source port is one of the given ports. The flag –sports is a convenient alias for this option.–destination-portsport[,port[,port…]]Match if the destination port is one of the given ports. The flag –dports is a convenient alias for this option.–portsport[,port[,port…]]Match if the both the source and destination ports are equal to each other and to one of the given ports.

multiportThis module matches a set of source or destination ports. Up to 15 ports can be specified. A port range (port:port) counts as two ports. It can only be used in conjunction with -p tcp or -p udp.–source-ports[!] port[,port[,port:port…]]Match if the source port is one of the given ports. The flag –sports is a convenient alias for this option.–destination-ports[!] port[,port[,port:port…]]Match if the destination port is one of the given ports. The flag –dports is a convenient alias for this option.–ports[!] port[,port[,port:port…]]Match if either the source or destination ports are equal to one of the given ports.

nthThis module matches every ‘n’th packet–everyvalueMatch every ‘value’ packet[–counternum]Use internal counter number ‘num’. Default is ‘0’.[–startnum]Initialize the counter at the number ‘num’ insetad of ‘0’. Most between ‘0’ and ‘value’-1.[–packetnum]Match on ‘num’ packet. Most be between ‘0’ and ‘value’-1.

osfThe idea of passive OS fingerprint matching exists for quite a long time, but was created as extension fo OpenBSD pf only some weeks ago. Original idea was lurked in some OpenBSD mailing list (thanks grange@open…) and than adopted for Linux netfilter in form of this code.

Original fingerprint table was created by Michal Zalewski <lcamtuf@coredump.cx>.

This module compares some data(WS, MSS, options and it’s order, ttl, df and others) from first SYN packet (actually from packets with SYN bit set) with dynamically loaded OS fingerprints.–log 1/0

If present, OSF will log determined genres even if they don’t match desired one.0 – log all determined entries, 1 – only first one.In syslog you find something like this:ipt_osf: Windows [2000:SP3:Windows XP Pro SP1, 2000 SP3]: 11.22.33.55:4024 -> 11.22.33.44:139

ipt_osf: Unknown: 16384:106:1:48:020405B401010402 44.33.22.11:1239 -> 11.22.33.44:80–smartif present, OSF will use some smartness to determine remote OS. OSF will use initial TTL only if source of connection is in our local network.–netlinkIf present, OSF will log all events also through netlink NETLINK_NFLOG groupt 1.–genre[!] stringMatch a OS genre by passive fingerprintingExample:

#iptables -I INPUT -j ACCEPT -p tcp -m osf –genre Linux –log 1 –smart

NOTE: -p tcp is obviously required as it is a TCP match.

Fingerprints can be loaded and read through /proc/sys/net/ipv4/osf file. One can flush all fingerprints with following command:echo -en FLUSH > /proc/sys/net/ipv4/osfOnly one fingerprint per open/write/close.

Fingerprints can be downloaded from http://www.openbsd.org/cgi-bin/cvsweb/src/etc/pf.os

ownerThis module attempts to match various characteristics of the packet creator, for locally-generated packets. It is only valid in the OUTPUT chain, and even this some packets (such as ICMP ping responses) may have no owner, and hence never match.–uid-owneruseridMatches if the packet was created by a process with the given effective user id.–gid-ownergroupidMatches if the packet was created by a process with the given effective group id.–pid-ownerprocessidMatches if the packet was created by a process with the given process id.–sid-ownersessionidMatches if the packet was created by a process in the given session group.–cmd-ownernameMatches if the packet was created by a process with the given command name. (this option is present only if iptables was compiled under a kernel supporting this feature)NOTE: pid, sid and command matching are broken on SMP

physdevThis module matches on the bridge port input and output devices enslaved to a bridge device. This module is a part of the infrastructure that enables a transparent bridging IP firewall and is only useful for kernel versions above version 2.5.44.–physdev-in [!] nameName of a bridge port via which a packet is received (only for packets entering the INPUTFORWARD and PREROUTING chains). If the interface name ends in a “+”, then any interface which begins with this name will match. If the packet didn’t arrive through a bridge device, this packet won’t match this option, unless ‘!’ is used.–physdev-out [!] nameName of a bridge port via which a packet is going to be sent (for packets entering the FORWARDOUTPUT and POSTROUTING chains). If the interface name ends in a “+”, then any interface which begins with this name will match. Note that in the nat and mangle OUTPUT chains one cannot match on the bridge output port, however one can in the filter OUTPUT chain. If the packet won’t leave by a bridge device or it is yet unknown what the output device will be, then the packet won’t match this option, unless[!] –physdev-is-inMatches if the packet has entered through a bridge interface.[!] –physdev-is-outMatches if the packet will leave through a bridge interface.[!] –physdev-is-bridgedMatches if the packet is being bridged and therefore is not being routed. This is only useful in the FORWARD and POSTROUTING chains.

pkttypeThis module matches the link-layer packet type.–pkt-type[unicast|broadcast|multicast]

policyThis modules matches the policy used by IPsec for handling a packet.–dirin|outUsed to select whether to match the policy used for decapsulation or the policy that will be used for encapsulation. in is valid in the PREROUTING, INPUT and FORWARD chains, out is valid in the POSTROUTING, OUTPUT and FORWARD chains.–polnone|ipsecMatches if the packet is subject to IPsec processing.–strictSelects whether to match the exact policy or match if any rule of the policy matches the given policy.–reqididMatches the reqid of the policy rule. The reqid can be specified with setkey(8) using unique:id as level.–spispiMatches the SPI of the SA.–protoah|esp|ipcompMatches the encapsulation protocol.–modetunnel|transportMatches the encapsulation mode.–tunnel-srcaddr[/mask]Matches the source end-point address of a tunnel mode SA. Only valid with –mode tunnel.–tunnel-dstaddr[/mask]Matches the destination end-point address of a tunnel mode SA. Only valid with –mode tunnel.–next

Start the next element in the policy specification. Can only be used with –strict

psdAttempt to detect TCP and UDP port scans. This match was derived from Solar Designer’s scanlogd.–psd-weight-thresholdthresholdTotal weight of the latest TCP/UDP packets with different destination ports coming from the same host to be treated as port scan sequence.–psd-delay-thresholddelayDelay (in hundredths of second) for the packets with different destination ports coming from the same host to be treated as possible port scan subsequence.–psd-lo-ports-weightweightWeight of the packet with privileged (<=1024) destination port.–psd-hi-ports-weightweightWeight of the packet with non-priviliged destination port.

quotaImplements network quotas by decrementing a byte counter with each packet.–quotabytesThe quota in bytes.KNOWN BUGS: this does not work on SMP systems.

randomThis module randomly matches a certain percentage of all packets.–averagepercentMatches the given percentage. If omitted, a probability of 50% is set.

realmThis matches the routing realm. Routing realms are used in complex routing setups involving dynamic routing protocols like BGP.–realm[!]value[/mask]Matches a given realm number (and optionally mask).

recentAllows you to dynamically create a list of IP addresses and then match against that list in a few different ways.

For example, you can create a ‘badguy’ list out of people attempting to connect to port 139 on your firewall and then DROP all future packets from them without considering them.–namenameSpecify the list to use for the commands. If no name is given then ‘DEFAULT’ will be used.[!–setThis will add the source address of the packet to the list. If the source address is already in the list, this will update the existing entry. This will always return success (or failure if ‘!’ is passed in).[!–rcheckCheck if the source address of the packet is currently in the list.[!–updateLike –rcheck, except it will update the “last seen” timestamp if it matches.[!–removeCheck if the source address of the packet is currently in the list and if so that address will be removed from the list and the rule will return true. If the address is not found, false is returned.[!–secondssecondsThis option must be used in conjunction with one of –rcheck or –update. When used, this will narrow the match to only happen when the address is in the list and was seen within the last given number of seconds.[!–hitcounthitsThis option must be used in conjunction with one of –rcheck or –update. When used, this will narrow the match to only happen when the address is in the list and packets had been received greater than or equal to the given value. This option may be used along with –seconds to create an even narrower match requiring a certain number of hits within a specific time frame.–rttl

This option must be used in conjunction with one of –rcheck or –update. When used, this will narrow the match to only happen when the address is in the list and the TTL of the current packet matches that of the packet which hit the –set rule. This may be useful if you have problems with people faking their source address in order to DoS you via this module by disallowing others access to your site by sending bogus packets to you.Examples:# iptables -A FORWARD -m recent –name badguy –rcheck –seconds 60 -j DROP

# iptables -A FORWARD -p tcp -i eth0 –dport 139 -m recent –name badguy –set -j DROPOfficial website (http://snowman.net/projects/ipt_recent/) also has some examples of usage.

/proc/net/ipt_recent/* are the current lists of addresses and information about each entry of each list.

Each file in /proc/net/ipt_recent/ can be read from to see the current list or written two using the following commands to modify the list:echo xx.xx.xx.xx > /proc/net/ipt_recent/DEFAULTto Add to the DEFAULT listecho -xx.xx.xx.xx > /proc/net/ipt_recent/DEFAULTto Remove from the DEFAULT listecho clear > /proc/net/ipt_recent/DEFAULTto empty the DEFAULT list.The module itself accepts parameters, defaults shown:ip_list_tot=۱۰۰Number of addresses remembered per tableip_pkt_list_tot=۲۰Number of packets per address rememberedip_list_hash_size=۰Hash table size. 0 means to calculate it based on ip_list_tot, default: 512ip_list_perms=۰۶۴۴Permissions for /proc/net/ipt_recent/* filesdebug=۰Set to 1 to get lots of debugging info

sctp–source-port,–sport [!port[:port]–destination-port,–dport [!port[:port]–chunk-types [!all|any|onlychunktype[:flags] […]The flag letter in upper case indicates that the flag is to match if set, in the lower case indicates to match if unset.

Chunk types: DATA INIT INIT_ACK SACK HEARTBEAT HEARTBEAT_ACK ABORT SHUTDOWN SHUTDOWN_ACK ERROR COOKIE_ECHO COOKIE_ACK ECN_ECNE ECN_CWR SHUTDOWN_COMPLETE ASCONF ASCONF_ACK

chunk type available flags
DATA U B E u b e
ABORT T t
SHUTDOWN_COMPLETE T t

(lowercase means flag should be “off”, uppercase means “on”)Examples:

iptables -A INPUT -p sctp –dport 80 -j DROP

iptables -A INPUT -p sctp –chunk-types any DATA,INIT -j DROP

iptables -A INPUT -p sctp –chunk-types any DATA:Be -j ACCEPT

setThis modules macthes IP sets which can be defined by ipset(۸).–set setname flag[,flag…]where flags are src and/or dst and there can be no more than six of them. Hence the command

iptables -A FORWARD -m set --set test src,dst

will match packets, for which (depending on the type of the set) the source address or port number of the packet can be found in the specified set. If there is a binding belonging to the mached set element or there is a default binding for the given set, then the rule will match the packet only if additionally (depending on the type of the set) the destination address or port number of the packet can be found in the set according to the binding.

stateThis module, when combined with connection tracking, allows access to the connection tracking state for this packet.–statestateWhere state is a comma separated list of the connection states to match. Possible states are INVALID meaning that the packet could not be identified for some reason which includes running out of memory and ICMP errors which don’t correspond to any known connection, ESTABLISHED meaning that the packet is associated with a connection which has seen packets in both directions, NEW meaning that the packet has started a new connection, or otherwise associated with a connection which has not seen packets in both directions, and RELATED meaning that the packet is starting a new connection, but is associated with an existing connection, such as an FTP data transfer, or an ICMP error.

stringThis modules matches a given string by using some pattern matching strategy. It requires a linux kernel >= 2.6.14.–algobm|kmpSelect the pattern matching strategy. (bm = Boyer-Moore, kmp = Knuth-Pratt-Morris)–fromoffsetSet the offset from which it starts looking for any matching. If not passed, default is 0.–tooffsetSet the offset from which it starts looking for any matching. If not passed, default is the packet size.–stringpatternMatches the given pattern. –hex-stringpattern Matches the given pattern in hex notation.

tcpThese extensions are loaded if ‘–protocol tcp’ is specified. It provides the following options:–source-port [!] port[:port]Source port or port range specification. This can either be a service name or a port number. An inclusive range can also be specified, using the format port:port. If the first port is omitted, “0” is assumed; if the last is omitted, “65535” is assumed. If the second port greater then the first they will be swapped. The flag –sport is a convenient alias for this option.–destination-port [!] port[:port]Destination port or port range specification. The flag –dport is a convenient alias for this option.–tcp-flags [!] mask compMatch when the TCP flags are as specified. The first argument is the flags which we should examine, written as a comma-separated list, and the second argument is a comma-separated list of flags which must be set. Flags are: SYN ACK FIN RST URG PSH ALL NONE. Hence the command

iptables -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST SYN

will only match packets with the SYN flag set, and the ACK, FIN and RST flags unset.[!] –synOnly match TCP packets with the SYN bit set and the ACK,RST and FIN bits cleared. Such packets are used to request TCP connection initiation; for example, blocking such packets coming in an interface will prevent incoming TCP connections, but outgoing TCP connections will be unaffected. It is equivalent to –tcp-flags SYN,RST,ACK,FIN SYN. If the “!” flag precedes the “–syn”, the sense of the option is inverted.–tcp-option [!] numberMatch if TCP option set.–mssvalue[:value]Match TCP SYN or SYN/ACK packets with the specified MSS value (or range), which control the maximum packet size for that connection.

tcpmssThis matches the TCP MSS (maximum segment size) field of the TCP header. You can only use this on TCP SYN or SYN/ACK packets, since the MSS is only negotiated during the TCP handshake at connection startup time.[!]–mss value[:value]”Match a given TCP MSS value or range.

timeThis matches if the packet arrival time/date is within a given range. All options are facultative.–timestartvalueMatch only if it is after ‘value’ (Inclusive, format: HH:MM ; default 00:00).–timestopvalueMatch only if it is before ‘value’ (Inclusive, format: HH:MM ; default 23:59).–dayslistofdaysMatch only if today is one of the given days. (format: Mon,Tue,Wed,Thu,Fri,Sat,Sun ; default everyday)–datestartdateMatch only if it is after ‘date’ (Inclusive, format: YYYY[:MM[:DD[:hh[:mm[:ss]]]]] ; h,m,s start from 0 ; default to 1970)–datestopdateMatch only if it is before ‘date’ (Inclusive, format: YYYY[:MM[:DD[:hh[:mm[:ss]]]]] ; h,m,s start from 0 ; default to 2037)

tosThis module matches the 8 bits of Type of Service field in the IP header (ie. including the precedence bits).–tostosThe argument is either a standard name, (use
iptables -m tos -h
to see the list), or a numeric value to match.

ttlThis module matches the time to live field in the IP header.–ttl-eqttlMatches the given TTL value.–ttl-gtttlMatches if TTL is greater than the given TTL value.–ttl-ltttlMatches if TTL is less than the given TTL value.

u32U32 allows you to extract quantities of up to 4 bytes from a packet, AND them with specified masks, shift them by specified amounts and test whether the results are in any of a set of specified ranges. The specification of what to extract is general enough to skip over headers with lengths stored in the packet, as in IP or TCP header lengths.

Details and examples are in the kernel module source.

udpThese extensions are loaded if ‘–protocol udp’ is specified. It provides the following options:–source-port [!] port[:port]Source port or port range specification. See the description of the –source-port option of the TCP extension for details.–destination-port [!] port[:port]Destination port or port range specification. See the description of the –destination-port option of the TCP extension for details.

uncleanThis module takes no options, but attempts to match packets which seem malformed or unusual. This is regarded as experimental.

Target Extensions

iptables can use extended target modules: the following are included in the standard distribution.

BALANCEThis allows you to DNAT connections in a round-robin way over a given range of destination addresses.–to-destinationipaddr-ipaddrAddress range to round-robin over.

CLASSIFYThis module allows you to set the skb->priority value (and thus classify the packet into a specific CBQ class).–set-classMAJOR:MINORSet the major and minor class value.

CLUSTERIPThis module allows you to configure a simple cluster of nodes that share a certain IP and MAC address without an explicit load balancer in front of them. Connections are statically distributed between the nodes in this cluster.–new

Create a new ClusterIP. You always have to set this on the first rule for a given ClusterIP.–hashmodemodeSpecify the hashing mode. Has to be one of sourceip, sourceip-sourceport, sourceip-sourceport-destport–clustermacmacSpecify the ClusterIP MAC address. Has to be a link-layer multicast address–total-nodesnumNumber of total nodes within this cluster.–local-nodenumLocal node number within this cluster.–hash-initrndSpecify the random seed used for hash initialization.

CONNMARKThis module sets the netfilter mark value associated with a connection–set-mark mark[/mask]Set connection mark. If a mask is specified then only those bits set in the mask is modified.–save-mark [–mask mask]Copy the netfilter packet mark value to the connection mark. If a mask is specified then only those bits are copied.–restore-mark [–mask mask]Copy the connection mark value to the packet. If a mask is specified then only those bits are copied. This is only valid in the mangle table.

DNATThis target is only valid in the nat table, in the PREROUTING and OUTPUT chains, and user-defined chains which are only called from those chains. It specifies that the destination address of the packet should be modified (and all future packets in this connection will also be mangled), and rules should cease being examined. It takes one type of option:–to-destinationipaddr[-ipaddr][:portport]which can specify a single new destination IP address, an inclusive range of IP addresses, and optionally, a port range (which is only valid if the rule also specifies -p tcp or -p udp). If no port range is specified, then the destination port will never be modified.In Kernels up to 2.6.10 you can add several –to-destination options. For those kernels, if you specify more than one destination address, either via an address range or multiple –to-destination options, a simple round-robin (one after another in cycle) load balancing takes place between these addresses. Later Kernels (>= 2.6.11-rc1) don’t have the ability to NAT to multiple ranges anymore.

DSCPThis target allows to alter the value of the DSCP bits within the TOS header of the IPv4 packet. As this manipulates a packet, it can only be used in the mangle table.–set-dscpvalueSet the DSCP field to a numerical value (can be decimal or hex)–set-dscp-classclassSet the DSCP field to a DiffServ class.

ECNThis target allows to selectively work around known ECN blackholes. It can only be used in the mangle table.–ecn-tcp-removeRemove all ECN bits from the TCP header. Of course, it can only be used in conjunction with -p tcp.

IPMARKAllows you to mark a received packet basing on its IP address. This can replace many mangle/mark entries with only one, if you use firewall based classifier.

This target is to be used inside the mangle table, in the PREROUTING, POSTROUTING or FORWARD hooks.–addrsrc/dstUse source or destination IP address.–and-maskmaskPerform bitwise ‘and’ on the IP address and this mask.–or-maskmaskPerform bitwise ‘or’ on the IP address and this mask.The order of IP address bytes is reversed to meet “human order of bytes”: 192.168.0.1 is 0xc0a80001. At first the ‘and’ operation is performed, then ‘or’.

Examples:

We create a queue for each user, the queue number is adequate to the IP address of the user, e.g.: all packets going to/from 192.168.5.2 are directed to 1:0502 queue, 192.168.5.12 -> 1:050c etc.

We have one classifier rule:tc filter add dev eth3 parent 1:0 protocol ip fwEarlier we had many rules just like below:iptables -t mangle -A POSTROUTING -o eth3 -d 192.168.5.2 -j MARK –set-mark 0x10502

iptables -t mangle -A POSTROUTING -o eth3 -d 192.168.5.3 -j MARK –set-mark 0x10503Using IPMARK target we can replace all the mangle/mark rules with only one:iptables -t mangle -A POSTROUTING -o eth3 -j IPMARK –addr=dst –and-mask=0xffff –or-mask=0x10000On the routers with hundreds of users there should be significant load decrease (e.g. twice).

IPV4OPTSSTRIPStrip all the IP options from a packet.

The target doesn’t take any option, and therefore is extremly easy to use :

# iptables -t mangle -A PREROUTING -j IPV4OPTSSTRIP

LOGTurn on kernel logging of matching packets. When this option is set for a rule, the Linux kernel will print some information on all matching packets (like most IP header fields) via the kernel log (where it can be read with dmesg or syslogd(۸)). This is a “non-terminating target”, i.e. rule traversal continues at the next rule. So if you want to LOG the packets you refuse, use two separate rules with the same matching criteria, first using target LOG then DROP (or REJECT).–log-levellevelLevel of logging (numeric or see syslog.conf(۵)).–log-prefixprefixPrefix log messages with the specified prefix; up to 29 letters long, and useful for distinguishing messages in the logs.–log-tcp-sequenceLog TCP sequence numbers. This is a security risk if the log is readable by users.–log-tcp-optionsLog options from the TCP packet header.–log-ip-optionsLog options from the IP packet header.–log-uidLog the userid of the process which generated the packet.

MARKThis is used to set the netfilter mark value associated with the packet. It is only valid in the mangle table. It can for example be used in conjunction with iproute2.–set-markmark

MASQUERADEThis target is only valid in the nat table, in the POSTROUTING chain. It should only be used with dynamically assigned IP (dialup) connections: if you have a static IP address, you should use the SNAT target. Masquerading is equivalent to specifying a mapping to the IP address of the interface the packet is going out, but also has the effect that connections are forgotten when the interface goes down. This is the correct behavior when the next dialup is unlikely to have the same interface address (and hence any established connections are lost anyway). It takes one option:–to-portsport[-port]This specifies a range of source ports to use, overriding the default SNAT source port-selection heuristics (see above). This is only valid if the rule also specifies -p tcp or -p udp.

MIRRORThis is an experimental demonstration target which inverts the source and destination fields in the IP header and retransmits the packet. It is only valid in the INPUTFORWARD and PREROUTING chains, and user-defined chains which are only called from those chains. Note that the outgoing packets are NOT seen by any packet filtering chains, connection tracking or NAT, to avoid loops and other problems.

NETMAPThis target allows you to statically map a whole network of addresses onto another network of addresses. It can only be used from rules in the nat table.–toaddress[/mask]Network address to map to. The resulting address will be constructed in the following way: All ‘one’ bits in the mask are filled in from the new ‘address’. All bits that are zero in the mask are filled in from the original address.

NFQUEUEThis target is an extension of the QUEUE target. As opposed to QUEUE, it allows you to put a packet into any specific queue, identified by its 16-bit queue number.–queue-numvalueThis specifies the QUEUE number to use. Valud queue numbers are 0 to 65535. The default value is 0.It can only be used with Kernel versions 2.6.14 or later, since it requiresthe nfnetlink_queue kernel support.

NOTRACKThis target disables connection tracking for all packets matching that rule.It can only be used in theraw table.

REDIRECTThis target is only valid in the nat table, in the PREROUTING and OUTPUT chains, and user-defined chains which are only called from those chains. It redirects the packet to the machine itself by changing the destination IP to the primary address of the incoming interface (locally-generated packets are mapped to the 127.0.0.1 address). It takes one option:–to-portsport[-port]This specifies a destination port or range of ports to use: without this, the destination port is never altered. This is only valid if the rule also specifies -p tcp or -p udp.

REJECTThis is used to send back an error packet in response to the matched packet: otherwise it is equivalent to DROP so it is a terminating TARGET, ending rule traversal. This target is only valid in the INPUTFORWARD and OUTPUT chains, and user-defined chains which are only called from those chains. The following option controls the nature of the error packet returned:–reject-withtypeThe type given can be

 icmp-net-unreachable
 icmp-host-unreachable
 icmp-port-unreachable
 icmp-proto-unreachable
 icmp-net-prohibited
 icmp-host-prohibited or
 icmp-admin-prohibited (*)

which return the appropriate ICMP error message (port-unreachable is the default). The option tcp-reset can be used on rules which only match the TCP protocol: this causes a TCP RST packet to be sent back. This is mainly useful for blocking ident (113/tcp) probes which frequently occur when sending mail to broken mail hosts (which won’t accept your mail otherwise).(*) Using icmp-admin-prohibited with kernels that do not support it will result in a plain DROP instead of REJECT

SAMESimilar to SNAT/DNAT depending on chain: it takes a range of addresses (‘–to 1.2.3.4-1.2.3.7’) and gives a client the same source-/destination-address for each connection.–to<ipaddr>-<ipaddr>Addresses to map source to. May be specified more than once for multiple ranges.–nodstDon’t use the destination-ip in the calculations when selecting the new source-ip

SETThis modules adds and/or deletes entries from IP sets which can be defined by ipset(۸).–add-set setname flag[,flag…]add the address(es)/port(s) of the packet to the sets–del-set setname flag[,flag…]delete the address(es)/port(s) of the packet from the sets, where flags are src and/or dst and there can be no more than six of them.The bindings to follow must previously be defined in order to usemultilevel adding/deleting by the SET target.

SNATThis target is only valid in the nat table, in the POSTROUTING chain. It specifies that the source address of the packet should be modified (and all future packets in this connection will also be mangled), and rules should cease being examined. It takes one type of option:–to-sourceipaddr[-ipaddr][:portport]which can specify a single new source IP address, an inclusive range of IP addresses, and optionally, a port range (which is only valid if the rule also specifies -p tcp or -p udp). If no port range is specified, then source ports below 512 will be mapped to other ports below 512: those between 512 and 1023 inclusive will be mapped to ports below 1024, and other ports will be mapped to 1024 or above. Where possible, no port alteration will occur.In Kernels up to 2.6.10, you can add several –to-source options. For those kernels, if you specify more than one source address, either via an address range or multiple –to-source options, a simple round-robin (one after another in cycle) takes place between these addresses. Later Kernels (>= 2.6.11-rc1) don’t have the ability to NAT to multiple ranges anymore.

TARPITCaptures and holds incoming TCP connections using no local per-connection resources. Connections are accepted, but immediately switched to the persist state (0 byte window), in which the remote side stops sending data and asks to continue every 60-240 seconds. Attempts to close the connection are ignored, forcing the remote side to time out the connection in 12-24 minutes.

This offers similar functionality to LaBrea <http://www.hackbusters.net/LaBrea/> but doesn’t require dedicated hardware or IPs. Any TCP port that you would normally DROP or REJECT can instead become a tarpit.

To tarpit connections to TCP port 80 destined for the current machine:iptables -A INPUT -p tcp -m tcp –dport 80 -j TARPITTo significantly slow down Code Red/Nimda-style scans of unused address space, forward unused ip addresses to a Linux box not acting as a router (e.g. “ip route 10.0.0.0 255.0.0.0 ip.of.linux.box” on a Cisco), enable IP forwarding on the Linux box, and add:iptables -A FORWARD -p tcp -j TARPIT

iptables -A FORWARD -j DROPNOTE:

If you use the conntrack module while you are using TARPIT, you should also use the NOTRACK target, or the kernel will unnecessarily allocate resources for each TARPITted connection. To TARPIT incoming connections to the standard IRC port while using conntrack, you could:iptables -t raw -A PREROUTING -p tcp –dport 6667 -j NOTRACK

iptables -A INPUT -p tcp –dport 6667 -j TARPIT

TCPMSSThis target allows to alter the MSS value of TCP SYN packets, to control the maximum size for that connection (usually limiting it to your outgoing interface’s MTU minus 40). Of course, it can only be used in conjunction with -p tcp. It is only valid in the mangle table.
This target is used to overcome criminally braindead ISPs or servers which block ICMP Fragmentation Needed packets. The symptoms of this problem are that everything works fine from your Linux firewall/router, but machines behind it can never exchange large packets:1)

Web browsers connect, then hang with no data received.

۲)

Small mail works fine, but large emails hang.

۳)

ssh works fine, but scp hangs after initial handshaking.Workaround: activate this option and add a rule to your firewall configuration like:

iptables -t mangle -A FORWARD -p tcp --tcp-flags SYN,RST SYN \
            -j TCPMSS --clamp-mss-to-pmtu

–set-mssvalueExplicitly set MSS option to specified value.–clamp-mss-to-pmtuAutomatically clamp MSS value to (path_MTU – 40).These options are mutually exclusive.

TOSThis is used to set the 8-bit Type of Service field in the IP header. It is only valid in the mangle table.–set-tostosYou can use a numeric TOS values, or use

iptables -j TOS -h

to see the list of valid TOS names.

TRACEThis target has no options. It just turns on packet tracing for all packets that match this rule.

TTLThis is used to modify the IPv4 TTL header field. The TTL field determines how many hops (routers) a packet can traverse until it’s time to live is exceeded.Setting or incrementing the TTL field can potentially be very dangerous,so it should be avoided at any cost.Don’t ever set or increment the value on packets that leave your local network!mangle table.–ttl-setvalueSet the TTL value to ‘value’.–ttl-decvalueDecrement the TTL value ‘value’ times.–ttl-incvalueIncrement the TTL value ‘value’ times.

ULOGThis target provides userspace logging of matching packets. When this target is set for a rule, the Linux kernel will multicast this packet through a netlink socket. One or more userspace processes may then subscribe to various multicast groups and receive the packets. Like LOG, this is a “non-terminating target”, i.e. rule traversal continues at the next rule.–ulog-nlgroupnlgroupThis specifies the netlink group (1-32) to which the packet is sent. Default value is 1.–ulog-prefixprefixPrefix log messages with the specified prefix; up to 32 characters long, and useful for distinguishing messages in the logs.–ulog-cprangesizeNumber of bytes to be copied to userspace. A value of 0 always copies the entire packet, regardless of its size. Default is 0.–ulog-qthresholdsizeNumber of packet to queue inside kernel. Setting this value to, e.g. 10 accumulates ten packets inside the kernel and transmits them as one netlink multipart message to userspace. Default is 1 (for backwards compatibility).

XOREncrypt TCP and UDP traffic using a simple XOR encryption–keystringSet key to “string”–block-sizeSet block size

Diagnostics

Various error messages are printed to standard error. The exit code is 0 for correct functioning. Errors which appear to be caused by invalid or abused command line parameters cause an exit code of 2, and other errors cause an exit code of 1.

Bugs

Bugs? What’s this? 😉 Well, you might want to have a look at http://bugzilla.netfilter.org/

Compatibility With Ipchains

This iptables is very similar to ipchains by Rusty Russell. The main difference is that the chains INPUT and OUTPUT are only traversed for packets coming into the local host and originating from the local host respectively. Hence every packet only passes through one of the three chains (except loopback traffic, which involves both INPUT and OUTPUT chains); previously a forwarded packet would pass through all three.

The other main difference is that -i refers to the input interface; -o refers to the output interface, and both are available for packets entering the FORWARD chain.

iptables is a pure packet filter when using the default ‘filter’ table, with optional extension modules. This should simplify much of the previous confusion over the combination of IP masquerading and packet filtering seen previously. So the following options are handled differently:

-j MASQ
-M -S
-M -L

There are several other changes in iptables.

See Also

iptables-save(۸), iptables-restore(۸), ip6tables(۸), ip6tables-save(۸), ip6tables-restore(۸), libipq(۳).

The packet-filtering-HOWTO details iptables usage for packet filtering, the NAT-HOWTO details NAT, the netfilter-extensions-HOWTO details the extensions that are not in the standard distribution, and the netfilter-hacking-HOWTO details the netfilter internals.
See http://www.netfilter.org/.

دستور Iptables فارسی

iptables – ابزار مدیریت برای فیلتر کردن بسته IPv4 و NAT

iptables [-t table] -[AD] chain rule-specification [گزینه ها]
iptables [-t table] -I
 chain [rulenum] rule-specification [گزینه ها]
iptables [-t table] -R
 chain rulenum rule-specification [گزینه ها ]
iptables [-t جدول] -D
 chain rulenum [گزینه‌ها]
iptables [-t جدول] -[LFZ]
 [زنجیره] [گزینه‌ها]
iptables [-t جدول] -N
 زنجیره
iptables [-t جدول] -X
 [زنجیره]
iptables [-t table] -P
 chain target [گزینه ها]
iptables [-t table] -E
 old-chain-name new-chain-name

شرح

Iptables برای تنظیم، نگهداری و بررسی جداول قوانین فیلتر بسته IP در هسته لینوکس استفاده می شود. ممکن است چندین جدول مختلف تعریف شود. هر جدول شامل تعدادی زنجیره داخلی است و همچنین ممکن است شامل زنجیره های تعریف شده توسط کاربر باشد.

هر زنجیره فهرستی از قوانین است که می تواند با مجموعه ای از بسته ها مطابقت داشته باشد. هر قانون مشخص می کند که با بسته ای که مطابقت دارد چه باید کرد. این “هدف” نامیده می شود، که ممکن است یک پرش به یک زنجیره تعریف شده توسط کاربر در همان جدول باشد.

اهداف

یک قانون فایروال معیارهایی را برای یک بسته و یک هدف مشخص می کند. اگر بسته مطابقت نداشته باشد، قانون بعدی در زنجیره بررسی شده است. اگر مطابقت داشت، قانون بعدی با مقدار هدف مشخص می شود، که می تواند نام یک زنجیره تعریف شده توسط کاربر یا یکی از مقادیر ویژه ACCEPT ، DROP ، QUEUE یا RETURN باشد.

ACCEPT به معنای اجازه دادن به بسته است. DROP به معنای انداختن بسته روی زمین است. QUEUE به معنای ارسال بسته به فضای کاربر است. (نحوه دریافت بسته توسط فرآیند فضای کاربر توسط کنترل کننده صف خاص متفاوت است. هسته های ۲.۴.x و ۲.۶.x تا ۲.۶.۱۳ شامل کنترل کننده صف ip_queue هستند. هسته های ۲.۶.۱۴ و بعداً شامل کنترل کننده صف nfnetlink_queue نیز می شوند. بسته‌های با هدف QUEUE در این مورد به صف شماره ‘۰’ ارسال می‌شوند. لطفاً هدف NFQUEUE را همانطور که در ادامه در این صفحه مرد توضیح داده شده است، ببینید.) RETURNبه این معنی است که عبور از این زنجیره را متوقف کنید و در قانون بعدی در زنجیره قبلی (در حال تماس) از سر بگیرید. اگر به انتهای یک زنجیره داخلی رسیده یا یک قانون در یک زنجیره داخلی با هدف RETURN مطابقت داشته باشد، هدف مشخص شده توسط خط مشی زنجیره سرنوشت بسته را تعیین می کند.

جداول

در حال حاضر سه جدول مستقل وجود دارد (که کدام جداول در هر زمان وجود دارند بستگی به گزینه های پیکربندی هسته و ماژول های موجود دارد).-t، — جدول جدولاین گزینه جدول تطبیق بسته را مشخص می کند که دستور باید روی آن عمل کند. اگر هسته با بارگذاری خودکار ماژول پیکربندی شده باشد، اگر ماژول مناسب برای آن جدول وجود نداشته باشد، تلاش خواهد شد.

جداول به شرح زیر است:فیلتر :این جدول پیش فرض است (اگر گزینه -t وجود نداشته باشد). این شامل زنجیره های داخلی INPUT (برای بسته های مقصد به سوکت های محلی)، FORWARD (برای بسته هایی که از طریق جعبه هدایت می شوند) و OUTPUT (برای بسته های محلی تولید شده).nat :هنگامی که با بسته ای که یک اتصال جدید ایجاد می کند، مواجه می شود، این جدول مورد بررسی قرار می گیرد. این شامل سه داخلی است: PREROUTING (برای تغییر بسته‌ها به محض ورود)، OUTPUT (برای تغییر بسته‌های تولید شده محلی قبل از مسیریابی)، و POSTROUTING (برای تغییر بسته‌ها در زمانی که در شرف خروج هستند).مانگل :این جدول برای تغییر تخصصی بسته ها استفاده می شود. تا قبل از کرنل ۲.۴.۱۷ دو زنجیره داخلی داشت: PREROUTING (برای تغییر بسته‌های ورودی قبل از مسیریابی) و OUTPUT (برای تغییر بسته‌های تولید شده محلی قبل از مسیریابی). از هسته ۲.۴.۱۸، سه زنجیره داخلی دیگر نیز پشتیبانی می‌شوند: INPUT (برای بسته‌هایی که به داخل جعبه وارد می‌شوند)، FORWARD (برای تغییر بسته‌هایی که از طریق جعبه هدایت می‌شوند) و POSTROUTING (برای تغییر بسته‌ها در حالی که قرار است بسته شوند). برو بیرون).خام :این جدول عمدتاً برای پیکربندی معافیت های ردیابی اتصال در ترکیب با هدف NOTRACK استفاده می شود. در قلاب های فیلتر شبکه با اولویت بالاتر ثبت می شود و بنابراین قبل از ip_conntrack یا هر جدول IP دیگر فراخوانی می شود. این زنجیره های داخلی زیر را فراهم می کند: PREROUTING (برای بسته هایی که از طریق هر رابط شبکه می رسند) OUTPUT (برای بسته های تولید شده توسط فرآیندهای محلی)

گزینه ها

گزینه هایی که توسط iptables شناسایی می شوند را می توان به چند گروه مختلف تقسیم کرد.

دستوراتاین گزینه ها عمل خاصی را که باید انجام شود را مشخص می کند. فقط یکی از آنها را می توان در خط فرمان مشخص کرد مگر اینکه در زیر مشخص شده باشد. برای تمام نسخه های طولانی نام دستورات و گزینه ها، باید فقط از حروف کافی استفاده کنید تا اطمینان حاصل شود که iptables می تواند آن را از سایر گزینه ها متمایز کند.-A، –Apend chain rule-specificationیک یا چند قانون را به انتهای زنجیره انتخاب شده اضافه کنید. هنگامی که نام مبدأ و/یا مقصد به بیش از یک آدرس مشخص می‌شود، یک قانون برای هر ترکیب آدرس ممکن اضافه می‌شود.-D، –حذف قاعده-مشخصات زنجیره ای-D، –حذف زنجیر رولنومیک یا چند قانون را از زنجیره انتخاب شده حذف کنید. دو نسخه از این دستور وجود دارد: قانون را می توان به عنوان یک عدد در زنجیره (از ۱ برای قانون اول شروع می شود) یا یک قانون برای مطابقت مشخص کرد.-I، –insert chain [ rulenum ] rule-specificationیک یا چند قانون را به عنوان شماره قانون در زنجیره انتخاب شده وارد کنید. بنابراین، اگر عدد قانون ۱ باشد، قانون یا قوانین در سر زنجیره درج می شود. اگر شماره قاعده ای مشخص نشده باشد، این نیز پیش فرض است.-R، -جایگزینی قاعده-مشخصات حاکم بر زنجیرهیک قانون را در زنجیره انتخاب شده جایگزین کنید. اگر نام مبدأ و/یا مقصد به چندین آدرس مشخص شود، دستور ناموفق خواهد بود. قوانین از ۱ شماره گذاری می شوند.-L، –list [ زنجیره ]تمام قوانین موجود در زنجیره انتخاب شده را فهرست کنید. اگر هیچ زنجیره ای انتخاب نشده باشد، همه زنجیره ها لیست می شوند. مانند هر دستور دیگر iptables، برای جدول مشخص شده اعمال می شود (فیلتر پیش فرض است)، بنابراین قوانین NAT توسط فهرست می شوند.

iptables -t nat -n -L

لطفاً توجه داشته باشید که اغلب با گزینه -n استفاده می شود تا از جستجوهای طولانی معکوس DNS جلوگیری شود. قانونی است که گزینه -Z (صفر) را نیز مشخص کنید، در این صورت زنجیره (ها) به صورت اتمی لیست شده و صفر می شود. خروجی دقیق تحت تأثیر سایر آرگومان های ارائه شده قرار می گیرد. قوانین دقیق تا زمانی که استفاده نکنید سرکوب می شوند

iptables -L -v

-F، — فلاش [ زنجیره ]زنجیر انتخابی را بشویید (همه زنجیرهای جدول اگر هیچ کدام داده نشده باشد). این معادل حذف یک به یک همه قوانین است.-Z، — صفر [ زنجیره ]شمارشگر بسته و بایت را در تمام زنجیره ها صفر کنید. قانونی است که گزینه -L، –list (list) را نیز مشخص کنید تا شمارنده ها را بلافاصله قبل از پاک شدن ببینید. (بالا را ببین.)-N ، –زنجیره جدیدیک زنجیره جدید تعریف شده توسط کاربر با نام داده شده ایجاد کنید. در حال حاضر نباید هدفی از آن نام وجود داشته باشد.-X، –حذف زنجیره [ زنجیره ]زنجیره اختیاری تعریف شده توسط کاربر را حذف کنید. نباید هیچ اشاره ای به زنجیره وجود داشته باشد. در صورت وجود، باید قبل از حذف زنجیره، قوانین ارجاع را حذف یا جایگزین کنید. زنجیر باید خالی باشد، یعنی حاوی هیچ قانون نباشد. اگر هیچ آرگومانی داده نشود، تلاش می‌کند تا تمام زنجیره‌های ساخته نشده در جدول را حذف کند.-P، — هدف زنجیره سیاستخط مشی را برای زنجیره روی هدف داده شده تنظیم کنید. برای اهداف قانونی به بخش اهداف مراجعه کنید. فقط زنجیره های داخلی (غیر تعریف شده توسط کاربر) می توانند خط مشی داشته باشند و نه زنجیره های داخلی و نه زنجیره های تعریف شده توسط کاربر نمی توانند اهداف خط مشی باشند.-E، –تغییر نام-زنجیره قدیمی-زنجیره جدید-زنجیرهنام زنجیره مشخص شده توسط کاربر را به نام ارائه شده توسط کاربر تغییر نام دهید. این لوازم آرایشی است و هیچ تاثیری در ساختار میز ندارد.-h

کمک. یک توضیح (در حال حاضر بسیار مختصر) از نحو دستور بدهید.

مولفه هایپارامترهای زیر یک مشخصه قانون را تشکیل می دهند (همانطور که در دستورات افزودن، حذف، درج، جایگزینی و الحاق استفاده می شود).پروتکل -p، –protocol [!]پروتکل قانون یا بسته ای که باید بررسی شود. پروتکل مشخص شده می تواند یکی از tcp ، udp ، icmp ، یا همه باشد، یا می تواند یک مقدار عددی باشد که یکی از این پروتکل ها یا پروتکل دیگری را نشان می دهد. نام پروتکل از /etc/protocols نیز مجاز است. آ “!” آرگومان قبل از اینکه پروتکل تست را معکوس کند. عدد صفر معادل همه است. Protocol all با همه پروتکل ها مطابقت دارد و زمانی که این گزینه حذف شود به عنوان پیش فرض در نظر گرفته می شود.-s، –source [!] آدرس [/ mask ]مشخصات منبع آدرس می تواند یک نام شبکه، یک نام میزبان (لطفاً توجه داشته باشید که تعیین هر نامی که باید با یک پرس و جو از راه دور مانند DNS حل شود ایده بسیار بدی است)، یک آدرس IP شبکه (با ماسک /) یا یک آدرس IP ساده باشد. ماسک می تواند یک ماسک شبکه یا یک عدد ساده باشد که تعداد ۱ ها را در سمت چپ ماسک شبکه مشخص می کند. بنابراین، ماسک ۲۴ معادل ۲۵۵.۲۵۵.۲۵۵.۰ است. آ “!” آرگومان قبل از مشخصات آدرس، مفهوم آدرس را معکوس می کند. پرچم –src نام مستعار این گزینه است.-d، –مقصد [!] آدرس [/ mask ]مشخصات مقصد. توضیحات پرچم -s (منبع) را برای شرح دقیق نحو ببینید. پرچم –dst نام مستعار این گزینه است.-j، –پرش هدفاین هدف قاعده را مشخص می کند. به عنوان مثال، اگر بسته با آن مطابقت داشت، چه باید کرد. هدف می تواند یک زنجیره تعریف شده توسط کاربر (غیر از آنچه این قانون در آن است)، یکی از اهداف داخلی خاص که سرنوشت بسته را فوراً تعیین می کند، یا یک برنامه افزودنی (به EXTENSIONS زیر مراجعه کنید). اگر این گزینه در یک قانون حذف شود (و -g استفاده نشود)، تطبیق قاعده تاثیری بر سرنوشت بسته نخواهد داشت، اما شمارنده‌های روی قانون افزایش می‌یابند.-g، –goto زنجیرهاین مشخص می کند که پردازش باید در یک زنجیره مشخص شده توسط کاربر ادامه یابد. برخلاف گزینه –jump، بازگشت به پردازش در این زنجیره ادامه نمی‌دهد، بلکه در زنجیره‌ای که ما را از طریق –jump فراخوانی می‌کند، ادامه می‌دهد.-i، –in-interface [!] نامنام رابطی که از طریق آن یک بسته دریافت شده است (فقط برای بسته هایی که وارد زنجیره های INPUT ، FORWARD و PREROUTING می شوند). وقتی که “!” آرگومان قبل از نام رابط استفاده می شود، حس معکوس است. اگر نام رابط به “+” ختم شود، هر رابطی که با این نام شروع شود مطابقت دارد. اگر این گزینه حذف شود، هر نام رابط مطابقت دارد.-o، –out-interface [!] نامنام رابطی که قرار است بسته از طریق آن ارسال شود (برای بسته هایی که وارد زنجیره های FORWARD ، OUTPUT و POSTROUTING می شوند). وقتی که “!” آرگومان قبل از نام رابط استفاده می شود، حس معکوس است. اگر نام رابط به “+” ختم شود، هر رابطی که با این نام شروع شود مطابقت دارد. اگر این گزینه حذف شود، هر نام رابط مطابقت دارد.[!] -f، –قطعهاین بدان معناست که این قانون فقط به قطعات دوم و بعدی بسته های تکه تکه شده اشاره دارد. از آنجایی که هیچ راهی برای گفتن پورت های مبدا یا مقصد چنین بسته ای (یا نوع ICMP) وجود ندارد، چنین بسته ای با قوانینی که آنها را مشخص می کند مطابقت نخواهد داشت. وقتی که “!” آرگومان مقدم بر پرچم “-f” است، این قانون فقط با قطعات سر یا بسته های تکه تکه نشده مطابقت دارد.-c، –set-counters PKTS BYTESاین به مدیر امکان می‌دهد تا شمارنده‌های بسته و بایت یک قانون (در طول عملیات INSERT، APPEND، REPLACE ) را مقداردهی اولیه کند.

گزینه های دیگرگزینه های اضافی زیر را می توان مشخص کرد:-v، — پرحرفخروجی پرمخاطب این گزینه باعث می شود دستور لیست نام رابط، گزینه های قانون (در صورت وجود) و ماسک های TOS را نشان دهد. شمارنده های بسته و بایت نیز با پسوند “K”، “M” یا “G” به ترتیب برای ۱۰۰۰، ۱۰۰۰۰۰۰ و ۱۰۰۰۰۰۰۰۰۰ ضرب کننده فهرست شده اند (اما برای تغییر این مورد، پرچم -x را ببینید). برای الحاق، درج، حذف و جایگزینی، این باعث می شود اطلاعات دقیق در مورد قانون یا قوانین چاپ شود.-n، –عددیخروجی عددی آدرس های IP و شماره پورت ها به صورت عددی چاپ می شوند. به طور پیش فرض، برنامه سعی می کند آنها را به عنوان نام میزبان، نام شبکه یا سرویس (در صورت لزوم) نمایش دهد.-x، –دقیقاعداد را بسط دهید. مقدار دقیق شمارشگر بسته و بایت را به جای فقط عدد گرد شده در K (چند ۱۰۰۰) M (چند ۱۰۰۰K) یا G (چند ۱۰۰۰M) نمایش دهید. این گزینه فقط مربوط به دستور -L است.–خط-اعدادهنگام فهرست کردن قوانین، شماره خطوط را به ابتدای هر قانون اضافه کنید، مطابق با موقعیت آن قانون در زنجیره.–modprobe=فرمانهنگام اضافه کردن یا درج قوانین به یک زنجیره، از دستور برای بارگذاری هر ماژول ضروری (هدف، پسوندهای مطابقت و غیره) استفاده کنید.

برنامه های افزودنی مطابقت

iptables می تواند از ماژول های تطبیق بسته توسعه یافته استفاده کند. اینها به دو صورت بارگذاری می شوند: به طور ضمنی، زمانی که -p یا پروتکل — مشخص شده است، یا با گزینه های -m یا –match ، به دنبال آن نام ماژول منطبق. پس از این موارد، بسته به ماژول خاص، گزینه های مختلف خط فرمان اضافی در دسترس می شوند. شما می توانید چندین ماژول تطبیق توسعه یافته را در یک خط مشخص کنید، و می توانید از گزینه های -h یا –help پس از مشخص شدن ماژول برای دریافت کمک خاص آن ماژول استفاده کنید.

موارد زیر در بسته پایه گنجانده شده است و بیشتر آنها می توانند قبل از یک برای وارونه کردن حس تطابق

حسابترافیک حساب برای همه میزبان ها در شبکه / نقاب شبکه تعریف شده.

امکانات:

– آمار طولانی (یک شمارنده در هر پروتکل TCP/UDP/IMCP/دیگر) و آمار کوتاه

– یک قانون iptables برای همه هاست ها در شبکه/netmask

– بارگیری/ذخیره شمارنده ها (با خواندن/نوشتن در ورودی های procfs)–aaddr network/netmaskشبکه/نقاب شبکه را تعریف می کند که برای آن آمار می سازد.–aname نامنام لیستی را که در آن آمار نگهداری می شود، تعریف می کند. اگر خیر مشخص شده باشد از DEFAULT استفاده خواهد شد.–کوتاهجدول فقط آمارهای کوتاه را جمع آوری می کند (فقط تعداد کل شمارنده ها بدون تقسیم آن به پروتکل ها).مثال استفاده:

ترافیک حساب برای/به شبکه ۱۹۲.۱۶۸.۰.۰/۲۴ در جدول mynetwork:

# iptables -یک حساب FORWARD -m –aname mynetwork –aaddr 192.168.0.0/24

ترافیک حساب برای/به سرور WWW برای شبکه ۱۹۲.۱۶۸.۰.۰/۲۴ در جدول mywwwserver:

# iptables -A INPUT -p tcp –dport 80 -m account –aname mywwwserver –aaddr 192.168.0.0/24 –short

# iptables -A OUTPUT -p tcp –sport 80 -m account –aname mywwwserver –aaddr 192.168.0.0/24 –short

شمارنده ها را بخوانید:

# cat /proc/net/ipt_account/mynetwork # cat /proc/net/ipt_account/mywwwserver

تنظیم شمارنده ها:

# echo “ip = 192.168.0.1 packets_src = 0” > /proc/net/ipt_account/mywwserver

صفحه وب: http://www.barbara.eu.org/~quaker/ipt_account/

adrtypeاین ماژول بسته ها را بر اساس نوع آدرس آنها مطابقت می دهد. انواع آدرس در پشته شبکه هسته استفاده می شود و آدرس ها را در گروه های مختلف دسته بندی می کند. تعریف دقیق آن گروه به پروتکل لایه سه خاص بستگی دارد.انواع آدرس زیر ممکن است:UNSPEC

یک آدرس نامشخص (یعنی ۰.۰.۰.۰) UNICAST یک آدرس unicast محلی یک آدرس محلی BROADCAST یک آدرس پخش ANYCAST یک بسته anycast MULTICAST یک آدرس چندپخشی سیاه چاله یک آدرس سیاهچاله غیرقابل دسترس یک آدرس غیرقابل دسترسی ممنوع کردن یک آدرس ممنوع NOLATHROW FIXME FIXME FIXMEنوع –srcاگر آدرس منبع از نوع معین باشد مطابقت داردنوع –dstاگر آدرس مقصد از نوع معین باشد مطابقت دارد

آهاین ماژول با SPI ها در هدر Authentication بسته های IPsec مطابقت دارد.–ahspi [!] spi [: spi ]

سطح کودکاین یک ماژول تجربی است. با این که آیا بسته بخشی از یک اتصال اصلی است یا یکی از فرزندان آن (یا نوه ها و غیره) مطابقت دارد. به عنوان مثال، بیشتر بسته ها سطح ۰ هستند. انتقال داده FTP سطح ۱ است.سطح –childlevel [!]

اظهار نظربه شما امکان می دهد نظرات (حداکثر ۲۵۶ کاراکتر) را به هر قانون اضافه کنید.–نظر دادنمثال:نظر iptables -A INPUT -s 192.168.0.0/16 -m – نظر “یک بلوک IP خصوصی”

وضعیتاگر یک نام فایل /proc خاص ‘۰’ یا ‘۱’ باشد، این منطبق است.–condition [!] نام فایلمطابق با مقدار بولی ذخیره شده در فایل /proc/net/ipt_condition/filename

connbytesبا تعداد بایت ها یا بسته هایی که یک اتصال (یا یکی از دو جریان تشکیل دهنده اتصال) تاکنون منتقل شده است یا با میانگین بایت در هر بسته مطابقت دهید.

شمارنده ها ۶۴ بیتی هستند و بنابراین انتظار نمی رود که سرریز شوند 😉

کاربرد اصلی شناسایی دانلودهای طولانی مدت و علامت گذاری آنها به عنوان برنامه ریزی با استفاده از باند اولویت پایین تر در کنترل ترافیک است.

بایت های منتقل شده در هر اتصال را نیز می توان از طریق /proc/net/ip_conntrack مشاهده کرد و از طریق ctnetlink به آن دسترسی داشت.[ –connbytes از : [ تا ]بسته ها را از اتصالی که بسته ها/بایت ها/میانگین اندازه بسته آن بیشتر از FROM و کمتر از TO بایت/بسته است، مطابقت دهید. اگر TO حذف شود، فقط بررسی FROM انجام می شود. “!” برای تطبیق بسته هایی که در محدوده قرار نمی گیرند استفاده می شود.–connbytes-dir [ اصلی | پاسخ | هر دو ]کدام بسته ها را در نظر بگیرید–connbytes-mode [ بسته ها | بایت | avgpkt ]آیا باید مقدار بسته‌ها، تعداد بایت‌های منتقل شده یا اندازه متوسط ​​(بر حسب بایت) همه بسته‌های دریافتی تا کنون بررسی شود. توجه داشته باشید که وقتی “دو” همراه با “avgpkt” استفاده می شود، و داده ها (عمدتا) فقط در یک جهت (مثلا HTTP) حرکت می کنند، میانگین اندازه بسته تقریباً نصف بسته های داده واقعی خواهد بود.مثال:iptables .. -m connbytes –connbytes 10000:100000 –connbytes-dir هر دو –connbytes-mode bytes …

محدود کردنبه شما امکان می دهد تعداد اتصالات TCP موازی را به یک سرور در هر آدرس IP مشتری (یا بلوک آدرس) محدود کنید.[ –connlimit-above nاگر تعداد اتصالات tcp موجود (نه) بالاتر از n باشد مطابقت دارند–connlimit-mask بیتگروه میزبان با استفاده از ماسکمثال ها:# اجازه ۲ اتصال تلنت برای هر میزبان مشتریiptables -p tcp –syn –dport 23 -m connlimit –connlimit-bove 2 -j REJECT# همچنین می توانید برعکس هم مطابقت دهید:iptables -p tcp –syn –dport 23 -m connlimit ! –connlimit-بالای ۲ -j ACCEPT# تعداد درخواست‌های http موازی را به ۱۶ در هر شبکه با اندازه کلاس C محدود کنید (ماسک شبکه ۲۴ بیتی)iptables -p tcp –syn –dport 80 -m connlimit –connlimit-بالای ۱۶ –connlimit-mask 24 -j REJECT

connmarkاین ماژول با فیلد علامت فیلتر شبکه مرتبط با یک اتصال مطابقت دارد (که می تواند با استفاده از هدف CONNMARK در زیر تنظیم شود).— ارزش علامت گذاری[/mask]بسته ها را در ارتباط با مقدار علامت داده شده مطابقت می دهد (اگر یک ماسک مشخص شده باشد، به طور منطقی با علامت قبل از مقایسه AND می شود).

قرارداداین ماژول با نرخ انتقال فعلی در یک اتصال مطابقت دارد.–connrate [!] [از]:[به]با نرخ انتقال اتصال فعلی که در بایت‌های «از» و «به» در ثانیه است مطابقت دهید. وقتی که “!” آرگومان قبل از محدوده استفاده می شود، حس تطابق معکوس است.

کنتراکاین ماژول، هنگامی که با ردیابی اتصال ترکیب می شود، امکان دسترسی به اطلاعات ردیابی اتصال بیشتری را نسبت به مطابقت “وضعیت” فراهم می کند. (این ماژول فقط در صورتی وجود دارد که iptables تحت هسته ای که از این ویژگی پشتیبانی می کند کامپایل شده باشد)حالت –ctstateجایی که state فهرستی از حالت‌های اتصال جدا شده با کاما است که باید مطابقت داشته باشند. حالت های احتمالی INVALID هستند به این معنی که بسته با هیچ اتصال شناخته شده ای مرتبط نیست، ESTABLISHED به این معنی که بسته با اتصالی مرتبط است که بسته ها را در هر دو جهت دیده است، NEW به این معنی که بسته یک اتصال جدید را شروع کرده است، یا به طور دیگری با یک اتصال مرتبط است. که بسته ها را در هر دو جهت ندیده است، و RELATED به این معنی است که بسته در حال شروع یک اتصال جدید است، اما با یک اتصال موجود، مانند انتقال داده FTP، یا یک خطای ICMP مرتبط است. SNAT یک حالت مجازی، در صورتی که آدرس منبع اصلی با مقصد پاسخ متفاوت باشد مطابقت دارد. DNATحالت مجازی، مطابق با اگر مقصد اصلی با منبع پاسخ متفاوت باشد.–ctproto protoپروتکل برای مطابقت (بر اساس شماره یا نام)–ctorigsrc [!] آدرس[/mask]مطابق با آدرس منبع اصلی–ctorigdst [!] آدرس[/mask]مطابق با آدرس مقصد اصلی–ctreplsrc [!] آدرس[/mask]مطابقت با آدرس منبع پاسخ–ctrepldst [!] آدرس [/ mask ]مطابقت با آدرس مقصد پاسخ–ctstatus [هیچ|انتظار می رود|SEEN_REPLY|مطمئن][،…]مطابقت با ایالت های کنتراک داخلی–ctexpire time[:time]مطابقت با طول عمر باقیمانده در ثانیه با مقدار داده شده یا محدوده مقادیر (شامل)

dccp–source-port , –sport [ پورت [ پورت ]–destination-port , –dport [ پورت [ پورت ]–dccp-types [ ماسکزمانی که نوع بسته DCCP یکی از «ماسک» است مطابقت دهید. ‘mask’ لیستی از انواع بسته ها است که با کاما از هم جدا شده اند. انواع بسته ها عبارتند از: درخواست پاسخ داده ACK DATAACK CLOSEREQ بستن بازنشانی همگام سازی همگام سازی نامعتبر است.–dccp-option [ شمارهدر صورت تنظیم گزینه DCP مطابقت دهید.

dscpاین ماژول با فیلد DSCP 6 بیتی در فیلد TOS در هدر IP مطابقت دارد. DSCP جایگزین TOS در IETF شده است.مقدار –dscpبا یک مقدار عددی (اعشاری یا هگزا) [۰-۶۳] مطابقت دهید.–dscp-class کلاس DiffServبا کلاس DiffServ مطابقت دهید. این مقدار ممکن است هر یک از کلاس های BE، EF، AFxx یا CSx باشد. سپس به مقدار عددی آن تبدیل می شود.

dstlimitاین ماژول به شما اجازه می دهد تا نرخ بسته در ثانیه (pps) را در یک IP مقصد یا در هر پایه پورت مقصد محدود کنید. برخلاف تطابق “Limit”، هر ip مقصد / پورت مقصد محدودیت خاص خود را دارد.این ماژول منسوخ شده است و با “hashlimit” جایگزین شده است–dstlimit agحداکثر میانگین نرخ تطابق (بسته‌ها در هر ثانیه، مگر اینکه با /sec/minute/hour/day postfixes دنبال شود).حالت -dstlimit- modehashmode محدود کننده. آیا حد مشخص شده در هر dstip، dstip-dstport tuple، srcip-dstip tuple یا هر srcipdstip-dstport tuple است.–dstlimit- nameنام برای /proc/net/ipt_dstlimit/* ورودی فایل–dstlimit-burst burst ]تعداد بسته هایی که به صورت پشت سر هم مطابقت دارند. پیش فرض: ۵–dstlimit-htable-size size ]تعداد سطل ها در hashtable–dstlimit-htable-max max ]حداکثر تعداد ورودی در hashtable–dstlimit-htable-gcinterval interval ]فاصله بین دوره‌های جمع‌آوری زباله هشتبل (در میلی‌ثانیه). پیش فرض ۱۰۰۰ (۱ ثانیه) است.–dstlimit-htable-expire timeپس از چه زمانی، ورودی‌های غیرفعال از hashtable منقضی می‌شوند (در میلی‌ثانیه)؟ پیش فرض ۱۰۰۰۰ (۱۰ ثانیه) است.

ecnاین به شما امکان می دهد بیت های ECN هدر IPv4 و TCP را مطابقت دهید. ECN مکانیسم اعلان ازدحام صریح است که در RFC3168 مشخص شده است–ecn-tcp-cwrاگر بیت TCP ECN CWR (پنجره تراکم دریافت شده) تنظیم شده باشد، مطابقت دارد.–ecn-tcp-eceاگر بیت TCP ECN ECE (ECN Echo) تنظیم شده باشد، مطابقت دارد.–ecn-ip-ect شمارهاین با یک IPv4 ECT خاص (ECN-Capable Transport) مطابقت دارد. باید عددی بین ۰ تا ۳ مشخص کنید.

مخصوصااین ماژول با SPI ها در هدر ESP بسته های IPsec مطابقت دارد.–espspi [!] spi [: spi ]

درهماین ماژول با محدودیت نرخ بر اساس کنترل کننده منطق فازی [FLC] مطابقت دارد.– عدد با حد پایینحد پایین تر (بر حسب بسته در ثانیه) را مشخص می کند.— تعداد حد بالاییحد بالایی (بر حسب بسته در ثانیه) را مشخص می کند.

هش کردناین پچ یک تطابق جدید به نام ‘hashlimit’ اضافه می کند. ایده این است که چیزی شبیه به “Limit” داشته باشیم، اما یا در هر مقصد-ip یا هر (destip,destport) تاپل.

این به شما توانایی بیان را می دهد’۱۰۰۰ بسته در ثانیه برای هر میزبان در ۱۹۲.۱۶۸.۰.۰/۱۶′

‘۱۰۰ بسته در ثانیه برای هر سرویس ۱۹۲.۱۶۸.۱.۱’با یک قانون iptables.— نرخ هش محدودیتنرخی درست مانند مطابقت حد–hashlimit-burst numمقدار Burst، درست مانند تطابق حد–hashlimit-mode start | شروع-شروعمحدودیت در هر IP یا هر پورت–hashlimit-name fooنام ورودی /proc/net/ipt_hashlimit/foo–hashlimit-htable-size numتعداد سطل های جدول هش–hashlimit-htable-max numحداکثر ورودی در هش–hashlimit-htable-expire numپس از چند میلی ثانیه، ورودی های هش منقضی می شوند–hashlimit-htable-gcinterval numچند میلی ثانیه بین فواصل جمع آوری زباله

یاوراین ماژول بسته های مربوط به یک conntrack-helper خاص را مطابقت می دهد.– رشته کمکیبسته های مربوط به conntrack-helper مشخص شده را مطابقت می دهد.رشته می تواند “ftp” برای بسته های مربوط به جلسه ftp در پورت پیش فرض باشد. برای پورت های دیگر، -portnr را به مقدار اضافه کنید. “ftp-2121”.

قوانین مشابه برای سایر conntrack-helpers اعمال می شود.

icmpاگر “–protocol icmp” مشخص شده باشد، این برنامه افزودنی بارگیری می شود. گزینه زیر را ارائه می دهد:–icmp -type [!] typenameاین اجازه می دهد تا نوع ICMP را مشخص کنید، که می تواند یک نوع ICMP عددی یا یکی از نام های نوع ICMP نشان داده شده توسط فرمان باشد.

iptables -p icmp -h

iprangeاین در یک محدوده دلخواه از آدرس های IPv4 مطابقت دارد[!] –src-range ip-ipIP منبع را در محدوده مشخص شده مطابقت دهید.[!] –dst-range ip-ipIP مقصد را در محدوده مشخص شده مطابقت دهید.

ipv4optionsبا گزینه‌های هدر IPv4 مانند مسیریابی منبع، مسیر ثبت، مهر زمانی و هشدار روتر مطابقت دهید.–ssr

برای تطبیق بسته ها با مسیریابی منبع دقیق پرچم.

–lsrr

برای تطبیق بسته ها با پرچم مسیریابی منبع آزاد.–no-srrبرای تطبیق بسته های بدون پرچم برای مسیریابی منبع.[ –rrبرای تطبیق بسته ها با پرچم RR.[ –tsبرای تطبیق بسته ها با پرچم TS.[ –raبرای تطبیق بسته ها با گزینه router-alert.[ –any-optبرای تطبیق یک بسته با حداقل یک گزینه IP، یا بدون هیچ گزینه IP اگر ! انتخاب شده است.مثال ها:$ iptables -A ورودی -m ipv4options –rr -j DROPبسته هایی را با پرچم رکورد مسیر رها می کند.$ iptables -A ورودی -m ipv4options –ts -j DROPبسته های دارای پرچم زمان را رها می کند.

طولاین ماژول طول یک بسته را با یک مقدار خاص یا محدوده ای از مقادیر مطابقت می دهد.–length [!] طول [: طول ]

حداین ماژول با استفاده از فیلتر سطل توکن با نرخ محدود مطابقت دارد. قاعده ای که از این پسوند استفاده می کند تا زمانی که به این حد برسد مطابقت دارد (مگر اینکه از پرچم “!” استفاده شود. به عنوان مثال می توان از آن در ترکیب با هدف LOG برای ایجاد گزارش محدود استفاده کرد.– نرخ حدحداکثر میانگین نرخ تطابق: به عنوان یک عدد مشخص شده است، با پسوند اختیاری ‘/second’، ‘/minute’، ‘/hour’ یا ‘/day’. پیش فرض ۳/hour است.— تعداد حد انفجارحداکثر تعداد بسته های اولیه برای مطابقت: این تعداد هر بار که به محدودیت تعیین شده در بالا نرسیده باشد، تا این تعداد یک بار شارژ می شود. پیش فرض ۵ است.

مکآدرس –mac-source [!]آدرس مک منبع را مطابقت دهید. باید به شکل XX:XX:XX:XX:XX:XX باشد. توجه داشته باشید که این فقط برای بسته هایی که از یک دستگاه اترنت می آیند و وارد زنجیره های PREROUTING ، FORWARD یا INPUT می شوند، منطقی است.

علامتاین ماژول با فیلد علامت فیلتر شبکه مرتبط با یک بسته (که می تواند با استفاده از هدف MARK زیر تنظیم شود) مطابقت دارد.— ارزش علامت [/ mask ]بسته ها را با مقدار علامت بدون علامت داده شده مطابقت می دهد (اگر یک ماسک مشخص شده باشد، به طور منطقی قبل از مقایسه با ماسک AND می شود).

امپورتاین ماژول با مجموعه ای از پورت های مبدا یا مقصد مطابقت دارد. حداکثر ۱۵ پورت را می توان مشخص کرد. این فقط می تواند در رابطه با -p tcp یا -p udp استفاده شود.–source-ports پورت [، پورت [، پورت …]]اگر پورت منبع یکی از پورت های داده شده باشد مطابقت دهید. flag –sports نام مستعار مناسبی برای این گزینه است.–destination-ports port [, port [, port …]]اگر پورت مقصد یکی از پورت های داده شده باشد مطابقت دهید. flag –dports نام مستعار مناسبی برای این گزینه است.–پورت [، پورت [، پورت  ]]اگر هر دو پورت مبدا و مقصد با یکدیگر و با یکی از پورت های داده شده برابر باشند، مطابقت دهید.

چند پورتاین ماژول با مجموعه ای از پورت های مبدا یا مقصد مطابقت دارد. حداکثر ۱۵ پورت را می توان مشخص کرد. یک محدوده پورت (port:port) به عنوان دو پورت محاسبه می شود. این فقط می تواند در رابطه با -p tcp یا -p udp استفاده شود.–source-ports [!] پورت [، پورت [، port:port …]]اگر پورت منبع یکی از پورت های داده شده باشد مطابقت دهید. flag –sports نام مستعار مناسبی برای این گزینه است.–destination-ports [!] port [, port [, port:port …]]اگر پورت مقصد یکی از پورت های داده شده باشد مطابقت دهید. flag –dports نام مستعار مناسبی برای این گزینه است.–پورت [!] پورت [، پورت [، پورت:پورت …]]اگر پورت مبدا یا مقصد برابر با یکی از پورت های داده شده باشد، مطابقت دهید.

نهمیناین ماژول با هر بسته n’ام مطابقت دارد— هر ارزشهر بسته “ارزشی” را مطابقت دهید–شماره شمارنده ]از شماره شمارنده داخلی ‘num’ استفاده کنید. پیش فرض “۰” است.–شماره شروع ]شمارنده را در عدد ‘num’ به جای ‘۰’ راه اندازی کنید. بیشتر بین ‘۰’ و ‘value’-1.[ — شماره بسته ]مطابقت بر روی بسته ‘num’. اکثر آنها بین ‘۰’ و ‘value’-1 هستند.

osfایده تطبیق اثر انگشت سیستم عامل منفعل برای مدت طولانی وجود داشته است، اما چند هفته پیش به عنوان افزونه برای OpenBSD pf ایجاد شد. ایده اصلی در لیست پستی OpenBSD پنهان شد (با تشکر grange@open…) و سپس برای فیلتر شبکه لینوکس در قالب این کد پذیرفته شد.

جدول اثر انگشت اصلی توسط Michal Zalewski < lcamtuf@coredump.cx > ایجاد شده است.

این ماژول برخی از داده‌ها (WS، MSS، گزینه‌ها و ترتیب آن، ttl، df و موارد دیگر) را از اولین بسته SYN (در واقع از بسته‌هایی با مجموعه بیت SYN) با اثرانگشت سیستم‌عامل بارگذاری شده پویا مقایسه می‌کند.–log 1/0

در صورت وجود، OSF ژانرهای تعیین شده را حتی اگر با ژانر مورد نظر مطابقت نداشته باشد، ثبت می کند.۰ – ورود همه ورودی های تعیین شده، ۱ – فقط اولین.در syslog چیزی شبیه به این پیدا می کنید:ipt_osf: Windows [2000:SP3:Windows XP Pro SP1, 2000 SP3]: 11.22.33.55:4024 -> 11.22.33.44:139

ipt_osf: ناشناس: ۱۶۳۸۴:۱۰۶:۱:۴۸:۰۲۰۴۰۵B401010402 44.33.22.11:1239 -> 11.22.33.44:80–هوشمندانهدر صورت وجود، OSF از مقداری هوشمندی برای تعیین سیستم عامل راه دور استفاده می کند. OSF تنها در صورتی از TTL اولیه استفاده خواهد کرد که منبع اتصال در شبکه محلی ما باشد.–netlinkدر صورت وجود، OSF همه رویدادها را از طریق netlink NETLINK_NFLOG groupt 1 نیز ثبت خواهد کرد.رشته — ژانر [!]با اثرانگشت غیرفعال، ژانر سیستم عامل را مطابقت دهیدمثال:

#iptables -I INPUT -j ACCEPT -p tcp -m osf –ژانر لینوکس –log 1 –smart

توجه: -p tcp بدیهی است که مورد نیاز است زیرا مطابق با TCP است.

اثر انگشت را می توان از طریق فایل /proc/sys/net/ipv4/osf بارگیری کرد و خواند. با دستور زیر می توان تمام اثر انگشت ها را شستشو داد:echo -en FLUSH > /proc/sys/net/ipv4/osfفقط یک اثر انگشت در هر باز/نوشتن/بستن.

اثر انگشت را می توان از http://www.openbsd.org/cgi-bin/cvsweb/src/etc/pf.os دانلود کرد

مالکاین ماژول تلاش می کند تا ویژگی های مختلف سازنده بسته را برای بسته های محلی تولید شده مطابقت دهد. این فقط در زنجیره OUTPUT معتبر است، و حتی برخی از بسته ها (مانند پاسخ های پینگ ICMP) ممکن است مالک نداشته باشند و از این رو هرگز با هم مطابقت ندارند.کاربران –uid-ownerدر صورتی مطابقت دارد که بسته توسط فرآیندی با شناسه کاربر مؤثر ایجاد شده باشد.–gid-owner groupidدر صورتی مطابقت دارد که بسته توسط فرآیندی با شناسه گروه موثر ایجاد شده باشد.–pid-مالک processidاگر بسته توسط فرآیندی با شناسه فرآیند داده شده ایجاد شده باشد، مطابقت دارد.–sid-مالک sessionidدر صورتی مطابقت دارد که بسته توسط فرآیندی در گروه جلسه داده شده ایجاد شده باشد.-cmd- نام مالکاگر بسته توسط فرآیندی با نام دستور داده شده ایجاد شده باشد مطابقت دارد. (این گزینه فقط در صورتی وجود دارد که iptables تحت هسته ای که از این ویژگی پشتیبانی می کند کامپایل شده باشد)توجه: تطبیق pid، sid و دستور در SMP شکسته شده است

physdevاین ماژول در دستگاه های ورودی و خروجی پورت پل که به دستگاه پل برده شده اند مطابقت دارد. این ماژول بخشی از زیرساختی است که یک فایروال IP پل زدن شفاف را فعال می کند و فقط برای نسخه های هسته بالای نسخه ۲.۵.۴۴ مفید است.–physdev-in [!] نامنام پورت پل که از طریق آن یک بسته دریافت می شود (فقط برای بسته هایی که وارد زنجیره های INPUT ، FORWARD و PREROUTING می شوند). اگر نام رابط به “+” ختم شود، هر رابطی که با این نام شروع شود مطابقت دارد. اگر بسته از طریق دستگاه Bridge وارد نشده باشد، این بسته با این گزینه مطابقت نخواهد داشت، مگر اینکه ‘!’ استفاده می شود.–physdev-out [!] نامنام پورت پل که قرار است بسته از طریق آن ارسال شود (برای بسته هایی که وارد زنجیره های FORWARD ، OUTPUT و POSTROUTING می شوند). اگر نام رابط به “+” ختم شود، هر رابطی که با این نام شروع شود مطابقت دارد. توجه داشته باشید که در زنجیره‌های خروجی nat و mangle نمی‌توان با پورت خروجی پل مطابقت داشت، اما در زنجیره خروجی فیلتر می‌توان آن را مطابقت داد. اگر بسته توسط یک دستگاه پل خارج نشود یا هنوز مشخص نیست که دستگاه خروجی چیست، بسته با این گزینه مطابقت نخواهد داشت، مگر اینکه[!] –physdev-is-inاگر بسته از طریق یک رابط پل وارد شده باشد مطابقت دارد.[!] –physdev-is-outاگر بسته از طریق یک رابط پل خارج شود مطابقت دارد.[!] –physdev-is-bridgedاگر بسته در حال پل زدن باشد و بنابراین مسیریابی نشده باشد، مطابقت دارد. این فقط در زنجیره های FORWARD و POSTROUTING مفید است.

pkttypeاین ماژول با نوع بسته لایه پیوند مطابقت دارد.–pkt-type [unicast|پخش|چندپست]

خط مشیاین ماژول با خط مشی مورد استفاده IPsec برای مدیریت یک بسته مطابقت دارد.–dir in|outبرای انتخاب مطابقت با خط مشی مورد استفاده برای کپسولاسیون یا خط مشی مورد استفاده برای کپسولاسیون استفاده می شود. in در زنجیره های PREROUTING، INPUT و FORWARD معتبر است ، out در زنجیره های POSTROUTING، OUTPUT و FORWARD معتبر است .— Half None |ipsecاگر بسته تحت پردازش IPsec باشد مطابقت دارد.–سخت گیرانهانتخاب می کند که آیا با خط مشی دقیق مطابقت داشته باشد یا مطابقت داشته باشد اگر هر یک از قوانین خط مشی با خط مشی داده شده مطابقت داشته باشد.– شناسه ثبت ناممنطبق با قاعده خط مشی. reqid را می توان با setkey (8) با استفاده از unique:id به عنوان سطح مشخص کرد.–spi spiبا SPI SA مطابقت دارد.–proto ah|esp|ipcompبا پروتکل کپسوله سازی مطابقت دارد.–mode تونل|حمل و نقلبا حالت کپسوله سازی مطابقت دارد.–tunnel-src addr[/mask]با آدرس نقطه پایانی منبع یک حالت تونل SA مطابقت دارد. فقط با تونل حالت – معتبر است.–tunnel-dst addr[/mask]با آدرس نقطه پایانی مقصد یک حالت تونل SA مطابقت دارد. فقط با تونل حالت – معتبر است.–بعد

عنصر بعدی را در مشخصات سیاست شروع کنید. فقط با –strict قابل استفاده است

psdسعی کنید اسکن پورت TCP و UDP را شناسایی کنید. این تطابق از Scanlogd Solar Designer مشتق شده است.–psd-weight-threshold thresholdوزن کل آخرین بسته‌های TCP/UDP با پورت‌های مقصد مختلف که از یک میزبان می‌آیند تا به عنوان دنباله اسکن پورت در نظر گرفته شوند.–psd-تاخیر آستانه تاخیرتأخیر (در صدم ثانیه) برای بسته‌هایی که درگاه‌های مقصد متفاوتی از یک میزبان می‌آیند تا به عنوان دنباله اسکن پورت ممکن در نظر گرفته شوند.–psd-lo-ports- وزنوزن بسته با پورت مقصد ممتاز (<=1024).–psd-hi-ports-weight weightوزن بسته با پورت مقصد غیرمجاز.

سهمیه، سهمسهمیه های شبکه را با کاهش یک بایت شمارنده با هر بسته پیاده سازی می کند.— سهمیه بایتسهمیه بر حسب بایتاشکالات شناخته شده: این در سیستم های SMP کار نمی کند.

تصادفیاین ماژول به طور تصادفی درصد معینی از تمام بسته ها را مطابقت می دهد.— درصد متوسطبا درصد داده شده مطابقت دارد. اگر حذف شود، احتمال ۵۰ درصد تعیین می شود.

قلمرواین با قلمرو مسیریابی مطابقت دارد. قلمروهای مسیریابی در تنظیمات مسیریابی پیچیده شامل پروتکل های مسیریابی پویا مانند BGP استفاده می شود.-قلمرو [!] مقدار[/mask]منطبق با یک شماره قلمرو داده شده (و به صورت اختیاری ماسک).

اخیربه شما امکان می دهد لیستی از آدرس های IP را به صورت پویا ایجاد کنید و سپس به روش های مختلف با آن لیست مطابقت دهید.

برای مثال، می‌توانید از افرادی که تلاش می‌کنند به پورت ۱۳۹ در فایروال خود متصل شوند، یک لیست «badguy» ایجاد کنید و سپس تمام بسته‌های آینده را بدون در نظر گرفتن آنها حذف کنید.–نام ناملیستی را برای استفاده از دستورات مشخص کنید. اگر نامی داده نشود، از «پیش‌فرض» استفاده می‌شود.[ — مجموعهبا این کار آدرس منبع بسته به لیست اضافه می شود. اگر آدرس منبع از قبل در لیست باشد، این ورودی موجود را به روز می کند. این همیشه موفقیت را باز خواهد گرداند (یا شکست اگر ‘!’ به آن منتقل شود).[ –rcheckبررسی کنید که آیا آدرس منبع بسته در حال حاضر در لیست است یا خیر.[ ] — به روز رسانیمانند –rcheck ، با این تفاوت که در صورت مطابقت، مهر زمانی “آخرین بازدید” را به روز می کند.[ — حذفبررسی کنید که آیا آدرس منبع بسته در حال حاضر در لیست است یا خیر و آیا این آدرس از لیست حذف می شود و قانون به درستی باز می گردد. اگر آدرس پیدا نشد، false برگردانده می شود.[ ] — ثانیه ثانیهاین گزینه باید همراه با یکی از –rcheck یا –update استفاده شود. هنگامی که استفاده می شود، این تطابق را محدود می کند تا زمانی اتفاق بیفتد که آدرس در لیست باشد و در آخرین تعداد ثانیه مشخص شده دیده شود.[ ] — تعداد بازدیدهااین گزینه باید همراه با یکی از –rcheck یا –update استفاده شود. هنگامی که استفاده می شود، این تطابق را محدود می کند تا زمانی اتفاق بیفتد که آدرس در لیست باشد و بسته ها بزرگتر یا مساوی با مقدار داده شده دریافت شده باشند. این گزینه ممکن است همراه با — ثانیه برای ایجاد یک تطابق حتی محدودتر که نیاز به تعداد معینی بازدید در یک بازه زمانی خاص دارد استفاده شود.–rttl

این گزینه باید همراه با یکی از –rcheck یا –update استفاده شود. هنگامی که استفاده می شود، این تطابق را محدود می کند تا زمانی اتفاق بیفتد که آدرس در لیست باشد و TTL بسته فعلی با بسته ای که قانون –set را زده است مطابقت داشته باشد. این ممکن است در صورتی مفید باشد که با افرادی که آدرس منبع خود را جعل می کنند تا از طریق این ماژول با منع دسترسی دیگران به سایت شما با ارسال بسته های جعلی برای شما، به شما خدمات رسانی کنند.مثال ها:# iptables -A FORWARD -m اخیر –name badguy –rcheck –seconds 60 -j DROP

# iptables -A FORWARD -p tcp -i eth0 –dport 139 -m اخیر –name badguy –set -j DROPوب سایت رسمی ( http://snowman.net/projects/ipt_recent/ ) نیز نمونه هایی از استفاده دارد.

/proc/net/ipt_recent/* لیست های فعلی آدرس ها و اطلاعات مربوط به هر ورودی هر لیست هستند.

هر فایل در /proc/net/ipt_recent/ را می‌توان از آن خواند تا لیست فعلی را مشاهده کرد یا با استفاده از دستورات زیر دو تا را برای تغییر لیست نوشت:echo xx.xx.xx.xx > /proc/net/ipt_recent/DEFAULTبرای افزودن به لیست پیش فرضecho -xx.xx.xx.xx > /proc/net/ipt_recent/DEFAULTبرای حذف از لیست پیش فرضecho clear > /proc/net/ipt_recent/DEFAULTبرای خالی کردن لیست DEFAULT.خود ماژول پارامترها را می پذیرد، به طور پیش فرض نشان داده شده است:ip_list_tot= ۱۰۰تعداد آدرس های به خاطر سپرده شده در هر جدولip_pkt_list_tot= ۲۰تعداد بسته های به خاطر سپرده شده در هر آدرسip_list_hash_size= ۰اندازه جدول هش. 0 یعنی محاسبه آن بر اساس ip_list_tot، پیش فرض: ۵۱۲ip_list_perms= ۰۶۴۴مجوز برای فایل های /proc/net/ipt_recent/*اشکال زدایی = ۰برای دریافت بسیاری از اطلاعات رفع اشکال، روی ۱ تنظیم کنید

sctp–source-port , –sport [ پورت [ پورت ]–destination-port , –dport [ پورت [ پورت ]–chunk-types [ همه | هر | only chunktype [ flags ] […]حرف پرچم با حروف بزرگ نشان می دهد که اگر تنظیم شده باشد پرچم مطابقت دارد، در صورت تنظیم نشدن علامت کوچک نشان می دهد که مطابقت دارد.

انواع تکه: داده‌ها INIT INIT_ACK SACK HEARTBEAT HEARTBEAT_ACK ABORT SHUTDOWN SHUTDOWN_ACK خطا COOKIE_ECHO COOKIE_ACK ECN_ECNE ECN_CWR SHUTDOWN_COMPLETE ASCONF ASCONF

نوع تکه پرچم های موجود
DATA UBE ube
ABORT T t
SHUTDOWN_COMPLETE T t

(حروف کوچک به این معنی است که پرچم باید “خاموش” باشد، حروف بزرگ به معنای “روشن” است)مثال ها:

iptables -A INPUT -p sctp –dport 80 -j DROP

iptables -A INPUT -p sctp –chunk-types any DATA,INIT -j DROP

iptables -A INPUT -p sctp –chunk-تایپ هر DATA:Be -j ACCEPT

تنظیماین ماژول مجموعه‌های IP را که می‌توان با ipset (8) تعریف کرد، به کار می‌برد.-تنظیم پرچم مجموعه[,پرچم…]که در آن پرچم‌ها src و/یا dst هستند و نمی‌توانند بیش از شش عدد از آنها باشند. از این رو دستور

iptables -A FORWARD -m set --set test src,dst

بسته هایی را مطابقت می دهد که (بسته به نوع مجموعه) آدرس منبع یا شماره پورت بسته را می توان در مجموعه مشخص شده پیدا کرد. اگر یک اتصال متعلق به عنصر مجموعه mached وجود داشته باشد یا یک اتصال پیش‌فرض برای مجموعه داده شده وجود داشته باشد، این قانون تنها در صورتی با بسته مطابقت دارد که علاوه بر این (بسته به نوع مجموعه) آدرس مقصد یا شماره پورت بسته نیز باشد. با توجه به صحافی در مجموعه یافت می شود.

حالتاین ماژول هنگامی که با ردیابی اتصال ترکیب می شود، امکان دسترسی به وضعیت ردیابی اتصال را برای این بسته فراهم می کند.– ایالتجایی که state فهرستی از حالت‌های اتصال جدا شده با کاما است که باید مطابقت داشته باشند. حالت های احتمالی نامعتبر هستند به این معنی که بسته به دلایلی نمی تواند شناسایی شود که شامل تمام شدن حافظه و خطاهای ICMP است که با هیچ ارتباط شناخته شده ای مطابقت ندارد . جهت ها، NEW به این معنی که بسته یک اتصال جدید را شروع کرده است، یا با اتصالی مرتبط است که بسته ها را در هر دو جهت ندیده است، و RELATED به این معنی که بسته در حال شروع یک اتصال جدید است، اما با یک اتصال موجود مرتبط است، مانند یک انتقال داده FTP یا یک خطای ICMP.

رشتهاین ماژول ها با استفاده از برخی استراتژی تطبیق الگو، یک رشته معین را مطابقت می دهد. به یک هسته لینوکس >= 2.6.14 نیاز دارد.–الگو bm| kmpاستراتژی تطبیق الگو را انتخاب کنید. (bm = Boyer-Moore، kmp = Knuth-Pratt-Morris)–از افستافستی را تنظیم کنید که از آن شروع به جستجوی هر گونه تطبیق می کند. اگر تصویب نشود، پیش فرض ۰ است.— برای جبرانافستی را تنظیم کنید که از آن شروع به جستجوی هر گونه تطبیق می کند. اگر تصویب نشد، پیش‌فرض اندازه بسته است.–الگوی رشته ایبا الگوی داده شده مطابقت دارد. — الگوی رشته هگزا با الگوی داده شده در نماد هگز مطابقت دارد.

tcpاگر «–protocol tcp» مشخص شده باشد، این پسوندها بارگیری می شوند. گزینه های زیر را ارائه می دهد:–source-port [!] پورت [: port ]مشخصات پورت منبع یا محدوده پورت. این می تواند نام سرویس یا شماره پورت باشد. با استفاده از پورت فرمت : پورت ، یک محدوده فراگیر نیز می‌تواند مشخص شود . اگر اولین پورت حذف شود، “۰” در نظر گرفته می شود. اگر آخرین مورد حذف شود، “۶۵۵۳۵” فرض می شود. اگر پورت دوم بزرگتر باشد، پورت اول عوض می شود. flag –sport نام مستعار مناسبی برای این گزینه است.–destination-port [!] port [: port ]مشخصات پورت مقصد یا محدوده بندر. flag –dport نام مستعار مناسبی برای این گزینه است.–tcp-flags [!] mask compزمانی که پرچم های TCP همانطور که مشخص شده است مطابقت دهید. آرگومان اول پرچم هایی است که باید آنها را بررسی کنیم و به صورت لیست جدا شده با کاما نوشته می شود و آرگومان دوم یک لیست پرچم های جدا شده با کاما است که باید تنظیم شوند. پرچم ها عبارتند از: SYN ACK FIN RST URG PSH ALL NONE . از این رو دستور

iptables -A FORWARD -p tcp --tcp-flags SYN,ACK,FIN,RST SYN

بسته‌ها را فقط با مجموعه پرچم SYN مطابقت می‌دهد و پرچم‌های ACK، FIN و RST تنظیم نشده است.[!] — synبسته های TCP را فقط با مجموعه بیت SYN و پاک شدن بیت های ACK، RST و FIN مطابقت دهید. چنین بسته هایی برای درخواست شروع اتصال TCP استفاده می شود. به عنوان مثال، مسدود کردن چنین بسته هایی که در یک رابط وارد می شوند، از اتصالات TCP ورودی جلوگیری می کند، اما اتصالات TCP خروجی تحت تأثیر قرار نمی گیرند. معادل –tcp-flags SYN,RST,ACK,FIN SYN است. اگر “!” پرچم قبل از “–syn” است، حس گزینه معکوس است.شماره –tcp-option [!]در صورت تنظیم گزینه TCP مطابقت دهید.مقدار –mss [: value ]بسته های TCP SYN یا SYN/ACK را با مقدار (یا محدوده) مشخص شده MSS، که حداکثر اندازه بسته را برای آن اتصال کنترل می کند، مطابقت دهید.

tcpmssاین با فیلد TCP MSS (حداکثر اندازه بخش) هدر TCP مطابقت دارد. شما فقط می‌توانید از آن در بسته‌های TCP SYN یا SYN/ACK استفاده کنید، زیرا MSS فقط در هنگام دست دادن TCP در زمان راه‌اندازی اتصال مورد مذاکره قرار می‌گیرد.[!] –mss value[:value]”یک مقدار یا محدوده TCP MSS داده شده را مطابقت دهید.

زماندر صورتی که زمان/تاریخ رسیدن بسته در محدوده معینی باشد، مطابقت دارد. همه گزینه ها اختیاری هستند– مقدار زمان شروعفقط در صورتی مطابقت داشته باشید که بعد از “مقدار” باشد (شامل، قالب: HH:MM ؛ پیش‌فرض ۰۰:۰۰).– مقدار توقف زمانفقط در صورتی مطابقت داشته باشید که قبل از “مقدار” باشد (شامل، قالب: HH:MM ؛ پیش‌فرض ۲۳:۵۹).— لیست روزهافقط در صورتی مطابقت داشته باشید که امروز یکی از روزهای معین باشد. (قالب: دوشنبه، سه شنبه، چهارشنبه، پنجشنبه، جمعه، شنبه، یکشنبه؛ پیش فرض هر روز)–datest تاریخ شروعفقط در صورتی مطابقت داشته باشد که بعد از «تاریخ» باشد (شامل، قالب: YYYY[:MM[:DD[:hh[:mm[:ss]]]]]؛ ساعت، ساعت، شروع از ۰؛ پیش‌فرض تا ۱۹۷۰)– تاریخ توقففقط در صورتی مطابقت داشته باشید که قبل از “تاریخ” باشد (شامل، قالب: YYYY[:MM[:DD[:hh[:mm[:ss]]]]] ؛ ساعت، ساعت، شروع از ۰؛ پیش‌فرض تا ۲۰۳۷)

بهاین ماژول با ۸ بیت فیلد Type of Service در هدر IP مطابقت دارد (یعنی از جمله بیت های اولویت).–پرتاب پرتاب کردنآرگومان یا یک نام استاندارد است (از
iptables -m tos -h
برای مشاهده لیست استفاده کنید)، یا یک مقدار عددی برای مطابقت.

ttlاین ماژول با زمان اجرای فیلد در هدر IP مطابقت دارد.–ttl-eq ttlبا مقدار TTL داده شده مطابقت دارد.–ttl-gt ttlاگر TTL بزرگتر از مقدار TTL داده شده باشد مطابقت دارد.–ttl-lt ttlاگر TTL کمتر از مقدار TTL داده شده باشد مطابقت دارد.

u32U32 به شما امکان می دهد تا مقادیر حداکثر ۴ بایت را از یک بسته استخراج کنید، و آنها را با ماسک های مشخص شده، تغییر دهید، آنها را بر اساس مقادیر مشخص جابجا کنید و آزمایش کنید که آیا نتایج در یک مجموعه از محدوده های مشخص شده هستند یا خیر. مشخصات چیزی که باید استخراج شود به اندازه کافی عمومی است که از سربرگ هایی با طول های ذخیره شده در بسته عبور کند، مانند طول سرصفحه IP یا TCP.

جزئیات و نمونه ها در منبع ماژول هسته موجود است.

udpاگر «–protocol udp» مشخص شده باشد، این برنامه‌های افزودنی بارگیری می‌شوند. گزینه های زیر را ارائه می دهد:–source-port [!] پورت [: port ]مشخصات پورت منبع یا محدوده پورت. برای جزئیات بیشتر به توضیحات گزینه –source-port افزونه TCP مراجعه کنید.–destination-port [!] port [: port ]مشخصات پورت مقصد یا محدوده بندر. برای جزئیات بیشتر به توضیحات گزینه –destination-port افزونه TCP مراجعه کنید.

ناپاکاین ماژول هیچ گزینه ای ندارد، اما تلاش می کند بسته هایی را که بد شکل یا غیرعادی به نظر می رسند مطابقت دهد. این به عنوان تجربی در نظر گرفته می شود.

برنامه های افزودنی هدف

iptables می تواند از ماژول های هدف توسعه یافته استفاده کند: موارد زیر در توزیع استاندارد گنجانده شده است.

تعادلاین به شما این امکان را می‌دهد تا اتصالات DNAT را به صورت دور در محدوده مشخصی از آدرس‌های مقصد برقرار کنید.–به مقصد ipaddr-ipaddrمحدوده آدرس تا دور برگشتی.

طبقه بندی کردناین ماژول به شما اجازه می دهد تا مقدار اولویت skb-> را تنظیم کنید (و بنابراین بسته را در یک کلاس CBQ خاص طبقه بندی کنید).–Set-class MAJOR:MINORمقدار کلاس اصلی و مینور را تنظیم کنید.

خوشهاین ماژول به شما این امکان را می دهد که یک خوشه ساده از گره ها را پیکربندی کنید که یک آدرس IP و MAC مشخص را بدون یک متعادل کننده بار صریح در مقابل آنها به اشتراک بگذارند. اتصالات به صورت ایستا بین گره های این خوشه توزیع می شوند.–جدید

یک ClusterIP جدید ایجاد کنید. شما همیشه باید این را در اولین قانون برای یک ClusterIP مشخص تنظیم کنید.– حالت hashmodeحالت هش را مشخص کنید. باید یکی از sourceip، sourceip-sourceport، sourceip-sourceport-destport باشد–کلسترمک مکآدرس مک ClusterIP را مشخص کنید. باید یک آدرس چندپخشی لایه پیوند باشد— total-nodes numتعداد کل گره ها در این خوشه.–local-node numشماره گره محلی در این خوشه.–hash-init rndدانه تصادفی مورد استفاده برای مقداردهی اولیه را مشخص کنید.

CONNMARKاین ماژول مقدار علامت netfilter مربوط به یک اتصال را تنظیم می کندعلامت تنظیم علامت[/mask]علامت اتصال را تنظیم کنید. اگر یک ماسک مشخص شده باشد، فقط آن بیت های تنظیم شده در ماسک اصلاح می شوند.–save-mark [–mask mask]مقدار علامت بسته netfilter را روی علامت اتصال کپی کنید. اگر یک ماسک مشخص شده باشد، فقط آن بیت ها کپی می شوند.–بازیابی علامت [–ماسک ماسک]مقدار علامت اتصال را در بسته کپی کنید. اگر یک ماسک مشخص شده باشد، فقط آن بیت ها کپی می شوند. این فقط در جدول mangle معتبر است.

DNATاین هدف فقط در جدول nat ، در زنجیره‌های PREROUTING و OUTPUT ، و زنجیره‌های تعریف‌شده توسط کاربر که فقط از آن زنجیره‌ها فراخوانی می‌شوند معتبر است. مشخص می‌کند که آدرس مقصد بسته باید اصلاح شود (و تمام بسته‌های آینده در این ارتباط نیز مخدوش خواهند شد)، و قوانین باید بررسی شوند. این یک نوع گزینه را می طلبد:–to-destination ipaddr [- ipaddr ][: port – port ]که می تواند یک آدرس IP مقصد جدید، یک محدوده شامل آدرس های IP، و به صورت اختیاری، یک محدوده پورت را مشخص کند (که فقط در صورتی معتبر است که قانون -p tcp یا -p udp را نیز مشخص کند). اگر محدوده پورتی مشخص نشده باشد، درگاه مقصد هرگز تغییر نخواهد کرد.در Kernels تا ۲.۶.۱۰ می توانید چندین گزینه –to-destination اضافه کنید. برای آن هسته‌ها، اگر بیش از یک آدرس مقصد را مشخص کنید، چه از طریق یک محدوده آدرس یا چند گزینه –to-destination، یک تعادل بار ساده (یکی پس از دیگری در چرخه) بین این آدرس‌ها انجام می‌شود. هسته های بعدی (>= 2.6.11-rc1) دیگر توانایی NAT به چندین محدوده را ندارند.

DSCPاین هدف اجازه می دهد تا مقدار بیت های DSCP را در هدر TOS بسته IPv4 تغییر دهید. از آنجایی که این یک بسته را دستکاری می کند، فقط می توان از آن در جدول mangle استفاده کرد.مقدار –set-dscpفیلد DSCP را روی یک مقدار عددی تنظیم کنید (می تواند اعشاری یا هگزا باشد)کلاس –set-dscp- classفیلد DSCP را روی یک کلاس DiffServ قرار دهید.

ECNاین هدف اجازه می دهد تا به طور انتخابی در اطراف سیاهچاله های شناخته شده ECN کار کنید. فقط می توان از آن در جدول مانگل استفاده کرد.–ecn-tcp-removeتمام بیت های ECN را از هدر TCP حذف کنید. البته فقط می‌توان آن را همراه با -p tcp استفاده کرد.

IPMARKبه شما امکان می دهد بسته دریافتی را بر اساس آدرس IP آن علامت گذاری کنید. اگر از طبقه‌بندی‌کننده مبتنی بر فایروال استفاده می‌کنید، این می‌تواند بسیاری از ورودی‌های mangle/mark را تنها با یکی جایگزین کند.

این هدف قرار است در داخل میز مانگل، در قلاب های PREROUTING، POSTROUTING یا FORWARD استفاده شود.–addr src/dstاز آدرس IP مبدا یا مقصد استفاده کنید.ماسک –and- mask“and” را روی آدرس IP و این ماسک به صورت بیتی اجرا کنید.ماسک –یا ماسک“یا” را به صورت بیتی روی آدرس IP و این ماسک انجام دهید.ترتیب بایت های آدرس IP معکوس می شود تا با “ترتیب انسانی بایت ها” مطابقت کند: ۱۹۲.۱۶۸.۰.۱ 0xc0a80001 است. ابتدا عملیات “and” انجام می شود، سپس “یا”.

مثال ها:

ما یک صف برای هر کاربر ایجاد می کنیم، شماره صف برای آدرس IP کاربر کافی است، به عنوان مثال: تمام بسته هایی که به/از ۱۹۲.۱۶۸.۵.۲ می روند به صف ۱:۰۵۰۲، ۱۹۲.۱۶۸.۵.۱۲ -> 1:050c و غیره هدایت می شوند.

ما یک قانون طبقه بندی کننده داریم:فیلتر tc افزودن پروتکل dev eth3 parent 1:0 ip fwقبلاً قوانین زیادی مانند زیر داشتیم:iptables -t mangle -A POSTROUTING -o eth3 -d 192.168.5.2 -j MARK –set-mark 0x10502

iptables -t mangle -A POSTROUTING -o eth3 -d 192.168.5.3 -j MARK –set-mark 0x10503با استفاده از IPMARK target، می‌توانیم همه قوانین mangle/mark را تنها با یکی جایگزین کنیم:iptables -t mangle -A POSTROUTING -o eth3 -j IPMARK –addr=dst –and-mask=0xffff –or-mask=0x10000در روترهایی با صدها کاربر باید بار قابل توجهی کاهش یابد (مثلاً دو بار).

IPV4OPTSSTRIPتمام گزینه های IP را از یک بسته حذف کنید.

هدف هیچ گزینه ای را انتخاب نمی کند، بنابراین استفاده از آن بسیار آسان است:

# iptables -t mangle -A PREROUTING -j IPV4OPTSSTRIP

ورود به سیستمثبت هسته بسته های منطبق را روشن کنید. هنگامی که این گزینه برای یک قانون تنظیم می شود، هسته لینوکس برخی از اطلاعات را روی تمام بسته های منطبق (مانند اکثر فیلدهای هدر IP) از طریق گزارش هسته (جایی که می توان با dmesg یا syslogd (8) خواند) چاپ می کند. این یک “هدف غیر پایانی” است، یعنی پیمایش قانون در قانون بعدی ادامه می یابد. بنابراین اگر می‌خواهید بسته‌هایی را که رد می‌کنید ثبت کنید، از دو قانون جداگانه با معیارهای مشابه استفاده کنید، ابتدا از هدف LOG سپس DROP (یا رد کردن) استفاده کنید.-سطح log- levelسطح ورود به سیستم (عددی یا syslog.conf (5) را ببینید).—log-پیوند پیشوندپیغام های ثبت پیشوند با پیشوند مشخص شده. حداکثر ۲۹ حرف طول دارد و برای تشخیص پیام ها در گزارش ها مفید است.–log-tcp-sequenceاعداد دنباله TCP را ثبت کنید. اگر گزارش برای کاربران قابل خواندن باشد، این یک خطر امنیتی است.–log-tcp-Optionsگزینه‌ها را از سربرگ بسته TCP ثبت کنید.–log-ip-Optionsگزینه های گزارش از سربرگ بسته IP.–log-uidشناسه کاربری فرآیندی که بسته را تولید کرده است را وارد کنید.

علامتاین برای تنظیم مقدار علامت netfilter مرتبط با بسته استفاده می شود. فقط در جدول mangle معتبر است. به عنوان مثال می توان از آن در ارتباط با iproute2 استفاده کرد.– علامت تنظیم

بالماسکهاین هدف فقط در جدول nat ، در زنجیره POSTROUTING معتبر است. این فقط باید با اتصالات IP (dialup) اختصاص داده شده به صورت پویا استفاده شود: اگر یک آدرس IP ثابت دارید، باید از هدف SNAT استفاده کنید. ماسکه کردن معادل تعیین یک نگاشت به آدرس IP رابطی است که بسته در حال خارج شدن است، اما همچنین باعث می شود که وقتی رابط از بین می رود، اتصالات فراموش می شوند. این رفتار درست زمانی است که شماره گیری بعدی بعید است که آدرس رابط یکسانی داشته باشد (و از این رو هر گونه اتصال برقرار شده به هر حال از بین می رود). یک گزینه لازم است:–to-ports port [- port ]این گستره ای از پورت های منبع را برای استفاده مشخص می کند، که اکتشافی انتخاب پورت منبع SNAT پیش فرض را نادیده می گیرد (به بالا مراجعه کنید). این فقط در صورتی معتبر است که قانون -p tcp یا -p udp را نیز مشخص کند.

آینهاین یک هدف نمایشی آزمایشی است که فیلدهای مبدا و مقصد را در هدر IP معکوس می‌کند و بسته را دوباره ارسال می‌کند. این فقط در زنجیره های INPUT ، FORWARD و PREROUTING و زنجیره های تعریف شده توسط کاربر که فقط از آن زنجیره ها فراخوانی می شوند معتبر است. توجه داشته باشید که بسته های خروجی توسط هیچ زنجیره فیلترینگ بسته، ردیابی اتصال یا NAT دیده نمی شوند تا از حلقه ها و سایر مشکلات جلوگیری شود.

NETMAPاین هدف به شما اجازه می دهد تا به صورت ایستا یک شبکه کامل از آدرس ها را بر روی شبکه دیگری از آدرس ها نگاشت کنید. فقط می توان از قوانین موجود در جدول nat استفاده کرد.–به آدرس[/mask]آدرس شبکه برای نقشه برداری آدرس به دست آمده به روش زیر ساخته می شود: همه بیت های “یک” در ماسک از “آدرس” جدید پر می شوند. تمام بیت هایی که در ماسک صفر هستند از آدرس اصلی پر می شوند.

NFQUEUEاین هدف توسعه ای از هدف QUEUE است. برخلاف QUEUE، به شما این امکان را می دهد که یک بسته را در هر صف خاصی قرار دهید که با شماره صف ۱۶ بیتی آن مشخص می شود.– مقدار صف-numاین شماره QUEUE برای استفاده را مشخص می کند. اعداد صف ارزش از ۰ تا ۶۵۵۳۵ هستند. مقدار پیش فرض ۰ است.از آنجایی که به آن نیاز دارد، فقط با نسخه های هسته ۲.۶.۱۴ یا جدیدتر قابل استفاده استپشتیبانی از هسته nfnetlink_queue .

هیچ ردی نیستاین هدف ردیابی اتصال را برای همه بسته های مطابق با این قانون غیرفعال می کند.فقط می توان از آن استفاده کردجدول خام

تغییر مسیراین هدف فقط در جدول nat ، در زنجیره‌های PREROUTING و OUTPUT ، و زنجیره‌های تعریف‌شده توسط کاربر که فقط از آن زنجیره‌ها فراخوانی می‌شوند معتبر است. با تغییر IP مقصد به آدرس اصلی رابط ورودی، بسته را به خود ماشین هدایت می کند (بسته های تولید شده محلی به آدرس ۱۲۷.۰.۰.۱ نگاشت می شوند). یک گزینه لازم است:–to-ports port [- port ]این یک پورت مقصد یا محدوده پورت های مورد استفاده را مشخص می کند: بدون این، درگاه مقصد هرگز تغییر نمی کند. این فقط در صورتی معتبر است که قانون -p tcp یا -p udp را نیز مشخص کند.

رد کنیداین برای ارسال یک بسته خطا در پاسخ به بسته منطبق استفاده می شود: در غیر این صورت معادل DROP است، بنابراین یک TARGET پایانی است که پیمایش قانون پایان می یابد. این هدف فقط در زنجیره های INPUT ، FORWARD و OUTPUT و زنجیره های تعریف شده توسط کاربر که فقط از آن زنجیره ها فراخوانی می شوند معتبر است. گزینه زیر ماهیت بسته خطای برگشتی را کنترل می کند:–رد-با نوعنوع داده شده می تواند باشد

icmp-net-unreachable
 icmp-host-unreachable
 icmp-port-غیرقابل دسترسی
 icmp-proto-دست نیافتنی
 icmp-net-prohibited
 icmp-host-prohibited یا
 icmp-admin-prohibited (*)

که پیغام خطای ICMP مناسب را برمی‌گرداند ( پورت غیرقابل دسترسی پیش‌فرض است). گزینه tcp-reset را می توان در قوانینی استفاده کرد که فقط با پروتکل TCP مطابقت دارند: این باعث می شود یک بسته TCP RST برگردانده شود. این عمدتا برای مسدود کردن کاوشگرهای شناسه (113/tcp) مفید است که اغلب هنگام ارسال نامه به میزبان های ایمیل خراب (که در غیر این صورت نامه شما را نمی پذیرند) اتفاق می افتد.(*) استفاده از icmp-admin-prohibited با هسته هایی که از آن پشتیبانی نمی کنند، به جای رد کردن، یک DROP ساده ایجاد می کند.

یکسانمشابه SNAT/DNAT بسته به زنجیره: محدوده ای از آدرس ها را می گیرد (‘–to 1.2.3.4-1.2.3.7’) و برای هر اتصال همان منبع/آدرس مقصد را به مشتری می دهد.–به < ipaddr >-<ipaddr>آدرس ها به منبع نقشه به. ممکن است بیش از یک بار برای چندین محدوده مشخص شود.— nodstهنگام انتخاب منبع-ip جدید از مقصد-ip در محاسبات استفاده نکنید

تنظیماین ماژول ورودی‌هایی را از مجموعه‌های IP که می‌توان با ipset (8) تعریف کرد، اضافه و/یا حذف می‌کند.–افزودن -تنظیم پرچم مجموعه[,پرچم…]آدرس(ها)/ پورت (های) بسته را به مجموعه ها اضافه کنید—del-set flag setname[,flag…]آدرس(ها)/ پورت (های) بسته را از مجموعه ها حذف کنید، جایی که پرچم ها src و/یا dst هستند و نمی تواند بیش از شش عدد از آنها باشد.پیوندهایی که باید دنبال شوند باید قبلاً برای استفاده تعریف شده باشندافزودن/حذف چندسطحی توسط هدف SET.

SNATاین هدف فقط در جدول nat ، در زنجیره POSTROUTING معتبر است. مشخص می‌کند که آدرس منبع بسته باید اصلاح شود (و تمام بسته‌های آینده در این ارتباط نیز مخدوش خواهند شد)، و قوانین باید بررسی شوند. این یک نوع گزینه را می طلبد:–to-source ipaddr [- ipaddr ][: port – port ]که می تواند یک آدرس IP منبع جدید، یک محدوده شامل آدرس های IP، و به صورت اختیاری، یک محدوده پورت را مشخص کند (که فقط در صورتی معتبر است که قانون -p tcp یا -p udp را نیز مشخص کند). اگر محدوده پورت مشخص نشده باشد، پورت های منبع زیر ۵۱۲ به پورت های دیگر زیر ۵۱۲ نگاشت می شوند: پورت های بین ۵۱۲ و ۱۰۲۳ شامل پورت های زیر ۱۰۲۴ و سایر پورت ها به ۱۰۲۴ یا بالاتر نگاشت می شوند. در صورت امکان، هیچ تغییری در پورت رخ نخواهد داد.در کرنل ها تا ۲.۶.۱۰، می توانید چندین گزینه –to-source اضافه کنید. برای آن هسته‌ها، اگر بیش از یک آدرس منبع را مشخص کنید، چه از طریق یک محدوده آدرس یا چندین گزینه –to-source، یک دور ساده (یکی پس از دیگری در چرخه) بین این آدرس‌ها انجام می‌شود. هسته های بعدی (>= 2.6.11-rc1) دیگر توانایی NAT به چندین محدوده را ندارند.

گودال قیراتصالات TCP ورودی را بدون استفاده از منابع محلی برای هر اتصال، ضبط و نگهداری می کند. اتصالات پذیرفته می شوند، اما بلافاصله به حالت ماندگار (پنجره ۰ بایت) تغییر می کنند، که در آن سمت راه دور ارسال داده را متوقف می کند و هر ۶۰-۲۴۰ ثانیه از شما درخواست می کند که ادامه یابد. تلاش‌ها برای بستن اتصال نادیده گرفته می‌شوند و طرف راه دور مجبور می‌شود اتصال را در ۱۲-۲۴ دقیقه قطع کند.

این عملکرد مشابه LaBrea < http://www.hackbusters.net/LaBrea/ > را ارائه می دهد اما به سخت افزار یا IP اختصاصی نیاز ندارد. هر پورت TCP که معمولاً آن را DROP یا رد می‌کنید، می‌تواند به یک tarpit تبدیل شود.

برای tarpit کردن اتصالات به پورت TCP 80 برای دستگاه فعلی:iptables -A INPUT -p tcp -m tcp –dport 80 -j TARPITبرای کند کردن قابل توجه اسکن‌های کد Red/Nimda از فضای آدرس بلااستفاده، آدرس‌های IP استفاده‌نشده را به جعبه لینوکس که به عنوان روتر عمل نمی‌کند، ارسال کنید (به عنوان مثال «IP route 10.0.0.0 255.0.0.0 ip.of.linux.box» در یک Cisco)، انتقال IP را در جعبه لینوکس فعال کنید و اضافه کنید:iptables -A FORWARD -p tcp -j TARPIT

iptables -A FORWARD -j DROPتوجه داشته باشید:

اگر در حین استفاده از TARPIT از ماژول conntrack استفاده می کنید، باید از هدف NOTRACK نیز استفاده کنید، در غیر این صورت کرنل منابعی را برای هر اتصال TARPIT اختصاص می دهد. برای TARPIT اتصالات ورودی به پورت استاندارد IRC در حین استفاده از conntrack، می توانید:iptables -t raw -A PREROUTING -p tcp –dport 6667 -j NOTRACK

iptables -A INPUT -p tcp –dport 6667 -j TARPIT

TCPMSSاین هدف اجازه می دهد تا مقدار MSS بسته های TCP SYN را تغییر دهید تا حداکثر اندازه آن اتصال را کنترل کنید (معمولاً آن را به MTU منهای ۴۰ رابط خروجی شما محدود می کند). البته فقط می‌توان آن را همراه با -p tcp استفاده کرد. فقط در جدول mangle معتبر است.
این هدف برای غلبه بر ISPها یا سرورهای مجرمانه مرگ مغزی که بسته های مورد نیاز ICMP Fragmentation Needed را مسدود می کنند، استفاده می شود. علائم این مشکل این است که همه چیز از طریق فایروال/روتر لینوکس شما به خوبی کار می کند، اما ماشین های پشت آن هرگز نمی توانند بسته های بزرگ را مبادله کنند:۱)

مرورگرهای وب متصل می‌شوند، سپس بدون دریافت داده‌ای متوقف می‌شوند.

۲)

نامه های کوچک به خوبی کار می کنند، اما ایمیل های بزرگ معلق هستند.

۳)

ssh خوب کار می کند، اما scp بعد از دست دادن اولیه هنگ می کند.راه حل: این گزینه را فعال کنید و یک قانون به پیکربندی فایروال خود اضافه کنید مانند:

iptables -t mangle -A FORWARD -p tcp --tcp-flags SYN,RST SYN \
            -j TCPMSS --clamp-mss-to-pmtu

مقدار –set-mssبه صراحت گزینه MSS را روی مقدار مشخص شده تنظیم کنید.–clamp-mss-to-pmtuبه طور خودکار مقدار MSS را روی (path_MTU – 40) گیره کنید.این گزینه ها متقابل هستند.

TOSاین برای تنظیم فیلد ۸ بیتی Type of Service در هدر IP استفاده می شود. فقط در جدول mangle معتبر است.— set-tos tosمی توانید از مقادیر TOS عددی استفاده کنید یا استفاده کنید

iptables -j TOS -h

برای مشاهده لیست نام های TOS معتبر.

پی گیریاین هدف هیچ گزینه ای ندارد. فقط ردیابی بسته را برای همه بسته هایی که با این قانون مطابقت دارند روشن می کند.

TTLاین برای اصلاح فیلد هدر IPv4 TTL استفاده می شود. فیلد TTL تعیین می‌کند که یک بسته چند جهش (روتر) را می‌تواند طی کند تا زمانی که زمان حیات از آن فراتر رود.تنظیم یا افزایش فیلد TTL به طور بالقوه می تواند بسیار خطرناک باشد،بنابراین باید به هر قیمتی از آن اجتناب کرد.هرگز مقدار بسته هایی را که شبکه محلی شما را ترک می کنند تنظیم یا افزایش ندهید!میز پره .مقدار –ttl-setمقدار TTL را روی “value” تنظیم کنید.مقدار –ttl-decبار مقدار TTL ‘value’ را کاهش دهید.مقدار –ttl-incبار مقدار TTL ‘value’ را افزایش دهید.

چاپلوسیاین هدف ثبت فضای کاربر بسته های منطبق را فراهم می کند. هنگامی که این هدف برای یک قانون تنظیم می شود، هسته لینوکس این بسته را از طریق یک سوکت شبکه چند پخش می کند. یک یا چند فرآیند فضای کاربر ممکن است در گروه‌های چندپخشی مختلف مشترک شوند و بسته‌ها را دریافت کنند. مانند LOG، این یک “هدف غیر پایانی” است، یعنی پیمایش قانون در قانون بعدی ادامه می یابد.–ulog-nlgroup nlgroupاین گروه netlink (1-32) را مشخص می کند که بسته به آن ارسال می شود. مقدار پیش فرض ۱ است.پیشوند –olog- prefixپیغام های ثبت پیشوند با پیشوند مشخص شده. حداکثر ۳۲ کاراکتر و برای تشخیص پیام ها در گزارش ها مفید است.اندازه –ulog-cprangeتعداد بایت هایی که باید در فضای کاربری کپی شوند. مقدار ۰ همیشه کل بسته را بدون توجه به اندازه آن کپی می کند. پیش فرض ۰ است.اندازه -ulog-qthresholdتعداد بسته برای صف در داخل هسته. تنظیم این مقدار روی، به عنوان مثال ۱۰، ده بسته را در داخل هسته جمع می کند و آنها را به عنوان یک پیام چند قسمتی شبکه به فضای کاربران ارسال می کند. پیش فرض ۱ است (برای سازگاری با عقب).

XORبا استفاده از یک رمزگذاری ساده XOR، ترافیک TCP و UDP را رمزگذاری کنید— رشته کلیدتنظیم کلید روی “رشته”– اندازه بلوکتنظیم اندازه بلوک

تشخیص

پیغام های خطای مختلفی با خطای استاندارد چاپ می شوند. کد خروج برای عملکرد صحیح ۰ است. خطاهایی که به نظر می رسد ناشی از پارامترهای خط فرمان نامعتبر یا سوء استفاده شده باشد باعث کد خروج ۲ می شود و سایر خطاها باعث ایجاد کد خروج ۱ می شوند.

اشکالات

اشکالات؟ این چیه؟ 😉 خوب، ممکن است بخواهید به http://bugzilla.netfilter.org/ نگاهی بیندازید

سازگاری با Ipchains

این iptables بسیار شبیه به ipchains توسط Rusty Russell است. تفاوت اصلی این است که زنجیره‌های INPUT و OUTPUT فقط برای بسته‌هایی که به میزبان محلی می‌آیند و به ترتیب از میزبان محلی منشا می‌گیرند، عبور می‌کنند. از این رو هر بسته فقط از یکی از سه زنجیره عبور می کند (به جز ترافیک حلقه بک که شامل هر دو زنجیره ورودی و خروجی می شود). قبلاً یک بسته ارسال شده از هر سه عبور می کرد.

تفاوت اصلی دیگر این است که -i به رابط ورودی اشاره دارد. -o به رابط خروجی اشاره دارد و هر دو برای بسته هایی که وارد زنجیره FORWARD می شوند در دسترس هستند.

iptables یک فیلتر بسته خالص در هنگام استفاده از جدول پیش‌فرض «فیلتر» با ماژول‌های افزونه اختیاری است. این باید بسیاری از سردرگمی های قبلی را در مورد ترکیبی از پنهان سازی IP و فیلتر بسته که قبلاً دیده شده بود، ساده کند. بنابراین گزینه های زیر به طور متفاوتی مدیریت می شوند:

-j MASQ
-ام‌اس
-M -L

چندین تغییر دیگر در iptable ها وجود دارد.

همچنین ببینید

iptables-save (8)، iptables-restore (8)، ip6tables (8)، ip6tables-save (8)، ip6tables-restore (8)، libipq (3).

packet-filtering-HOWTO جزئیات استفاده از iptables برای فیلتر کردن بسته ها، NAT-HOWTO جزئیات NAT، netfilter-extensions-HOWTO جزئیات برنامه های افزودنی که در توزیع استاندارد نیستند، و netfilter-hacking-HOWTO جزئیات داخلی فیلتر netfilter را نشان می دهد. به http://www.netfilter.org/
مراجعه کنید .

نویسندگان

Rusty Russell در ابتدا با مشورت مایکل Neuling، iptables را نوشت.

مارک بوچر با لابی کردن برای یک چارچوب انتخاب بسته عمومی در iptables، Rusty را وادار کرد که ipnatctl را رها کند، سپس جدول mangle، تطبیق مالک، چیزهای علامت گذاری را نوشت و به اطراف دوید و کارهای جالبی را در همه جا انجام داد.

جیمز موریس هدف TOS و tos match را نوشت.

Jozsef Kadlecsik هدف رد کردن را نوشت.

Harald Welte هدف ULOG و NFQUEUE، libiptc جدید، و همچنین TTL، DSCP، ECN و اهداف را نوشت.

تیم اصلی Netfilter عبارتند از: مارک بوچر، مارتین جوزفسون، جوزف کادلسیک، پاتریک مک هاردی، جیمز موریس، هارالد ولته و روستی راسل.

Tab 3

منبع دستور https://linux.die.net/man/8/iptables

آیا این نوشته برایتان مفید بود؟

‫2 نظر

دیدگاهتان را بنویسید

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *

پشتیبانی امداد شبکه