IPTABLES-EXTENSIONS(8) iptables 1.8.11 IPTABLES-EXTENSIONS(8) (NAME) iptables-extensions - iptables (SYNOPSIS) ip6tables [-m name [module-options...]] [-j target-name [target- options...] iptables [-m name [module-options...]] [-j target-name [target- options...] (MATCH EXTENSIONS) iptables -m --match . -h --help . . -p --protocol iptables . addrtype . . . : UNSPEC ( 0.0.0.0) UNICAST (unicast) LOCAL (local) BROADCAST (broadcast) ANYCAST (anycast) MULTICAST (multicast) BLACKHOLE (blackhole) UNREACHABLE (unreachable) PROHIBIT (prohibited) THROW FIXME NAT FIXME XRESOLVE [!] --src-type type [!] --dst-type type --limit-iface-in . PREROUTING INPUT FORWARD . --limit-iface-out . --limit-iface-out . POSTROUTING OUTPUT FORWARD . --limit-iface-in . ah (IPv6-specific) (Authentication header) IPsec . [!] --ahspi spi[:spi] SPI . [!] --ahlen length (). --ahres . ah (IPv4-specific) SPI (Authentication header) IPsec . [!] --ahspi spi[:spi] bpf (Linux Socket Filter). eBPF cBPF () . --object-pinned path eBPF. eBPF bpf() BPF_PROG_LOAD BPF_OBJ_PIN . iptables bpf (mount) : mount -t bpf bpf ${BPF_MOUNT} iptables : iptables -A OUTPUT -m bpf --object-pinned ${BPF_MOUNT}/{PINNED_PATH} -j ACCEPT --bytecode code BPF nfbpf_compile . tcpdump -ddd : . 'u16 u8 u8 u32' . (true) (false) 'K' . () . 'ip proto 6' : 4 # number of instructions 48 0 0 9 # load byte ip->proto 21 0 1 6 # jump equal IPPROTO_TCP 6 0 0 1 # return pass (non-zero) 6 0 0 0 # return fail (zero) bpf : iptables -A OUTPUT -m bpf --bytecode '4,48 0 0 9,21 0 1 6,6 0 0 1,6 0 0 0' -j ACCEPT nfbpf_compile : iptables -A OUTPUT -m bpf --bytecode "`nfbpf_compile RAW 'ip proto 6'`" -j ACCEPT tcpdump -ddd . BPF (data link type) xtables . iptables MAC . RAW tun: ip tuntap add tun0 mode tun ip link set tun0 up tcpdump -ddd -i tun0 ip proto 6 tcpdump -L -i $dev . BPF bpf(4) FreeBSD . cgroup [!] --path path cgroup2. cgroup . . cgroup2 . [!] --cgroup classid classid net_cls cgroup. classid net_cls cgroup . --path . : iptables -A OUTPUT -p tcp --sport 80 -m cgroup ! --path service/http-server -j DROP iptables -A OUTPUT -p tcp --sport 80 -m cgroup ! --cgroup 1 -j DROP : INPUT cgroup (early socket demuxing) . INPUT . 3.14 . cluster (load-sharing) (load-balancers) . . cluster : --cluster-total-nodes num . [!] --cluster-local-node num (ID) . [!] --cluster-local-nodemask mask . --cluster-local-node . --cluster-hash-seed value (seed) (Jenkins hash). : iptables -A PREROUTING -t mangle -i eth1 -m cluster --cluster-total-nodes 2 --cluster-local-node 1 --cluster-hash-seed 0xdeadbeef -j MARK --set-mark 0xffff iptables -A PREROUTING -t mangle -i eth2 -m cluster --cluster-total-nodes 2 --cluster-local-node 1 --cluster-hash-seed 0xdeadbeef -j MARK --set-mark 0xffff iptables -A PREROUTING -t mangle -i eth1 -m mark ! --mark 0xffff -j DROP iptables -A PREROUTING -t mangle -i eth2 -m mark ! --mark 0xffff -j DROP : ip maddr add 01:00:5e:00:01:01 dev eth1 ip maddr add 01:00:5e:00:01:02 dev eth2 arptables -A OUTPUT -o eth1 --h-length 6 -j mangle --mangle-mac-s 01:00:5e:00:01:01 arptables -A INPUT -i eth1 --h-length 6 --destination-mac 01:00:5e:00:01:01 -j mangle --mangle-mac-d 00:zz:yy:xx:5a:27 arptables -A OUTPUT -o eth2 --h-length 6 -j mangle --mangle-mac-s 01:00:5e:00:01:02 arptables -A INPUT -i eth2 --h-length 6 --destination-mac 01:00:5e:00:01:02 -j mangle --mangle-mac-d 00:zz:yy:xx:5a:27 : arptables . arptables-jf RedHat CentOS Fedora . arptables-jf . TCP pickup TCP ACK : echo 0 > /proc/sys/net/netfilter/nf_conntrack_tcp_loose comment ( ) . --comment comment : iptables -A INPUT -i eth1 -m comment --comment "my local LAN" connbytes ( ) . ;) . conntrack -L ctnetlink . (accounting) false . "net.netfilter.nf_conntrack_acct" / . . [!] --connbytes from[:to] // FROM TO / . TO FROM . "!" . --connbytes-dir {original|reply|both} . --connbytes-mode {packets|bytes|avgpkt} ( ) . "both" "avgpkt" () ( HTTP) . : iptables .. -m connbytes --connbytes 10000:100000 --connbytes-dir both --connbytes-mode bytes ... connlabel connlabel . connlabel connmark . . [!] --label name name . ( ) . connlabel.conf . --set . conntrack . ( --label ). libnetfilter_conntrack 1.0.4 . /etc/xtables/connlabel.conf . : 0 eth0-in 1 eth0-out 2 ppp-in 3 ppp-out 4 bulk-traffic 5 interactive connlimit IP ( ) . --connlimit-upto n n . --connlimit-above n n . --connlimit-mask prefix_length (prefix length). IPv4 ( ) . IPv6 . . --connlimit-saddr . --connlimit-daddr . --connlimit-daddr . : o telnet : iptables -A INPUT -p tcp --syn --dport 23 -m connlimit --connlimit-above 2 -j REJECT o : iptables -A INPUT -p tcp --syn --dport 23 -m connlimit --connlimit-upto 2 -j ACCEPT o HTTP C ( ): iptables -p tcp --syn --dport 80 -m connlimit --connlimit-above 16 --connlimit-mask 24 -j REJECT o HTTP (IPv6): ip6tables -p tcp --syn --dport 80 -s fe80::/64 -m connlimit --connlimit-above 16 --connlimit-mask 64 -j REJECT o : ip6tables -p tcp --syn --dport 49152:65535 -d 2001:db8::1 -m connlimit --connlimit-above 100 -j REJECT connmark (mark) (netfilter) ( CONNMARK ). [!] --mark value[/mask] ( AND ). conntrack (connection tracking) / . [!] --ctstate statelist statelist . . [!] --ctproto l4proto ( ). [!] --ctorigsrc address[/mask] [!] --ctorigdst address[/mask] [!] --ctreplsrc address[/mask] [!] --ctrepldst address[/mask] / (original) (reply). [!] --ctorigsrcport port[:port] [!] --ctorigdstport port[:port] [!] --ctreplsrcport port[:port] [!] --ctrepldstport port[:port] / (TCP/UDP ) GRE. 2.6.38 . [!] --ctstatus statelist statuslist . . [!] --ctexpire time[:time] ( ). --ctdir {ORIGINAL|REPLY} . . --ctstate: INVALID . NEW . ESTABLISHED . RELATED FTP ICMP. UNTRACKED -j CT --notrack raw . SNAT . DNAT . --ctstatus: NONE . EXPECTED ( conntrack helper ). SEEN_REPLY conntrack . ASSURED conntrack . CONFIRMED : . cpu [!] --cpu number . 0 NR_CPUS-1 . RPS ( Remote Packet Steering) (multiqueue NICs) . : iptables -t nat -A PREROUTING -p tcp --dport 80 -m cpu --cpu 0 -j REDIRECT --to-ports 8080 iptables -t nat -A PREROUTING -p tcp --dport 80 -m cpu --cpu 1 -j REDIRECT --to-ports 8081 2.6.36 . dccp [!] --source-port,--sport port[:port] [!] --destination-port,--dport port[:port] [!] --dccp-types mask DCCP 'mask' . 'mask' . : REQUEST RESPONSE DATA ACK DATAACK CLOSEREQ CLOSE RESET SYNC SYNCACK INVALID. [!] --dccp-option number DCCP . devgroup / . [!] --src-group name [!] --dst-group name dscp DSCP TOS IP . DSCP IETF TOS . [!] --dscp value ( ) 0-63. [!] --dscp-class class DiffServ. BE EF AFxx CSx . . dst (IPv6-specific) (Destination Options) . [!] --dst-len length (). --dst-opts type[:length][,type[:length]...] (). ecn ECN IPv4/IPv6 TCP . ECN (Explicit Congestion Notification) RFC3168 . [!] --ecn-tcp-cwr ECN CWR ( / Congestion Window Received) TCP . [!] --ecn-tcp-ece ECN ECE ( ECN / ECN Echo) TCP . [!] --ecn-ip-ect num ECT ( ECN / ECN-Capable Transport) IPv4/IPv6 . `0` `3` . esp SPI ESP IPsec . [!] --espspi spi[:spi] eui64 (IPv6-specific) EUI-64 IPv6 (stateless autoconfigured) . EUI-64 MAC IPv6 . "Universal/Local" . PREROUTING INPUT FORWARD . frag (IPv6-specific) (Fragment header) . [!] --fragid id[:id] (Identification) . [!] --fraglen length 2.6.10 . . --fragres . --fragfirst . --fragmore . --fraglast . hashlimit hashlimit (hash buckets) ( limit) iptables . ( / ) / . "N " "N " ( ). (--hashlimit-upto --hashlimit-above) --hashlimit-name . --hashlimit-upto amount[/second|/minute|/hour|/day] amount/quantum . ( 3/hour ) amountb/second ( ). --hashlimit-above amount[/second|/minute|/hour|/day] amount/quantum . --hashlimit-burst amount : 5 . . -- burst . --hashlimit-mode {srcip|srcport|dstip|dstport},... . --hashlimit-mode hashlimit limit . --hashlimit-srcmask prefix --hashlimit-mode srcip hashlimit . prefix 0 32 ( ) . --hashlimit-srcmask 0 srcip --hashlimit-mode . --hashlimit-dstmask prefix --hashlimit-srcmask . --hashlimit-name foo proc/net/ipt_hashlimit/foo/. --hashlimit-htable-size buckets . --hashlimit-htable-max entries . --hashlimit-htable-expire msec . --hashlimit-htable-gcinterval msec (garbage collection). --hashlimit-rate-match . / (true/false) / . --hashlimit-rate-interval sec --hashlimit-rate-match . : "1000 packets per second for every host in 192.168.0.0/16" => -s 192.168.0.0/16 --hashlimit-mode srcip --hashlimit-upto 1000/sec "100 packets per second for every service of 192.168.1.1" => -s 192.168.1.1 --hashlimit-mode srcport --hashlimit-upto 100/sec "10000 packets per minute for every /28 subnet (groups of 8 addresses) in 10.0.0.0/8" => -s 10.0.0.0/8 --hashlimit-mask 28 --hashlimit-upto 10000/min "flows exceeding 512kbyte/s" => --hashlimit-mode srcip,dstip,srcport,dstport --hashlimit-above 512kb/s "hosts that exceed 512kbyte/s, but permit up to 1Megabytes without matching" --hashlimit-mode dstip --hashlimit-above 512kb/s --hashlimit-burst 1mb hbh (IPv6-specific) (Hop-by-Hop Options) . [!] --hbh-len length (). --hbh-opts type[:length][,type[:length]...] (). helper conntrack helper . [!] --helper string conntrack helper . FTP "ftp" . portnr-- "ftp-2121". conntrack helper . hl (IPv6-specific) (Hop Limit) IPv6 . [!] --hl-eq value value . --hl-lt value value . --hl-gt value value . icmp (IPv4-specific) `--protocol icmp` . : [!] --icmp-type {type[/code]|typename} ICMP ICMP / (type/code) ICMP : iptables -p icmp -h icmp6 (IPv6-specific) `--protocol ipv6-icmp` `--protocol icmpv6` . : [!] --icmpv6-type type[/code]|typename ICMPv6 type ICMPv6 type code ICMPv6 : ip6tables -p ipv6-icmp -h iprange IP . [!] --src-range from[-to] IP . [!] --dst-range from[-to] IP . ipv6header (IPv6-specific) IPv6 / . --soft --header . [!] --header header[,header...] . ESP . header : hop|hop-by-hop (Hop-by-Hop Options) dst (Destination Options) route (Routing) frag (Fragment) auth (Authentication) esp (Encapsulating Security Payload) none (No Next header) 59 'Next Header' IPv6 IPv6 prot . /etc/protocols . 255 prot . ipvs IPVS ( ). [!] --ipvs IPVS . --ipvs ( ): [!] --vproto protocol VIP "tcp". [!] --vaddr address[/mask] VIP . [!] --vport port VIP "http". --vdir {ORIGINAL|REPLY} ( ). [!] --vmethod {GATE|IPIP|MASQ} (Forwarding) IPVS. [!] --vportctl port VIP 21 FTP. length (Payload) ( ) . [!] --length length[:length] limit (Token Bucket Filter) . . LOG . xt_limit -- -m hashlimit ! --hashlimit rate --hashlimit-mode . --limit rate[/second|/minute|/hour|/day] : `/second` `/minute` `/hour` `/day` 3/hour . --limit-burst number : 5 . mac [!] --mac-source address MAC . XX:XX:XX:XX:XX:XX . PREROUTING FORWARD INPUT . mark (mark) ( MARK ). [!] --mark value[/mask] (mark) (unsigned) ( mask mask AND ). mh (IPv6-specific) --protocol ipv6-mh --protocol mh : [!] --mh-type type[:type] (Mobility Header MH) type type MH : ip6tables -p mh -h multiport . . (port:port) . : tcp udp udplite dccp sctp. [!] --source-ports,--sports port[,port|,port:port]... . --sports . () (:) . 53,1024:65535 . [!] --destination-ports,--dports port[,port|,port:port]... . --dports . [!] --ports port[,port|,port:port]... . nfacct nfacct (accounting) iptables . nfacct(8) . : --nfacct-name name . : nfacct add http-traffic iptables : iptables -I INPUT -p tcp --sport 80 -m nfacct --nfacct-name http-traffic iptables -I OUTPUT -p tcp --dport 80 -m nfacct --nfacct-name http-traffic : nfacct get http-traffic { pkts = 00000000000000000156, bytes = 00000000000000151786 } = http-traffic; nfacct(8) https://www.netfilter.org git.netfilter.org . osf osf (Passive OS Fingerprinting) . ( MSS TTL DF ) SYN . [!] --genre string () . --ttl level TTL . level : 0 IP TTL . (LAN) . 1 TTL IP . () . 2 TTL . --log level dmesg . level : 0 1 2 syslog : Windows [2000:SP3:Windows XP Pro SP1, 2000 SP3]: 11.22.33.55:4024 -> 11.22.33.44:139 hops=3 Linux [2.5-2.6:] : 1.2.3.4:42624 -> 1.2.3.5:22 hops=4 nfnl_osf . : nfnl_osf -f /usr/share/xtables/pf.os : nfnl_osf -f /usr/share/xtables/pf.os -d : http://www.openbsd.org/cgi-bin/cvsweb/src/etc/pf.os owner . OUTPUT POSTROUTING . (Forwarded) . (Kernel Threads) . [!] --uid-owner username [!] --uid-owner userid[-userid] ( ) . UID UID . [!] --gid-owner groupname [!] --gid-owner groupid[-groupid] . GID GID . --suppl-groups () --gid-owner (Supplementary Groups) . [!] --socket-exists . physdev (Bridge) . IP 2.5.44 . [!] --physdev-in name ( INPUT FORWARD PREROUTING ). "+" . '!' . [!] --physdev-out name ( FORWARD POSTROUTING ). "+" . [!] --physdev-is-in . [!] --physdev-is-out . [!] --physdev-is-bridged . FORWARD POSTROUTING . pkttype (Link-Layer) . [!] --pkt-type {unicast|broadcast|multicast} policy (Policy) IPsec . --dir {in|out} (Decapsulation) (Encapsulation). in PREROUTING INPUT FORWARD out POSTROUTING OUTPUT FORWARD . --pol {none|ipsec} IPsec . --pol none --strict . --strict . . --strict . [!] --reqid id reqid . reqid setkey(8) unique:id . [!] --spi spi SPI SA . [!] --proto {ah|esp|ipcomp} . [!] --mode {tunnel|transport} . [!] --tunnel-src addr[/mask] SA . --mode tunnel . [!] --tunnel-dst addr[/mask] SA . --mode tunnel . --next . --strict . quota (Network Quota) . ( ). ( ). [!] --quota bytes . rateest (Rate Estimator) RATEEST . bps/pps . : (Absolute): o rateest operator rateest-bps o rateest operator rateest-pps + (Absolute + Delta): o (rateest minus rateest-bps1) operator rateest-bps2 o (rateest minus rateest-pps1) operator rateest-pps2 (Relative): o rateest1 operator rateest2 rateest-bps(without rate!) o rateest1 operator rateest2 rateest-pps(without rate!) + (Relative + Delta): o (rateest1 minus rateest-bps1) operator (rateest2 minus rateest- bps2) o (rateest1 minus rateest-pps1) operator (rateest2 minus rateest- pps2) --rateest-delta ( ) BPS/PPS . BPS/PPS 0 . "max(0, rateest#_rate - rateest#_bps)" . [!] --rateest-lt / . [!] --rateest-gt / . [!] --rateest-eq / . " " (absolute mode) " " (relative mode) . --rateest name . --rateest1 name --rateest2 name . --rateest-bps [value] --rateest-pps [value] --rateest-bps1 [value] --rateest-bps2 [value] --rateest-pps1 [value] --rateest-pps2 [value] () . . () -- : bit [kmgt]bit [KMGT]ibit Bps [KMGT]Bps [KMGT]iBps. : FTP : # iptables -t mangle -A POSTROUTING -o eth0 -j RATEEST --rateest-name eth0 --rateest-interval 250ms --rateest-ewma 0.5s iptables -t mangle -A POSTROUTING -o ppp0 -j RATEEST --rateest-name ppp0 --rateest-interval 250ms --rateest-ewma 0.5s # iptables -t mangle -A balance -m conntrack --ctstate NEW -m helper --helper ftp -m rateest --rateest-delta --rateest1 eth0 --rateest-bps1 2.5mbit --rateest-gt --rateest2 ppp0 --rateest-bps2 2mbit -j CONNMARK --set-mark 1 iptables -t mangle -A balance -m conntrack --ctstate NEW -m helper --helper ftp -m rateest --rateest-delta --rateest1 ppp0 --rateest-bps1 2mbit --rateest-gt --rateest2 eth0 --rateest-bps2 2.5mbit -j CONNMARK --set-mark 2 iptables -t mangle -A balance -j CONNMARK --restore-mark realm (IPv4-specific) (Routing Realm) . BGP . [!] --realm value[/mask] ( ) . /etc/iproute2/rt_realms ( ). () ( "0x") ( ) . recent IP . "badguy" DROP . --set --rcheck --update --remove ( ). --name name . DEFAULT . [!] --set . . ( ! ) . --rsource . . --rdest . --mask netmask (netmask) . [!] --rcheck . [!] --update --rcheck << >> (last seen) . [!] --remove (true) . (false) . --seconds seconds --rcheck --update . . --reap --seconds . . --hitcount hits --rcheck --update . . --seconds . --rttl --rcheck --update . TTL TTL --set . (DoS) . : 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 DROP /proc/net/xt_recent/* . /proc/net/xt_recent/ : echo +addr >/proc/net/xt_recent/DEFAULT addr DEFAULT echo -addr >/proc/net/xt_recent/DEFAULT addr DEFAULT echo / >/proc/net/xt_recent/DEFAULT DEFAULT ( ). : ip_list_tot=100 . ip_pkt_list_tot=0 . . --hitcount . ip_list_hash_size=0 (Hash table). ip_list_tot ( 100 ip_list_tot ip_list_hash_size 128 ). ip_list_perms=0644 /proc/net/xt_recent/*. ip_list_uid=0 (UID) /proc/net/xt_recent/*. ip_list_gid=0 (GID) /proc/net/xt_recent/*. rpfilter (reverse path filter) . . rp_filter IPSec . policy . loopback . PREROUTING raw mangle . --loose . --validmark nfmark . --accept-local . --invert . (DROP) : iptables -t raw -N RPFILTER iptables -t raw -A RPFILTER -m rpfilter -j RETURN iptables -t raw -A RPFILTER -m limit --limit 10/minute -j NFLOG --nflog-prefix "rpfilter drop" iptables -t raw -A RPFILTER -j DROP iptables -t raw -A PREROUTING -j RPFILTER : iptables -t raw -A RPFILTER -m rpfilter --invert -j DROP rt (IPv6-specific) IPv6. [!] --rt-type type (). [!] --rt-segsleft num[:num] << >> (`segments left`) ( ). [!] --rt-len length . --rt-0-res (type=0). --rt-0-addrs addr[,addr...] (). --rt-0-not-strict (strict) . sctp (SCTP) . [!] --source-port,--sport port[:port] [!] --destination-port,--dport port[:port] [!] --chunk-types {all|any|only} chunktype[:flags] [...] (set) (unset) . : all (chunk types) . any . only . (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 I_DATA RE_CONFIG PAD ASCONF ASCONF_ACK FORWARD_TSN I_FORWARD_TSN chunk type available flags DATA I U B E i u b e I_DATA I U B E i u b e 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-types any DATA:Be -j ACCEPT set IP ipset(8) . [!] --match-set setname flag[,flag]... src / dst . iptables -A FORWARD -m set --match-set test src,dst ( ipportmap ) . ( ipmap) . --return-nomatch --return-nomatch nomatch : nomatch true false . ! --update-counters --update-counters . . ! --update-subcounters --update-subcounters . . [!] --packets-eq value . --packets-lt value . --packets-gt value . [!] --bytes-eq value . --bytes-lt value . --bytes-gt value . . --match-set --set . -m set ipset 2.6.39 . socket TCP/UDP . (bound) (established) ( ) . (tuple) TCP/UDP TCP/UDP (embedded) ICMP/ICMPv6 . --transparent (non-transparent) . --nowildcard ('any' address 0.0.0.0) . (zero- bound) (forward) . (policy routing) . --transparent . ( ): -t mangle -A PREROUTING -m socket --transparent -j MARK --set-mark 1 --restore-skmark . --transparent --nowildcard . : (IP_TRANSPARENT) SO_MARK . : -t mangle -I PREROUTING -m socket --transparent --restore-skmark -j action -t mangle -A action -m mark --mark 10 -j action2 -t mangle -A action -m mark --mark 11 -j action3 state <> <> . <> (connection tracking) . [!] --state state state . <> : INVALID ESTABLISHED NEW RELATED UNTRACKED. <> . statistic . --mode . : --mode mode random nth. [!] --probability p . random . p 0.0 1.0 . 1/2147483648 . [!] --every n n . nth ( --packet ). --packet p (0 <= p <= n-1 0) nth . string . 2.6.14 . --algo {bm|kmp} . (bm = Boyer-Moore kmp = Knuth-Pratt-Morris) --from offset ( ) . . --to offset offset ( ) pattern . . [!] --string pattern . [!] --hex-string pattern (hex) . --icase . : # . iptables -A INPUT -p tcp --dport 80 -m string --algo bm --string 'GET /index.html' -j LOG # |0D 0A| |0D0A|. iptables -p udp --dport 53 -m string --algo bm --from 40 --to 57 --hex-string '|03|www|09|netfilter|03|org|00|' : - (BM) . -- (KMP) . . (NIDS) KMP . -- (QoS) -- BM . tcp --protocol tcp : [!] --source-port,--sport port[:port] () . . ( ) first:last . <<0>> <<65535>> . --sport . [!] --destination-port,--dport port[:port] () . --dport . [!] --tcp-flags mask comp TCP . mask ( ) comp (set) . : 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 number (option) TCP . tcpmss TCP MSS ( ) TCP . TCP SYN SYN/ACK MSS (handshake) TCP . [!] --mss value[:value] TCP MSS. value value . time / . AND . UTC . --datestart YYYY[-MM[-DD[Thh[:mm[:ss]]]]] --datestop YYYY[-MM[-DD[Thh[:mm[:ss]]]]] "T" ISO 8601 . 1970-01-01T00:00:00 2038-01-19T04:17:07 . --datestart --datestop 1970-01-01 2038-01-19 . --timestart hh:mm[:ss] --timestop hh:mm[:ss] . 00:00:00 23:59:59 . ( "06:03") . [!] --monthdays day[,day...] . 1 31 . 31 . [!] --weekdays day[,day...] . : Mon Tue Wed Thu Fri Sat Sun 1 7. (Mo Tu ) . --contiguous --timestop --timestart . (EXAMPLES) . --kerneltz (kernel timezone) UTC . : UTC . . ( CMOS RTC x86) UTC . UTC (userspace) . (Local time) ( ) . TZ . . TZ UTC date(1) . TZ (DST) . UTC ( FAT) UTC ( ) . . . ntpd . +0000 . --kerneltz . (EXAMPLES): : -m time --weekdays Sa,Su () : -m time --datestart 2007-12-24 --datestop 2007-12-27 (inclusive) : -m time --datestart 2007-01-01T17:00 --datestop 2007-01-01T23:59:59 : -m time --timestart 12:30 --timestop 13:30 : -m time --weekdays Fr --monthdays 22,23,24,25,26,27,28 ( . << >> .) . : -m time --weekdays Mo --timestart 23:00 --timestop 01:00 : . ( << : >> ) --contiguous . tos Type of Service ( ) IPv4 ( "Precedence") (Priority - ) IPv6 . [!] --tos value[/mask] (mark) TOS. (mask) TOS AND . [!] --tos symbol tos IPv4 () . TOS iptables -m tos -h . 0x3F ( ECN). ttl (IPv4-specific) TTL ( Time To Live) IP . [!] --ttl-eq ttl TTL. --ttl-gt ttl TTL . --ttl-lt ttl TTL . u32 U32 . TCP (payload) . [!] --u32 tests . tests := location "=" value | tests "&&" location "=" value value := range | value "," range range := number | number ":" number n n:n . n:m >=n <=m . location := number | location operator number operator := "&" | "<<" | ">>" | "@" & << >> && C . = (syntax) . @ . (tests) : * <<=>> ( <<&&>>) u32 * ( ) (value) * ( ) (location) (location) . () : A char * IP B C : number B = number; C = (*(A+B)<<24) + (*(A+B+1)<<16) + (*(A+B+2)<<8) + *(A+B+3) &number C = C & number << number C = C << number >> number C = C >> number @number A = A + C; then do the instruction number [skb->data,skb->end] (fail) . C . (whitespace) . (quoting) () . : IP >= 256 IP (bytes 2-3). --u32 "0 & 0xFFFF = 0x100:0xFFFF" (bytes 0-3) 0xFFFF AND ( ) [0x100:0xFFFF] : ( ) ICMP icmp 0 ICMP () = --u32 "6 & 0xFF = 1 && ... & . (fragment) . ( .) : IP . ( ). . ... 4 & 0x3FFF = 0 && ... : IP ( type) . @ . IP ( IHL ) IP . ... 0 >> 22 & 0x3C @ 0 >> 24 = 0" >>22 . . &3C . IHL=5 IP ( x ) . ( ) xxxx0101 yyzzzzzz >>22 xxxx0101yy &3C 010100 . @ . (payload) ICMP ICMP ( ICMP type) . . : TCP ( TCP payload) TCP ( ICMP). --u32 "6 & 0xFF = 6 && ... (fragment) ( ). ... 0 >> 22 & 0x3C @ 12 >> 26 & 0x3C @ 8 = 1,2,5,8" 0>>22&3C IP . @ TCP . TCP ( ) TCP . 12>>26&3C ( IP ). "@" TCP . 8 = . udp --protocol udp : [!] --source-port,--sport port[:port] () . --source-port TCP . [!] --destination-port,--dport port[:port] () . --destination-port TCP . (TARGET EXTENSIONS) iptables . AUDIT (audit) . (accepted) (dropped) (rejected) . auditd(8) . --type {accept|drop|reject} . . . iptables . : iptables -N AUDIT_DROP iptables -A AUDIT_DROP -j AUDIT iptables -A AUDIT_DROP -j DROP CHECKSUM . mangle . --checksum-fill . DHCP (checksum offloads) . CLASSIFY skb->priority ( CBQ ). --set-class major:minor (major) (minor) . () 0x . CLUSTERIP (IPv4-specific) IP MAC (load balancer) . . CLUSTERIP cluster IPv4 . --new ClusterIP . ClusterIP . --hashmode mode (hashing) . sourceip sourceip-sourceport sourceip-sourceport-destport . --clustermac mac MAC ClusterIP . (link-layer multicast) . --total-nodes num . --local-node num . --hash-init rnd (seed) . CONNMARK (mark) . . --set-xmark value[/mask] mask value ctmark XOR . --save-mark [--nfmask nfmask] [--ctmask ctmask] (nfmark) (ctmark) . ctmark : ctmark = (ctmark & ~ctmask) ^ (nfmark & nfmask) ctmask nfmask nfmark ctmark XOR . ctmask nfmask 0xFFFFFFFF . --restore-mark [--nfmask nfmask] [--ctmask ctmask] (ctmark) (nfmark) . nfmark : nfmark = (nfmark & ~nfmask) ^ (ctmark & ctmask); nfmask ctmask ctmark nfmark XOR . ctmask nfmask 0xFFFFFFFF . --restore-mark mangle . (mnemonics) --set-xmark : --and-mark bits AND ctmark bits . ( --set-xmark 0/invbits invbits bits .) --or-mark bits OR ctmark bits . ( --set-xmark bits/bits.) --xor-mark bits XOR ctmark bits . ( --set-xmark bits/0.) --set-mark value[/mask] . . --save-mark [--mask mask] nfmark ctmark . . --restore-mark [--mask mask] ctmark nfmark . . mangle . CONNSECMARK ( ) ( ) . SECMARK security ( mangle ). --save . --restore . CT CT . <<>> (template) ct conntrack . <> . --notrack . --helper name (helper) name . conntrack . --ctevents event[,...] conntrack . : new related destroy reply assured protoinfo helper mark ( ctmark nfmark) natseqinfo secmark (ctsecmark). --expevents event[,...] (expectation) . : new. --zone-orig {id|mark} ORIGINAL () (zone) id . id mark nfmark . --zone-reply {id|mark} REPLY () id . id mark nfmark . --zone {id|mark} id . id mark nfmark . . . --timeout name (timeout) name . /proc/sys/net/netfilter/nf_conntrack_*_timeout_* . DNAT nat PREROUTING OUTPUT . ( ) . : --to-destination [ipaddr[-ipaddr]][:port[-port[/baseport]]] IP IP . tcp udp dccp sctp . . IP . baseport . (shifted portmap) . . baseport /etc/services . --random ( >= 2.6.22). --persistent / . SAME . 2.6.29-rc2 . IPv6 >= 3.7 . DNPT (IPv6-specific) IPv6--IPv6 (stateless destination IPv6-to-IPv6 Network Prefix Translation RFC 6296 ) . mangle nat. : --src-pfx [prefix/length] . --dst-pfx [prefix/length] . SNPT . : ip6tables -t mangle -I POSTROUTING -s fd00::/64 ! -o vboxnet0 -j SNPT --src-pfx fd00::/64 --dst-pfx 2001:e20:2000:40f::/64 ip6tables -t mangle -I PREROUTING -i wlan0 -d 2001:e20:2000:40f::/64 -j DNPT --src-pfx 2001:e20:2000:40f::/64 --dst-pfx fd00::/64 IPv6 : sysctl -w net.ipv6.conf.all.proxy_ndp=1 NOTRACK . DSCP DSCP TOS IPv4 . mangle . --set-dscp value DSCP ( ) . --set-dscp-class class DSCP DiffServ . ECN (IPv4-specific) ECN . mangle . --ecn-tcp-remove ECN TCP . -p tcp . HL (IPv6-specific) (Hop Limit) IPv6 . Hop Limit IPv4 TTL . Hop Limit . mangle . ! --hl-set value Hop Limit <> . --hl-dec value Hop Limit <> . --hl-inc value Hop Limit <> . HMARK MARK fwmark . . ICMP . : --hmark-tuple tuple : src ( IPv4 IPv6) dst ( IPv4 IPv6) sport (TCP UDP UDPlite SCTP DCCP) dport (TCP UDP UDPlite SCTP DCCP) spi Security Parameter Index ( AH ESP) ct conntrack . --hmark-mod value (must be > 0) (Modulus) ( ). --hmark-offset value . --hmark-tuple : --hmark-src-prefix cidr CIDR. --hmark-dst-prefix cidr CIDR. --hmark-sport-mask value . --hmark-dport-mask value . --hmark-spi-mask value spi. --hmark-proto-mask value . --hmark-rnd value . : iptables -t mangle -A PREROUTING -m conntrack --ctstate NEW -j HMARK --hmark-tuple ct,src,dst,proto --hmark-offset 10000 --hmark-mod 10 --hmark-rnd 0xfeedcafe iptables -t mangle -A PREROUTING -j HMARK --hmark-offset 10000 --hmark- tuple src,dst,proto --hmark-mod 10 --hmark-rnd 0xdeafbeef IDLETIMER (idle) . . ( ) . . sysfs . . xt_idletimer : /sys/class/xt_idletimer/timers/