2

In my pg_hba.conf, I need a single user to be allowed to connect from two completely different IP addresses (like work and home, for example).

Something like the following would be really nice:

host    all    my_awesome_user    151.123.45.67/0, 72.11.12.13/0    md5

Putting adding two entries (one for each IP doesn't work: postgres just sees the first entry, which ether matches or doesn't and completely ignores the second entry.

Any help would be appreciated.

  • 1
    '/0' matches all addresses. Do you really have '/32' ? In any event, only one range per line is allowed. – jjanes Jan 20 '18 at 6:27
3

Putting adding two entries (one for each IP doesn't work: postgres just sees the first entry, which ether matches or doesn't and completely ignores the second entry.

I don't believe that's true. PostgreSQL won't match it if the address is wrong, from the docs on pg_hba.conf

Each record specifies a connection type, a client IP address range (if relevant for the connection type), a database name, a user name, and the authentication method to be used for connections matching these parameters. The first record with a matching connection type, client address, requested database, and user name is used to perform authentication. There is no “fall-through” or “backup”: if one record is chosen and the authentication fails, subsequent records are not considered. If no record matches, access is denied.

If the client's address does not match, it continues looking for one that does.

  • 1
    Yes, you are correct. I don't know why it didn't work before. – cutmancometh Feb 7 '18 at 6:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.