input license here

Configure PostgreSQL to allow remote connections

Prepare a centos7 operating system with PostgreSQL Database installed. If not, see here.



  1. Configure the postgresql.conf . file

    Find the path containing the file postgresql.conf
    #find / -name “postgresql.conf


    Access the path and edit the file like so
    #vi /var/lib/pgsql/11/data/postgresql.conf

    find the line #listening_addresses=’localhost’ , #port=5432 and adjusted like a star
    listening_addresses=’*’
    port=5432


    '*' means it will listen on all ip addresses if you want to listen with 1 or several ip addresses, you can replace the * sign with the ip address you want, each ip separated by comma


  2. Configuration file pg_hba.conf

    Find the file path pg_hba.conf

    #find / -name “pg_hba.conf”

    Access the path and edit the file like so
    # vi /var/lib/pgsql/11/data/pg_hba.conf

    Add the following line at the end of the file
    host all all 0.0.0.0/0 md5 –> all ip addresses can connect to postgresql.

    (md5 is the password authentication mode, if you don't want to authenticate with a password, then replace it md5 is equal to trust).
    host all 103.121.88.143/24 md5 –> only allow ip addresses in range 192.168.3.12/24

  3. Firewall configuration on centos7
    Open port 5432 on centos7's firewalld firewall
    #firewall-cmd –zone=public –add-port=5432/tcp –permanent
    #firewall-cmd –relead

    Check if the port is open
    firewall-cmd –zone=public –list-port
    Allow to add wan ip address on firewalld firewall to allow ip to connect remotely (get wan ip address) here).
    #firewall-cmd –permanent –zone=public –add-source=192.168.100.1
    #firewall-cmd –relead

    Check to see if it has been added
    #firewall-cmd –zone=public –list-all

  4. Login to check
    Here use another vps with ip like in the file settings pg_hba.conf to test the connection to postgresql server configured by me trust So when you log in, you don't need to confirm the password.


Good luck
Thanh Tung


The post Configuring PostgreSQL to allow remote connections appeared first on BKNS.VN.

Related Posts
Diệp Quân
Nguyen Manh Cuong is the author and founder of the vmwareplayerfree blog. With over 14 years of experience in Online Marketing, he now runs a number of successful websites, and occasionally shares his experience & knowledge on this blog.
SHARE

Related Posts

Subscribe to get free updates

Post a Comment

Sticky