
로컬 IP에 CentOS 7을 설치하면 다른 로컬 IP에 CentOS 7을 설치할 192.168.1.6
수 있으 려면 어떤 구체적인 변경이 필요합니까 ?telnet
192.168.1.5
보시다시피, 다음과 같이 192.168.1.6
PING을 할 수 있습니다 :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
그러나 telnet
FROM 192.168.1.6
TO는 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
telnet
FROM 192.168.1.6
TO port 5432
at 도 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
ping
그리고 위의 telnet
명령 을 실행하기 전에 PostgreSQL을 다시 시작하고 systemctl restart postgresql
.
마찬가지로 위 명령을 실행하기 전에 ping
다음 telnet
방화벽 규칙도 만들었습니다 192.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에서 다음 텔넷을 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의 제안:
On 에서 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
대체되었습니다 . iptables
firewalld
ss -rn
90라인의 출력을 생성했습니다. 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
입력 192.168.1.6
을 통해 두 시스템 모두에서 방화벽을 제거했습니다. 그런 다음 다음과 같이 두 가지 제거를 모두 확인했습니다. yum remove firewalld
yum 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
다음으로 on을 입력 192.168.1.5
하고 telnet 192.168.1.5 5432
on을 입력했습니다 192.168.1.6
.
텔넷 결과 다음과 같은 거부 메시지가 인쇄되었습니다 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.5
telnet
1.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이 수신 대기 중인지 여부를 확인하기 위해 port 5432
다음 두 명령을 입력했습니다 192.168.1.5
.
참고하세요firewalld
iptables
다음 명령이 실행되는 동안 둘 다 여전히 제거됩니다 .:
먼저 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.5
port 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
두 번째 문제는 각 호스트에 방화벽 규칙이 있어서배 밖으로5432/tcp로의 트래픽. (그리고 아마도 다른 포트도 마찬가지일 것 입니다 .) 오류 메시지 "호스트에 대한 경로 없음" iptables --j REJECT
은 OUTPUT
. --reject-with icmp-host-prohibited
다음은 그러한 규칙을 생성하는 예입니다.
iptables -I OUTPUT -p tcp --dport 5432 -j REJECT --reject-with icmp-host-prohibited
이는 성공했기 때문에 경로가 명확하게 존재 ping
하지만 telnet
세션이 실패하는 상황을 만족시킵니다. 체인에 대한 규칙을 나열하려고 시도하는 명령 iptables --line-numbers -nvL
이 아닌 명령을 사용하여 이를 직접 확인할 수 있습니다 .iptables -Ln
n
트래픽이 실제로 설정될 수 있는지 확인하기 위한 두 가지 임시 수정 사항은 다음과 같습니다.
- 두 시스템 모두에서 방화벽을 완전히 비활성화합니다.
-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 방화벽 도구에 대해 완전한 솔루션을 제공할 만큼 충분히 익숙하지 않습니다. 제가 직접 조사해 볼 수도 있고 다른 사람이 해당 정보를 제공하기 위해 이 답변을 편집하고 싶을 수도 있습니다.