postgresql (remote) connection refused
<p>My error:</p>

<pre><code># psql -U postgres -h 10.230.5.51
psql: could not connect to server: Connection refused
        Is the server running on host "10.230.5.51" and accepting
        TCP/IP connections on port 5432?
</code></pre>

<p>in postgresql.conf:</p>

<pre><code>listen_addresses = '*'
port = 5432                             # (change requires restart)
</code></pre>

<p>I have added the client server in pg_hba.conf (username/database replaced by X)</p>

<pre><code>host    X          X          10.230.5.21             md5
host    X          X          10.230.5.22             md5
</code></pre>

<p>Before I added those in the pg_hba.conf, it gave me this error:</p>

<pre><code># psql -U postgres -h 10.230.5.51
psql: FATAL:  no pg_hba.conf entry for host "10.230.5.22", user "X", database "X", SSL on
FATAL:  no pg_hba.conf entry for host "10.230.5.22", user "X", database "X", SSL off
</code></pre>

<p>So I assume the first steps I have taken are correct?</p>

<p>The last step I feel like I <em>may</em> be missing, could be iptables. they look like this:</p>

<pre><code>-A INPUT -i lo -j ACCEPT
-A INPUT -d 127.0.0.0/8 ! -i lo -j REJECT --reject-with icmp-port-unreachable
-A INPUT -s 10.230.4.0/22 -j LOCAL
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 8010 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 10443 -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -p gre -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-port-unreachable
-A LOCAL -p udp -m state --state NEW -m udp --dport 53 -j ACCEPT
-A LOCAL -p tcp -m state --state NEW -m tcp --dport 53 -j ACCEPT
-A LOCAL -p udp -m state --state NEW -m udp --dport 123 -j ACCEPT
-A LOCAL -p tcp -m state --state NEW -m tcp --dport 2181 -j ACCEPT
-A LOCAL -p tcp -m state --state NEW -m tcp --dport 2888 -j ACCEPT
-A LOCAL -p tcp -m state --state NEW -m tcp --dport 3888 -j ACCEPT
-A LOCAL -p tcp -m state --state NEW -m tcp --dport 5432 -j ACCEPT
-A LOCAL -p tcp -m state --state NEW -m tcp --dport 7000 -j ACCEPT
-A LOCAL -p tcp -m state --state NEW -m tcp --dport 7001 -j ACCEPT
-A LOCAL -p tcp -m state --state NEW -m tcp --dport 9042 -j ACCEPT
-A LOCAL -p tcp -m state --state NEW -m tcp --dport 9160 -j ACCEPT
</code></pre>

<p>Is the iptables ok? I can see that port 5432 is on the list. Is the connection being refused by another rule before that? iptable commands are weird.</p>

<p><strong>General information</strong>:</p>

<p>Both computers are running linux. I did not originally setup the database. The database is running fine, but only locally, even though this happened when running the command on the server with postgres database:</p>

<pre><code># psql -U postgres -h localhost
psql: could not connect to server: Connection refused
        Is the server running on host "localhost" (::1) and accepting
        TCP/IP connections on port 5432?
could not connect to server: Connection refused
        Is the server running on host "localhost" (127.0.0.1) and accepting
        TCP/IP connections on port 5432?
</code></pre>