CIDR_TABLE(5)
π cidr_table β the vibe of Postfix CIDR tables π
okay so bestie. welcome to cidr_table, aka the File Formats Manual page about how Postfix does CIDR lookup tables. it's giving "networking but make it cute" and honestly? we're obsessed. let's get into it β¨
πΈ SYNOPSIS πΈ
postmap -q "string" cidr:/etc/postfix/filename
postmap -q - cidr:/etc/postfix/filename <inputfile
that's it. that's the whole vibe. two commands and you're that girl π
π¦ DESCRIPTION π¦
so the Postfix mail system uses optional lookup tables, right? and normally those tables are in lmdb:, cdb:, hash:, or dbm: format. classic. love that for them.
but β and this is the main character moment β lookup tables can also be specified in CIDR form, which stands for Classless Inter-Domain Routing. in that case, every input gets compared against a list of patterns. the moment a match is found, the corresponding result gets returned and the search is terminated. no further searching, we said what we said, periodt π
wanna know what types of lookup tables your Postfix system supports? run the "postconf -m" command, bestie.
and to actually test lookup tables, use the "postmap -q" command, exactly like the SYNOPSIS above shows you. easy peasy π
β¨ TABLE FORMAT β¨
the general form of a Postfix CIDR table goes a lil something like this:
pattern resultβ when a search string matches the specified pattern, use the corresponding result value. the pattern must be innetwork/prefixornetwork_addressform (peep ADDRESS PATTERN SYNTAX below for the deets).!pattern resultβ when a search string does not match the specified pattern, use the specified result value. the pattern must be innetwork/prefixornetwork_addressform (again, see ADDRESS PATTERN SYNTAX below).
this feature is available in Postfix 3.2 and later.
if pattern/endifβ when a search string matches the specified pattern, match that search string against the patterns betweenifandendif. the pattern must be innetwork/prefixornetwork_addressform (yep, ADDRESS PATTERN SYNTAX). and theif..endifblocks can nest. πͺ
Note: do not prepend whitespace to text between if..endif. i'm so serious, bestie. do not. π
this feature is available in Postfix 3.2 and later.
if !pattern/endifβ when a search string does not match the specified pattern, match that search string against the patterns betweenifandendif. the pattern must be innetwork/prefixornetwork_addressform (you know the drill β ADDRESS PATTERN SYNTAX). theif..endifcan nest. π«
Note: do not prepend whitespace to text between if..endif. same rule, still iconic, still non-negotiable. π
this feature is available in Postfix 3.2 and later.
- blank lines and comments β empty lines and whitespace-only lines are ignored, and so are lines whose first non-whitespace character is a
#. live your truth, leave comments, we support you. π - multi-line text β a logical line starts with non-whitespace text. a line that starts with whitespace continues a logical line. that's the rule, no cap. π§
π₯ TABLE SEARCH ORDER π₯
patterns are applied in the order as specified in the table, until a pattern is found that matches the search string. so basically: order matters, bestie. first match wins, and then we're done. π
π ADDRESS PATTERN SYNTAX π
Postfix CIDR tables are pattern-based. a pattern is either:
- a
network_address, which requires an exact match, or - a
network_address/prefix_length, where theprefix_lengthpart specifies the length of thenetwork_addressprefix that must be matched β and the other bits in thenetwork_addresspart must be zero.
an IPv4 network address is a sequence of four decimal octets separated by ".", and an IPv6 network address is a sequence of three to eight hexadecimal octet pairs separated by ":" or "::", where the latter is short-hand for a sequence of one or more all-zero octet pairs. the pattern 0.0.0.0/0 matches every IPv4 address, and ::/0 matches every IPv6 address. IPv6 support is available in Postfix 2.2 and later. π
before comparisons are made, lookup keys and table entries are converted from string to binary. therefore, IPv6 patterns will be matched regardless of leading zeros (a leading zero in an IPv4 address octet indicates octal notation). fun fact, keep it in your back pocket. π
Note: address information may be enclosed inside "[]" but this form is not required. do with that what you will. π
π INLINE SPECIFICATION π
the contents of a table may be specified in the table name (Postfix 3.7 and later). the basic syntax is:
main.cf:
parameter = .. cidr:{ { rule-1 }, { rule-2 } .. } ..
master.cf:
.. -o { parameter = .. cidr:{ { rule-1 }, { rule-2 } .. } .. } ..
Postfix recursively expands any $parametername instances in the above parameter value, ignores whitespace after '{' and before '}', and writes each rule as one text line to an in-memory file:
in-memory file:
rule-1
rule-2
..
Postfix then parses the result as if it is a file in /etc/postfix. iconic behaviour honestly. πΈ
Note: if a rule contains$, specify$$to keep Postfix from trying to do$nameexpansion as it evaluates a parameter value. don't skip this one bestie, it'll getcha. π
π EXAMPLE SMTPD ACCESS MAP π
/etc/postfix/main.cf:
smtpd_client_restrictions = ... cidr:/etc/postfix/client.cidr ...
/etc/postfix/client.cidr:
# Rule order matters. Put more specific allowlist entries
# before more general denylist entries.
192.168.1.1 OK
192.168.0.0/16 REJECT
2001:db8::1 OK
2001:db8::/32 REJECT
see how the specific stuff goes first? that's the whole trick. main character energy from the allowlist. π₯
π¦ SEE ALSO π¦
postmap(1), Postfix lookup table managerregexp_table(5), format of regular expression tablespcre_table(5), format of PCRE tables
π README FILES π
use "postconf readme_directory" or "postconf html_directory" to locate this information.
DATABASE_README, Postfix lookup table overview
β HISTORY β
CIDR table support was introduced with Postfix version 2.1. a classic. a pioneer. we stan. π«Ά
π AUTHOR(S) π
the CIDR table lookup code was originally written by:
Jozsef Kadlecsik
KFKI Research Institute for Particle and Nuclear Physics
POB. 49
1525 Budapest, Hungary
Adopted and adapted by:
Wietse Venema
IBM T.J. Watson Research
P.O. Box 704
Yorktown Heights, NY 10598, USA
Wietse Venema
Google, Inc.
111 8th Avenue
New York, NY 10011, USA
and that's the whole page bestie!! this was the cidr_table(5) page from the File Formats Manual, and you absolutely ate it. go forth and CIDR responsibly. no cap. π
β¨ππ¦π
π¦ where this page comes from
- alpine 3.24: postfix-doc 3.11.7-r0 Β· IPL-1.0 EPL-2.0
- arch rolling: postfix 3.11.7-1 Β· EPL-2.0 OR IPL-1.0 AND BSD-4-Clause-UC
- nixos 26.05: postfix 3.11.7
- nixpkgs unstable: postfix 3.11.7
- ubuntu stonking: postfix 3.11.7-1ubuntu2
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms