AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / unix / 问题 / 523857
Accepted
maniat1k
maniat1k
Asked: 2019-06-10 08:17:11 +0800 CST2019-06-10 08:17:11 +0800 CST 2019-06-10 08:17:11 +0800 CST

无法在 Debian 上打开端口

  • 772

我有一个 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

结果相同我在这里缺少什么?

只需检查一下(感谢@thomas):

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
debian iptables
  • 1 1 个回答
  • 1410 Views

1 个回答

  • Voted
  1. Best Answer
    Thomas
    2019-06-10T08:34:54+08:002019-06-10T08:34:54+08:00

    postgresql默认情况下只监听本地主机(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。我还建议检查结果是否符合您的期望。


    lsof使用在 localhost 和 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)
    
    • 3

相关问题

  • GRUB 配置以识别同一 Linux 发行版的不同桌面环境(安装)

  • astyle 不会更改源文件格式

  • 接收有关全新 Debian 的电子邮件

  • Debian Stretch:libgs_plugin_systemd-updates.so 中的 gnome-software 段错误

  • 如何在拼音输入法中输入ü?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    模块 i915 可能缺少固件 /lib/firmware/i915/*

    • 3 个回答
  • Marko Smith

    无法获取 jessie backports 存储库

    • 4 个回答
  • Marko Smith

    如何将 GPG 私钥和公钥导出到文件

    • 4 个回答
  • Marko Smith

    我们如何运行存储在变量中的命令?

    • 5 个回答
  • Marko Smith

    如何配置 systemd-resolved 和 systemd-networkd 以使用本地 DNS 服务器来解析本地域和远程 DNS 服务器来解析远程域?

    • 3 个回答
  • Marko Smith

    dist-upgrade 后 Kali Linux 中的 apt-get update 错误 [重复]

    • 2 个回答
  • Marko Smith

    如何从 systemctl 服务日志中查看最新的 x 行

    • 5 个回答
  • Marko Smith

    Nano - 跳转到文件末尾

    • 8 个回答
  • Marko Smith

    grub 错误:你需要先加载内核

    • 4 个回答
  • Marko Smith

    如何下载软件包而不是使用 apt-get 命令安装它?

    • 7 个回答
  • Martin Hope
    user12345 无法获取 jessie backports 存储库 2019-03-27 04:39:28 +0800 CST
  • Martin Hope
    Carl 为什么大多数 systemd 示例都包含 WantedBy=multi-user.target? 2019-03-15 11:49:25 +0800 CST
  • Martin Hope
    rocky 如何将 GPG 私钥和公钥导出到文件 2018-11-16 05:36:15 +0800 CST
  • Martin Hope
    Evan Carroll systemctl 状态显示:“状态:降级” 2018-06-03 18:48:17 +0800 CST
  • Martin Hope
    Tim 我们如何运行存储在变量中的命令? 2018-05-21 04:46:29 +0800 CST
  • Martin Hope
    Ankur S 为什么 /dev/null 是一个文件?为什么它的功能不作为一个简单的程序来实现? 2018-04-17 07:28:04 +0800 CST
  • Martin Hope
    user3191334 如何从 systemctl 服务日志中查看最新的 x 行 2018-02-07 00:14:16 +0800 CST
  • Martin Hope
    Marko Pacak Nano - 跳转到文件末尾 2018-02-01 01:53:03 +0800 CST
  • Martin Hope
    Kidburla 为什么真假这么大? 2018-01-26 12:14:47 +0800 CST
  • Martin Hope
    Christos Baziotis 在一个巨大的(70GB)、一行、文本文件中替换字符串 2017-12-30 06:58:33 +0800 CST

热门标签

linux bash debian shell-script text-processing ubuntu centos shell awk ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve