プライベート IP またはポートに Telnet を接続できません。

プライベート IP またはポートに Telnet を接続できません。

ローカルIPのCentOS 7インストールが他のローカルIPの他のCentOS 7インストールにインストールされる192.168.1.6ように、具体的にどのような変更が必要ですか?telnet192.168.1.5

ご覧のとおり、次のように 192.168.1.6PINGを実行できます。192.168.1.5

[root@localhost /]# ping 192.168.1.5
PING 192.168.1.5 (192.168.1.5) 56(84) bytes of data.
64 bytes from 192.168.1.5: icmp_seq=1 ttl=64 time=0.515 ms
64 bytes from 192.168.1.5: icmp_seq=2 ttl=64 time=0.565 ms
^C
--- 192.168.1.5 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.515/0.540/0.565/0.025 ms

ただし、telnetFROM 192.168.1.6TOは192.168.1.5次のように失敗します。

[root@localhost /]# telnet 192.168.1.5
Trying 192.168.1.5...
telnet: connect to address 192.168.1.5: No route to host

telnetFROM 192.168.1.6TO port 5432atも192.168.1.5以下のように失敗します。

[root@localhost /]# telnet 192.168.1.5:5432
telnet: 192.168.1.5:5432: Name or service not known
192.168.1.5:5432: Unknown host
[root@localhost /]#

PostgreSQLが実行されてい192.168.1.5ますtelnet 192.168.1.5:5432。だからpg_hba.conf上記のコードを実行する前に、次の行を追加しました。

host    all    all    192.168.1.6/24    trust

上記のコマンドを実行しますpingtelnetsystemctl restart postgresql

同様に、上記のコマンドを実行する前に、次のファイアウォールルールも作成しましpingた。 telnet192.168.1.5

[root@localhost ~]# firewall-cmd --zone=public --add-port=5432/tcp
[root@localhost ~]# firewall-cmd --permanent --zone=trusted --add-source=192.168.1.6/32
[root@localhost ~]# firewall-cmd --reload  

port 5432また、端末に次のコマンドを入力してPostgreSQLが実行されていることを確認しました192.168.1.5

[root@localhost ~]# ss -l -n | grep 5432
u_str  LISTEN     0      128    /var/run/postgresql/.s.PGSQL.5432 71466                 * 0
u_str  LISTEN     0      128    /tmp/.s.PGSQL.5432 71468                 * 0
tcp    LISTEN     0      128    127.0.0.1:5432                  *:*
tcp    LISTEN     0      128     ::1:5432                 :::*
[root@localhost ~]#


@roaimaの提案:

@roaimaの提案に従って次のことを試しましたが、まだ接続できません。

192.168.1.6 で以下を送信しました。

[root@localhost ~]# telnet 192.168.1.5 5432
Trying 192.168.1.5...
telnet: connect to address 192.168.1.5: No route to host

192.168.1.5では、tcpdump受信側への要求は次telnetのとおりです。

[root@localhost ~]# tcpdump -i eth0 port 5432 or arp
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
16:52:49.309526 IP 192.168.1.6.53328 > localhost.localdomain.postgres: Flags [S], seq 3210933916, win 29200, options [mss 1460,sackOK,TS val 629624820 ecr 0,nop,wscale 7], length 0
16:52:54.312716 ARP, Request who-has localhost.localdomain tell 192.168.1.6, length 28
16:52:54.312750 ARP, Reply localhost.localdomain is-at 52:54:00:ef:35:18 (oui Unknown), length 28
^C
3 packets captured
4 packets received by filter
0 packets dropped by kernel  

同様に、192.168.1.6 では、次の Telnet を IP レベルにのみ送信します。

[root@localhost ~]# telnet 192.168.1.5
Trying 192.168.1.5...
telnet: connect to address 192.168.1.5: No route to host
[root@localhost ~]#

192.168.1.5では、tcpdump受信側への要求は次telnetのとおりです。

[root@localhost ~]# tcpdump -i eth0 port 5432 or arp
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
//THESE 2 LINES PRINTED BEFORE 2ND TELNET WAS RUN: 16:58:11.619638 ARP, Request who-has gateway tell localhost.localdomain, length 28
//THESE 2 LINES PRINTED BEFORE 2ND TELNET WAS RUN: 16:58:11.619940 ARP, Reply gateway is-at b8:ec:a3:11:74:6e (oui Unknown), length 46
16:58:35.555570 ARP, Request who-has 192.168.1.6 tell localhost.localdomain, length 28
16:58:35.555753 ARP, Reply 192.168.1.6 is-at 52:54:00:ab:31:40 (oui Unknown), length 28
^C
4 packets captured
4 packets received by filter
0 packets dropped by kernel
[root@localhost ~]#  


@cutrightjmの提案:

上記では192.168.1.5、Puttyセッションに次のように入力しました。

[root@localhost ~]# telnet localhost 5432
Trying ::1...
Connected to localhost.
Escape character is '^]'.

また、別々のPuttyセッションでは、次の192.168.1.5結果は表示されませんtcpdump

[root@localhost ~]# tcpdump -i eth0 port 5432 or arp
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
^C
0 packets captured
0 packets received by filter
0 packets dropped by kernel
[root@localhost ~]#


@ JeffSchallerの提案:

@ JeffSchallerの提案に従ってこの作業を行っています192.168.1.6。これはCentOS 7で、netstat次にss置き換えられました。 iptablesfirewalld

ss -rn90ラインの出力が生成されました。grep投稿に追加できる量で出力を減らすために意味のあるフィルタやその他のフィルタを提案できますか?

[root@localhost ~]# iptables -Ln
iptables: No chain/target/match by that name.


[root@localhost ~]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0
  sources:
  services: dhcpv6-client ssh
  ports: 8080/tcp
  protocols:
  masquerade: no
  forward-ports:
  sourceports:
  icmp-blocks:
  rich rules:

[root@localhost ~]#

また、次のコマンドを実行しました192.168.1.6

[root@localhost ~]# ip route
default via 192.168.1.1 dev eth0  proto static  metric 100
192.168.1.0/24 dev eth0  proto kernel  scope link  src 192.168.1.6  metric 100

[root@localhost ~]# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 52:54:00:ab:31:40 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.6/24 brd 192.168.1.255 scope global dynamic eth0
       valid_lft 133013sec preferred_lft 133013sec
    inet6 fe80::5054:ff:feab:3140/64 scope link
       valid_lft forever preferred_lft forever
[root@localhost ~]#


両方のコンピュータからファイアウォールを削除します。

極端なテストでは、両方のコンピュータ192.168.1.5で と と入力して両方のコンピュータのファイアウォールを削除しました。その後、次のように2つの削除を確認しました。 192.168.1.6yum remove firewalldyum remove iptables

存在する192.168.1.5

[root@localhost ~]# systemctl status firewalld
Unit firewalld.service could not be found.
[root@localhost ~]# iptables -L -n
-bash: /sbin/iptables: No such file or directory

存在する192.168.1.6

[root@localhost ~]# systemctl status firewalld
Unit firewalld.service could not be found.
[root@localhost ~]# iptables -L -n
-bash: /sbin/iptables: No such file or directory

次へを入力tcpdump -i eth0 port 5432 or arpし、192.168.1.5次にtelnet 192.168.1.5 5432入力します192.168.1.6

Telnetの結果は、次の拒否メッセージです192.168.1.6

[root@localhost ~]# telnet 192.168.1.5 5432
Trying 192.168.1.5...
telnet: connect to address 192.168.1.5: Connection refused
[root@localhost ~]#

一方、通話のtcpdump結果は次のとおりです。192.168.1.5telnet1.6

