Port forward from external postgresql to localhost












0















I have several databases hosted outside the application server, ex:
DB instances:



192.168.178.21:5432
192.168.178.22:5432
192.168.178.23:5432


app-server: 192.168.178.11



now I want to forward the external dbs to ports 5431-5433
and be able to connect with psql to localhost:



psql -h 127.0.0.1 -p 5432 -U <user> -d <db>


I get:



psql: could not connect to server: Connection refused
Is the server running on host "127.0.0.1" and accepting
TCP/IP connections on port 5432?


services on this server are only allowed to connect to localhost, additionally these ports will be forwarded with ssh.



I tried firewalld masquerade:



firewall-cmd --zone=internal --add-masquerade --permanent
firewall-cmd --zone=internal --add-forward-port=port=5432:proto=tcp:toport=5432:toaddr=192.168.178.22 --permanent
firewall-cmd --reload


Any ideas? (I've cowered several manuals, including CentOS, Fedora and Redhat intros)










share|improve this question



























    0















    I have several databases hosted outside the application server, ex:
    DB instances:



    192.168.178.21:5432
    192.168.178.22:5432
    192.168.178.23:5432


    app-server: 192.168.178.11



    now I want to forward the external dbs to ports 5431-5433
    and be able to connect with psql to localhost:



    psql -h 127.0.0.1 -p 5432 -U <user> -d <db>


    I get:



    psql: could not connect to server: Connection refused
    Is the server running on host "127.0.0.1" and accepting
    TCP/IP connections on port 5432?


    services on this server are only allowed to connect to localhost, additionally these ports will be forwarded with ssh.



    I tried firewalld masquerade:



    firewall-cmd --zone=internal --add-masquerade --permanent
    firewall-cmd --zone=internal --add-forward-port=port=5432:proto=tcp:toport=5432:toaddr=192.168.178.22 --permanent
    firewall-cmd --reload


    Any ideas? (I've cowered several manuals, including CentOS, Fedora and Redhat intros)










    share|improve this question

























      0












      0








      0








      I have several databases hosted outside the application server, ex:
      DB instances:



      192.168.178.21:5432
      192.168.178.22:5432
      192.168.178.23:5432


      app-server: 192.168.178.11



      now I want to forward the external dbs to ports 5431-5433
      and be able to connect with psql to localhost:



      psql -h 127.0.0.1 -p 5432 -U <user> -d <db>


      I get:



      psql: could not connect to server: Connection refused
      Is the server running on host "127.0.0.1" and accepting
      TCP/IP connections on port 5432?


      services on this server are only allowed to connect to localhost, additionally these ports will be forwarded with ssh.



      I tried firewalld masquerade:



      firewall-cmd --zone=internal --add-masquerade --permanent
      firewall-cmd --zone=internal --add-forward-port=port=5432:proto=tcp:toport=5432:toaddr=192.168.178.22 --permanent
      firewall-cmd --reload


      Any ideas? (I've cowered several manuals, including CentOS, Fedora and Redhat intros)










      share|improve this question














      I have several databases hosted outside the application server, ex:
      DB instances:



      192.168.178.21:5432
      192.168.178.22:5432
      192.168.178.23:5432


      app-server: 192.168.178.11



      now I want to forward the external dbs to ports 5431-5433
      and be able to connect with psql to localhost:



      psql -h 127.0.0.1 -p 5432 -U <user> -d <db>


      I get:



      psql: could not connect to server: Connection refused
      Is the server running on host "127.0.0.1" and accepting
      TCP/IP connections on port 5432?


      services on this server are only allowed to connect to localhost, additionally these ports will be forwarded with ssh.



      I tried firewalld masquerade:



      firewall-cmd --zone=internal --add-masquerade --permanent
      firewall-cmd --zone=internal --add-forward-port=port=5432:proto=tcp:toport=5432:toaddr=192.168.178.22 --permanent
      firewall-cmd --reload


      Any ideas? (I've cowered several manuals, including CentOS, Fedora and Redhat intros)







      port-forwarding firewalld






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 1 hour ago









      Mihail GershkovichMihail Gershkovich

      313




      313






















          1 Answer
          1






          active

          oldest

          votes


















          0














          It depends how is the postgresql pg_hba.conf configured and whether the postgresql server listen on IP addresses you've listed.



          Otherwise If You can ssh to those servers You can use ssh port forwarding -L option in ssh(1)
          example:



          ssh user@192.168.178.21 -L 5431:localhost:5432 -f
          ssh user@192.168.178.22 -L 5432:localhost:5432 -f
          ssh user@192.168.178.23 -L 5433:localhost:5432 -f


          You can achieve the same with following ~/.ssh/config



          Host db1
          Hostname 192.168.178.21
          LocalForward localhost:5431 localhost:5432

          Host db2
          Hostname 192.168.178.22
          LocalForward localhost:5432 localhost:5432

          Host db3
          Hostname 192.168.178.23
          LocalForward localhost:5433 localhost:5432


          and then just



          ssh -f db1
          ssh -f db2
          ssh -f db3





          share|improve this answer























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "106"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f501718%2fport-forward-from-external-postgresql-to-localhost%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            It depends how is the postgresql pg_hba.conf configured and whether the postgresql server listen on IP addresses you've listed.



            Otherwise If You can ssh to those servers You can use ssh port forwarding -L option in ssh(1)
            example:



            ssh user@192.168.178.21 -L 5431:localhost:5432 -f
            ssh user@192.168.178.22 -L 5432:localhost:5432 -f
            ssh user@192.168.178.23 -L 5433:localhost:5432 -f


            You can achieve the same with following ~/.ssh/config



            Host db1
            Hostname 192.168.178.21
            LocalForward localhost:5431 localhost:5432

            Host db2
            Hostname 192.168.178.22
            LocalForward localhost:5432 localhost:5432

            Host db3
            Hostname 192.168.178.23
            LocalForward localhost:5433 localhost:5432


            and then just



            ssh -f db1
            ssh -f db2
            ssh -f db3





            share|improve this answer




























              0














              It depends how is the postgresql pg_hba.conf configured and whether the postgresql server listen on IP addresses you've listed.



              Otherwise If You can ssh to those servers You can use ssh port forwarding -L option in ssh(1)
              example:



              ssh user@192.168.178.21 -L 5431:localhost:5432 -f
              ssh user@192.168.178.22 -L 5432:localhost:5432 -f
              ssh user@192.168.178.23 -L 5433:localhost:5432 -f


              You can achieve the same with following ~/.ssh/config



              Host db1
              Hostname 192.168.178.21
              LocalForward localhost:5431 localhost:5432

              Host db2
              Hostname 192.168.178.22
              LocalForward localhost:5432 localhost:5432

              Host db3
              Hostname 192.168.178.23
              LocalForward localhost:5433 localhost:5432


              and then just



              ssh -f db1
              ssh -f db2
              ssh -f db3





              share|improve this answer


























                0












                0








                0







                It depends how is the postgresql pg_hba.conf configured and whether the postgresql server listen on IP addresses you've listed.



                Otherwise If You can ssh to those servers You can use ssh port forwarding -L option in ssh(1)
                example:



                ssh user@192.168.178.21 -L 5431:localhost:5432 -f
                ssh user@192.168.178.22 -L 5432:localhost:5432 -f
                ssh user@192.168.178.23 -L 5433:localhost:5432 -f


                You can achieve the same with following ~/.ssh/config



                Host db1
                Hostname 192.168.178.21
                LocalForward localhost:5431 localhost:5432

                Host db2
                Hostname 192.168.178.22
                LocalForward localhost:5432 localhost:5432

                Host db3
                Hostname 192.168.178.23
                LocalForward localhost:5433 localhost:5432


                and then just



                ssh -f db1
                ssh -f db2
                ssh -f db3





                share|improve this answer













                It depends how is the postgresql pg_hba.conf configured and whether the postgresql server listen on IP addresses you've listed.



                Otherwise If You can ssh to those servers You can use ssh port forwarding -L option in ssh(1)
                example:



                ssh user@192.168.178.21 -L 5431:localhost:5432 -f
                ssh user@192.168.178.22 -L 5432:localhost:5432 -f
                ssh user@192.168.178.23 -L 5433:localhost:5432 -f


                You can achieve the same with following ~/.ssh/config



                Host db1
                Hostname 192.168.178.21
                LocalForward localhost:5431 localhost:5432

                Host db2
                Hostname 192.168.178.22
                LocalForward localhost:5432 localhost:5432

                Host db3
                Hostname 192.168.178.23
                LocalForward localhost:5433 localhost:5432


                and then just



                ssh -f db1
                ssh -f db2
                ssh -f db3






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 33 mins ago









                Jakub JindraJakub Jindra

                1267




                1267






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f501718%2fport-forward-from-external-postgresql-to-localhost%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Histoire des bourses de valeurs

                    Why is there Russian traffic in my log files?

                    Rename multiple files to decrement number in file name?