Debianでポートを開けない

Debianでポートを開けない

私はDebianをインストールしています

~$ cat /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/

PostgreSQLをインストールした場所

 PostgreSQL 11.3 (Debian 11.3-1.pgdg90+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516, 64-bit

PostgreSQLは実行中ですが、別のマシンから使用できます。firewalld経由で5432ポートを開きました。

# firewall-cmd --zone=public --list-ports
8443/tcp 5432/tcp

しかし、それは機能しません。

これは地元では

~$ telnet localhost 5432
Trying ::1...
Connected to localhost.
Escape character is '^]'.

これは私のマシンからのものです(別のVLAN上)

:> telnet 192.168.13.183 5432
Trying 192.168.13.183...
telnet: Unable to connect to remote host: Connection refused

これは別のマシンからのものです(Debianと同じVLAN内)

telnet 192.168.13.183 5432
Trying 192.168.13.183...
telnet: connect to address 192.168.13.183: Connection refused

そこで、firewalld をオフにしてみましたが (テストのためだけに)、結果は同じでした。その後、iptables を使って同じことを試してみました:

iptables -A INPUT -p tcp --dport 5432 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -p tcp --sport 5432 -m conntrack --ctstate ESTABLISHED -j ACCEPT

結果は同じです。ここで何が欠けているのでしょうか?

これをチェックしてください(ありがとう@トーマス):

netstat -tulpan | grep postgres
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      6386/postgres       
tcp6       0      0 ::1:5432                :::*                    LISTEN      6386/postgres       
udp6       0      0 ::1:44652               ::1:44652               ESTABLISHED 6386/postgres

lsof -n -i:5432
COMMAND   PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
postgres 6386 postgres    3u  IPv6  72390      0t0  TCP [::1]:postgresql (LISTEN)
postgres 6386 postgres    5u  IPv4  72391      0t0  TCP 127.0.0.1:postgresql (LISTEN

答え1

postgresqlデフォルトではlocalhostのみをリッスンします(127.0.0.1そして::1postgresql.conf)。この動作を変更するには、 (通常は )にある他のリスニング アドレスを で手動で設定する必要があります$PGDATA

たとえば、postgres がローカル アドレス 10.0.10.156 でも listen するようにするには、listen_addresses次のように指定する必要があります。

listen_addresses = 'localhost, 10.0.10.156'

postgres がすべてのインターフェースで listen するようにするには、ワイルドカードを使用することもできます。

listen_addresses = '*'

この変更後、postgres を再起動する必要があります。また、結果が期待どおりであるかどうかを確認することをお勧めします。


lsofローカルホストと 10.0.10.156 でリッスンしている postgresの出力。

# lsof -n -i:5432
COMMAND   PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
postgres 7893 postgres    3u  IPv6  55868      0t0  TCP [::1]:postgres (LISTEN)
postgres 7893 postgres    4u  IPv4  55869      0t0  TCP 127.0.0.1:postgres (LISTEN)
postgres 7893 postgres    5u  IPv4  55870      0t0  TCP 10.0.10.156:postgres (LISTEN)

lsofすべてのインターフェースでリッスンしている postgresの出力。

# lsof -n -i:5432
COMMAND   PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
postgres 7527 postgres    3u  IPv4  54903      0t0  TCP *:postgres (LISTEN)
postgres 7527 postgres    4u  IPv6  54904      0t0  TCP *:postgres (LISTEN)

関連情報