[root@localhost ~]# tcpdump -i eth0 port 5432 or arp
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
10:25:11.349238 ARP, Request who-has localhost.localdomain tell gateway, length 46
10:25:11.349261 ARP, Reply localhost.localdomain is-at 52:54:00:ef:35:18 (oui Unknown), length 28
10:25:14.391222 IP 192.168.1.6.53344 > localhost.localdomain.postgres: Flags [S], seq 3043089625, win 29200, options [mss 1460,sackOK,TS val 692769902 ecr 0,nop,wscale 7], length 0
10:25:14.391265 IP localhost.localdomain.postgres > 192.168.1.6.53344: Flags [R.], seq 0, ack 3043089626, win 0, length 0
10:25:19.395578 ARP, Request who-has 192.168.1.6 tell localhost.localdomain, length 28
10:25:19.396039 ARP, Reply 192.168.1.6 is-at 52:54:00:ab:31:40 (oui Unknown), length 28
^C
6 packets captured
6 packets received by filter
0 packets dropped by kernel
[root@localhost ~]#

PostgreSQLがリッスンしていることを確認するために、次の2つのport 5432コマンドを入力しました192.168.1.5

気づくfirewalldiptables次のコマンドを実行すると、両方とも削除されます。:

pg_hba.confまず、ファイルを見て192.168.1.5信頼できるルールを見つけました192.168.1.6

[root@localhost ~]# vi /var/lib/pgsql/data/pg_hba.conf
# LOTS OF # COMMENTED LINES OMITTED HERE FOR BREVITY
# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
host    all             all             192.168.1.6/24          trust
# IPv6 local connections:
host    all             all             ::1/128                 trust

次に、ルールがあるかどうかを確認するために、次のnetstatコマンドを入力しました。 192.168.1.5port 5432

[root@localhost ~]# netstat -anpt | grep LISTEN
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      943/sshd
tcp        0      0 127.0.0.1:5432          0.0.0.0:*               LISTEN      25166/postgres
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1483/master
tcp6       0      0 127.0.0.1:45228         :::*                    LISTEN      19089/java
tcp6       0      0 127.0.0.1:8020          :::*                    LISTEN      14338/java
tcp6       0      0 :::7990                 :::*                    LISTEN      19089/java
tcp6       0      0 :::22                   :::*                    LISTEN      943/sshd
tcp6       0      0 ::1:5432                :::*                    LISTEN      25166/postgres
tcp6       0      0 127.0.0.1:7992          :::*                    LISTEN      19066/java
tcp6       0      0 ::1:7992                :::*                    LISTEN      19066/java
tcp6       0      0 ::1:25                  :::*                    LISTEN      1483/master
tcp6       0      0 127.0.0.1:36122         :::*                    LISTEN      19089/java
tcp6       0      0 :::8095                 :::*                    LISTEN      14338/java
tcp6       0      0 :::5701                 :::*                    LISTEN      19089/java
[root@localhost ~]#

ベストアンサー1

最初の問題は、誤ったコマンド構文を使用していることですtelnet。実行すると、man telnet構文は次のようになります。

telnet <host> [<port>]

したがって、あなたの場合は、以下を実行する必要があります。

telnet 192.168.1.5 5432

2番目の問題は、各ホストにファイアウォールルールがあるため、これを防ぐことができることです。国を離れる5432/tcp へのトラフィック。 (他のポートがある可能性があります。)以下は、これらのルールを作成する例ですiptables --j REJECTOUTPUT--reject-with icmp-host-prohibited

iptables -I OUTPUT -p tcp --dport 5432 -j REJECT --reject-with icmp-host-prohibited

これは、パスがはっきりと存在するが成功によってpingセッションが失敗する状況に適しています。これは、チェーンのルールを一覧表示したいコマンドではなく、コマンドを使用して直接確認telnetできます。iptables --line-numbers -nvLiptables -Lnn

トラフィックが実際に確立できることを確認するための2つの一時的な修正は次のとおりです。

  • 両方のシステムでファイアウォールを完全に無効にします。
  • 両方のシステムでこれら2つのコマンドを実行します(-I後でに置き換えて削除できます-D)。

    iptables -I INPUT -p tcp --src 192.168.1.5/30 -j ACCEPT
    iptables -I OUTPUT -p tcp --dst 192.168.1.5/30 -j ACCEPT
    

私は完全なソリューションを提供するのに十分なCentOS 7ファイアウォールツールに(まだ)十分に慣れていません。私は自分で調べてみたり、他の人がこの情報を提供するためにこの回答を編集したいと思うかもしれません。

おすすめ記事