Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configure PostgreSQL to work for only LOCALHOST or specified ip + port [closed]

Tags:

I want to configure PostgreSQL to accept connections only from a specified IP. It should not accept requests from any other IP.

like image 894
Ankur Loriya Avatar asked Aug 01 '12 05:08

Ankur Loriya


People also ask

How do I enable port 5432?

As an alternative you can go to Control Panel -> Systems and Security -> Windows Firewall -> Allow a program or feature through Windows Firewall -> Advanced Settings -> New Rule: Rule Type: Port. TCP or UDP: TCP. Specific local ports: 5432.

What ports need to be open for PostgreSQL?

The PostgreSQL database service is available on localhost and the default PostgreSQL port is 5432 .

How do I connect to PostgreSQL localhost?

You can also connect to PostgreSQL database using pgAdmin GUI application. Connect to the database at localhost:5432 using the user name postgres and the password supplied. Now, double click on PostgreSQL 9.4 under the "Servers Groups". pgAdmin will ask you for a password.


2 Answers

The following pg_hba.conf allows local and specified Ip have privilege login, but reject others。

# TYPE  DATABASE        USER            ADDRESS                 METHOD local   all             all                                     trust host    testdb          testuser      192.168.1.1/32             md5 host    all             all           0.0.0.0/0                 reject  
like image 170
francs Avatar answered Oct 15 '22 09:10

francs


The easiest way is to make PostgreSQL listen only on localhost for incoming connections. The relevant parameter is listen_addresses in postgresql.conf. The doc is here.

like image 40
A.H. Avatar answered Oct 15 '22 10:10

A.H.