I have Postgres running on my windows machine and I need to connect to it from inside WSL2.
- The postgres windows service is running
- I can connect to it from the windows command line using
psql
- The IP of the WSL2 vm is
172.31.210.120
, netmask255.255.240.0
(determined usingipfconfig
). - The IP of the windows host from inside the vm is
172.31.208.1
(determined usingcat /etc/resolv.conf
) - I can connect to a simple web server running on the host from the vm with
curl http://172.31.208.1:8080
. If I log the IP of the incoming requests, I get172.31.210.120
so this verifies that both IPs are correct. - I added the following line to
pg_hba.conf
:host all all 172.31.210.120/20 scram-sha-256
- I restarted the postgres windows service
If I try to connect to it from WSL using the following command:
$ psql --host=172.31.208.1 --port=5432 --user=postgres
I get this error:
psql: error: could not connect to server: could not connect to server: Connection timed out
Is the server running on host "172.31.208.1" and accepting
TCP/IP connections on port 5432?
NOTE: I also tried to test the connection using telnet
but it failed too.
The logs under c:\Program Files\PostgreSQL\13\data\log\
show no errors or any signs that there was a connection attempt.
What am I missing here?