80
80
A record is made
81
81
up of a number of fields which are separated by spaces and/or tabs.
82
82
Fields can contain white space if the field value is quoted.
83
- Quoting one of the keywords in a database or user name field (e.g.,
83
+ Quoting one of the keywords in a database, user, or address field (e.g.,
84
84
<literal>all</> or <literal>replication</>) makes the word lose its special
85
- character, and just match a database or user with that name.
85
+ character, and just match a database, user, or host with that name.
86
86
</para>
87
87
88
88
<para>
101
101
A record can have one of the seven formats
102
102
<synopsis>
103
103
local <replaceable>database</replaceable> <replaceable>user</replaceable> <replaceable>auth-method</replaceable> <optional><replaceable>auth-options</replaceable></optional>
104
- host <replaceable>database</replaceable> <replaceable>user</replaceable> <replaceable>CIDR- address</replaceable> <replaceable>auth-method</replaceable> <optional><replaceable>auth-options</replaceable></optional>
105
- hostssl <replaceable>database</replaceable> <replaceable>user</replaceable> <replaceable>CIDR- address</replaceable> <replaceable>auth-method</replaceable> <optional><replaceable>auth-options</replaceable></optional>
106
- hostnossl <replaceable>database</replaceable> <replaceable>user</replaceable> <replaceable>CIDR- address</replaceable> <replaceable>auth-method</replaceable> <optional><replaceable>auth-options</replaceable></optional>
104
+ host <replaceable>database</replaceable> <replaceable>user</replaceable> <replaceable>address</replaceable> <replaceable>auth-method</replaceable> <optional><replaceable>auth-options</replaceable></optional>
105
+ hostssl <replaceable>database</replaceable> <replaceable>user</replaceable> <replaceable>address</replaceable> <replaceable>auth-method</replaceable> <optional><replaceable>auth-options</replaceable></optional>
106
+ hostnossl <replaceable>database</replaceable> <replaceable>user</replaceable> <replaceable>address</replaceable> <replaceable>auth-method</replaceable> <optional><replaceable>auth-options</replaceable></optional>
107
107
host <replaceable>database</replaceable> <replaceable>user</replaceable> <replaceable>IP-address</replaceable> <replaceable>IP-mask</replaceable> <replaceable>auth-method</replaceable> <optional><replaceable>auth-options</replaceable></optional>
108
108
hostssl <replaceable>database</replaceable> <replaceable>user</replaceable> <replaceable>IP-address</replaceable> <replaceable>IP-mask</replaceable> <replaceable>auth-method</replaceable> <optional><replaceable>auth-options</replaceable></optional>
109
109
hostnossl <replaceable>database</replaceable> <replaceable>user</replaceable> <replaceable>IP-address</replaceable> <replaceable>IP-mask</replaceable> <replaceable>auth-method</replaceable> <optional><replaceable>auth-options</replaceable></optional>
@@ -218,13 +218,17 @@ hostnossl <replaceable>database</replaceable> <replaceable>user</replaceable>
218
218
</varlistentry>
219
219
220
220
<varlistentry>
221
- <term><replaceable>CIDR- address</replaceable></term>
221
+ <term><replaceable>address</replaceable></term>
222
222
<listitem>
223
223
<para>
224
- Specifies the client machine IP address range that this record
225
- matches. This field contains an IP address in standard dotted decimal
226
- notation and a <acronym>CIDR</> mask length. (IP addresses can only be
227
- specified numerically, not as domain or host names.) The mask
224
+ Specifies the client machine addresses that this record
225
+ matches. This field can contain either a host name, an IP
226
+ address range, or one of the special key words mentioned below.
227
+ </para>
228
+
229
+ <para>
230
+ An IP address is specified in standard dotted decimal
231
+ notation with a <acronym>CIDR</> mask length. The mask
228
232
length indicates the number of high-order bits of the client
229
233
IP address that must match. Bits to the right of this must
230
234
be zero in the given IP address.
@@ -233,14 +237,7 @@ hostnossl <replaceable>database</replaceable> <replaceable>user</replaceable>
233
237
</para>
234
238
235
239
<para>
236
- Instead of a <replaceable>CIDR-address</replaceable>, you can write
237
- <literal>samehost</literal> to match any of the server's own IP
238
- addresses, or <literal>samenet</literal> to match any address in any
239
- subnet that the server is directly connected to.
240
- </para>
241
-
242
- <para>
243
- Typical examples of a <replaceable>CIDR-address</replaceable> are
240
+ Typical examples of an IP address range specified this way are
244
241
<literal>172.20.143.89/32</literal> for a single host, or
245
242
<literal>172.20.143.0/24</literal> for a small network, or
246
243
<literal>10.6.0.0/16</literal> for a larger one.
@@ -259,6 +256,67 @@ hostnossl <replaceable>database</replaceable> <replaceable>user</replaceable>
259
256
support for IPv6 addresses.
260
257
</para>
261
258
259
+ <para>
260
+ You can also write
261
+ <literal>samehost</literal> to match any of the server's own IP
262
+ addresses, or <literal>samenet</literal> to match any address in any
263
+ subnet that the server is directly connected to.
264
+ </para>
265
+
266
+ <para>
267
+ If a host name is specified (anything that is not an IP address
268
+ or a special key word is processed as a potential host name),
269
+ that name is compared with the result of a reverse name
270
+ resolution of the client's IP address (e.g., reverse DNS
271
+ lookup, if DNS is used). Host name comparisons are case
272
+ insensitive. If there is a match, then a forward name
273
+ resolution (e.g., forward DNS lookup) is performed on the host
274
+ name to check whether any of the addresses it resolves to are
275
+ equal to the client's IP address. If both directions match,
276
+ then the entry is considered to match. (The host name that is
277
+ used in <filename>pg_hba.conf</filename> should be the one that
278
+ address-to-name resolution of the client's IP address returns,
279
+ otherwise the line won't be matched. Some host name databases
280
+ allow associating an IP address with multiple host names, but
281
+ the operating system will only return one host name when asked
282
+ to resolve an IP address.)
283
+ </para>
284
+
285
+ <para>
286
+ When host names are specified
287
+ in <filename>pg_hba.conf</filename>, you should make sure that
288
+ name resolution is reasonably fast. It can be of advantage to
289
+ set up a local name resolution cache such
290
+ as <command>nscd</command>. Also, you may wish to enable the
291
+ configuration parameter <varname>log_hostname</varname> to see
292
+ the client's host name instead of the IP address in the log.
293
+ </para>
294
+
295
+ <sidebar>
296
+ <para>
297
+ Occasionally, users have wondered why host names are handled
298
+ in this seemingly complicated way with two name resolutions
299
+ and requiring reverse lookup of IP addresses, which is
300
+ sometimes not set up or points to some undesirable host name.
301
+ It is primarily for efficiency: A connection attempt requires
302
+ two resolver lookups of the current client's address. If
303
+ there is resolver problem with that address, it becomes only
304
+ that client's problem. A hypothetical alternative
305
+ implementation which only does forward lookups would have to
306
+ resolve every host name mentioned in
307
+ <filename>pg_hba.conf</filename> at every connection attempt.
308
+ That would already be slow by itself. And if there is a
309
+ resolver problem with one of the host names, it becomes
310
+ everyone's problem.
311
+ </para>
312
+
313
+ <para>
314
+ Note that this behavior is consistent with other popular
315
+ implementations of host name-based access control, such as the
316
+ Apache HTTP Server and TCP Wrappers.
317
+ </para>
318
+ </sidebar>
319
+
262
320
<para>
263
321
This field only applies to <literal>host</literal>,
264
322
<literal>hostssl</literal>, and <literal>hostnossl</> records.
@@ -511,30 +569,40 @@ hostnossl <replaceable>database</replaceable> <replaceable>user</replaceable>
511
569
# any database user name using Unix-domain sockets (the default for local
512
570
# connections).
513
571
#
514
- # TYPE DATABASE USER CIDR- ADDRESS METHOD
572
+ # TYPE DATABASE USER ADDRESS METHOD
515
573
local all all trust
516
574
517
575
# The same using local loopback TCP/IP connections.
518
576
#
519
- # TYPE DATABASE USER CIDR- ADDRESS METHOD
577
+ # TYPE DATABASE USER ADDRESS METHOD
520
578
host all all 127.0.0.1/32 trust
521
579
522
580
# The same as the previous line, but using a separate netmask column
523
581
#
524
582
# TYPE DATABASE USER IP-ADDRESS IP-MASK METHOD
525
583
host all all 127.0.0.1 255.255.255.255 trust
526
584
585
+ # The same over IPv6.
586
+ #
587
+ # TYPE DATABASE USER ADDRESS METHOD
588
+ host all all ::1/128 trust
589
+
590
+ # The same using a host name (would typically cover both IPv4 and IPv6).
591
+ #
592
+ # TYPE DATABASE USER ADDRESS METHOD
593
+ host all all localhost trust
594
+
527
595
# Allow any user from any host with IP address 192.168.93.x to connect
528
596
# to database "postgres" as the same user name that ident reports for
529
597
# the connection (typically the operating system user name).
530
598
#
531
- # TYPE DATABASE USER CIDR- ADDRESS METHOD
599
+ # TYPE DATABASE USER ADDRESS METHOD
532
600
host postgres all 192.168.93.0/24 ident
533
601
534
602
# Allow any user from host 192.168.12.10 to connect to database
535
603
# "postgres" if the user's password is correctly supplied.
536
604
#
537
- # TYPE DATABASE USER CIDR- ADDRESS METHOD
605
+ # TYPE DATABASE USER ADDRESS METHOD
538
606
host postgres all 192.168.12.10/32 md5
539
607
540
608
# In the absence of preceding "host" lines, these two lines will
@@ -543,7 +611,7 @@ host postgres all 192.168.12.10/32 md5
543
611
# on the Internet. The zero mask causes no bits of the host IP
544
612
# address to be considered, so it matches any host.
545
613
#
546
- # TYPE DATABASE USER CIDR- ADDRESS METHOD
614
+ # TYPE DATABASE USER ADDRESS METHOD
547
615
host all all 192.168.54.1/32 reject
548
616
host all all 0.0.0.0/0 krb5
549
617
@@ -553,7 +621,7 @@ host all all 0.0.0.0/0 krb5
553
621
# connection is allowed if there is an entry in pg_ident.conf for map
554
622
# "omicron" that says "bryanh" is allowed to connect as "guest1".
555
623
#
556
- # TYPE DATABASE USER CIDR- ADDRESS METHOD
624
+ # TYPE DATABASE USER ADDRESS METHOD
557
625
host all all 192.168.0.0/16 ident map=omicron
558
626
559
627
# If these are the only three lines for local connections, they will
@@ -563,7 +631,7 @@ host all all 192.168.0.0/16 ident map=omicro
563
631
# $PGDATA/admins contains a list of names of administrators. Passwords
564
632
# are required in all cases.
565
633
#
566
- # TYPE DATABASE USER CIDR- ADDRESS METHOD
634
+ # TYPE DATABASE USER ADDRESS METHOD
567
635
local sameuser all md5
568
636
local all @admins md5
569
637
local all +support md5
0 commit comments