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は実行中ですが、他のコンピュータで使用できます。ファイアウォールを介して5432 porを開きました。

# 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

だから(テスト用に)ファイアウォールを消しましたが、結果は同じでした。その後、私は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そして::1)。この動作を変更するには、通常、他のpostgresql.conf受信アドレスを手動で設定する必要があります$PGDATA

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

listen_addresses = 'localhost, 10.0.10.156'

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

listen_addresses = '*'

このように変更したら、Postgresを再起動する必要があります。また、結果があなたの期待と一致していることを確認することをお勧めします。


lsoflocalhostおよび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)

lsofpostgres はすべてのインターフェイスで出力を受け取ります。

# 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)

おすすめ記事