포트 전달을 사용하여 Oracle VM Virtualbox에서 웹 서버를 실행하는 중에 문제 발생

포트 전달을 사용하여 Oracle VM Virtualbox에서 웹 서버를 실행하는 중에 문제 발생

저는 Oracle VM VirtualBox를 사용하고 있으며 CentOS 7 인스턴스를 실행하고 있습니다. 이 컴퓨터에 두 개의 네트워크 어댑터를 설정했습니다. 하나는 Host Only 모드로 설정되어 있고 다른 하나는 NAT 모드로 설정되어 있습니다. VM에 SSH로 연결할 수 있습니다. 이제 이 VM에서 웹 서버도 실행하고 있으며 동일한 방식으로 액세스하려고 합니다. 하지만 이런 식으로는 작동하지 않습니다. 나는 다른 규칙(호스트의 포트 3000, 게스트의 포트 80)으로도 시도했습니다.

호스트에서는 포트 12000, 게스트에서는 포트 80입니다.

호스트의 호스트:3000에 동일한 IP가 있고 게스트의 정확한 IP:포트가 있습니다.

호스트에는 IP 및 포트 3000이 없고 게스트에는 정확한 IP:포트가 있습니다.

작동하지 않습니다. 호스트에서 VM으로 또는 그 반대로 핑을 보낼 수도 있습니다. VM 서버 내부에서 Apache HTTPD 구성을 테스트했습니다.

저는 Lynx를 사용하여 사이트에 액세스했는데 그것도 작동하지만 VM 내에서만 작동합니다. 기계 외부나 호스트 OS 외부에서는 발생하지 않습니다.

호스트에서 게스트로의 PING 출력-

C:\Users\apandey>ping 192.168.56.101

Pinging 192.168.56.101 with 32 bytes of data:
Reply from 192.168.56.101: bytes=32 time<1ms TTL=64
Reply from 192.168.56.101: bytes=32 time<1ms TTL=64
Reply from 192.168.56.101: bytes=32 time=1ms TTL=64
Reply from 192.168.56.101: bytes=32 time<1ms TTL=64

Ping statistics for 192.168.56.101:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 0ms, Maximum = 1ms, Average = 0ms

게스트 네트워크 연결-

[root@phsita phsita_]# ip addr
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: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:35:35:5b brd ff:ff:ff:ff:ff:ff
    inet 10.0.2.15/24 brd 10.0.2.255 scope global dynamic enp0s3
       valid_lft 63341sec preferred_lft 63341sec
    inet6 fe80::a49c:d796:6e85:93a3/64 scope link
       valid_lft forever preferred_lft forever
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:fa:0c:03 brd ff:ff:ff:ff:ff:ff
    inet 192.168.56.101/24 brd 192.168.56.255 scope global enp0s8
       valid_lft forever preferred_lft forever
    inet6 fe80::552d:c3b3:245a:ca7d/64 scope link
       valid_lft forever preferred_lft forever

게스트 내에서 컬-

[root@phsita phsita_]# cat /var/www/html/index.html
It worked. This is a test page running on Apache HTTPD.
[root@phsita phsita_]# curl localhost
It worked. This is a test page running on Apache HTTPD.

CentOS VM의 iptables 구성은 다음과 같습니다.

[root@phsita phsita_]# iptables -L -n

Chain INPUT (policy ACCEPT)    
target     prot opt source               destination    
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED    
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0    
INPUT_direct  all  --  0.0.0.0/0            0.0.0.0/0    
INPUT_ZONES_SOURCE  all  --  0.0.0.0/0            0.0.0.0/0   
INPUT_ZONES  all  --  0.0.0.0/0            0.0.0.0/0    
DROP       all  --  0.0.0.0/0            0.0.0.0/0            ctstate INVALID   
REJECT     all  --  0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited    
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:80    

Chain FORWARD (policy ACCEPT)    
target     prot opt source               destination    
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED    
ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0    
FORWARD_direct  all  --  0.0.0.0/0            0.0.0.0/0    
FORWARD_IN_ZONES_SOURCE  all  --  0.0.0.0/0            0.0.0.0/0    
FORWARD_IN_ZONES  all  --  0.0.0.0/0            0.0.0.0/0    
FORWARD_OUT_ZONES_SOURCE  all  --  0.0.0.0/0            0.0.0.0/0    
FORWARD_OUT_ZONES  all  --  0.0.0.0/0            0.0.0.0/0    
DROP       all  --  0.0.0.0/0            0.0.0.0/0            ctstate INVALID    
REJECT     all  --  0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited    

Chain OUTPUT (policy ACCEPT)    
target     prot opt source               destination    
OUTPUT_direct  all  --  0.0.0.0/0            0.0.0.0/0

CentOS VM의 Netstat 출력은 다음과 같습니다.

Active Internet connections (servers and established)    
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      5777/httpd
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1059/sshd
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1379/master
tcp        0      0 0.0.0.0:5666            0.0.0.0:*               LISTEN      6702/nrpe   
tcp        0      0 192.168.56.101:22       192.168.56.1:50997      ESTABLISHED 8059/sshd: root@not   
tcp        0     36 192.168.56.101:22       192.168.56.1:50996      ESTABLISHED 8054/sshd: root@pts   
tcp6       0      0 :::22                   :::*                    LISTEN      1059/sshd   
tcp6       0      0 ::1:25                  :::*                    LISTEN      1379/master   
tcp6       0      0 :::5666                 :::*                    LISTEN      6702/nrpe 
udp        0      0 127.0.0.1:323           0.0.0.0:*                           619/chronyd   
udp      768      0 10.0.2.15:42450         10.100.1.21:53          ESTABLISHED 9559/ping   
udp        0      0 0.0.0.0:15961           0.0.0.0:*                           8008/dhclient   
udp        0      0 0.0.0.0:68              0.0.0.0:*                           8008/dhclient   
udp6       0      0 ::1:323                 :::*                                619/chronyd   
udp6       0      0 :::9882                 :::*                                8008/dhclient

나의포트 포워딩 규칙다음과 같다-

Name     Protocol Host IP  Host Port    Guest IP  Guest Port
HTTPD        TCP                50000                   80
SSHD Rule    TCP                 2222                   22

내 호스트 Windows 시스템의 Netstat 응답은 다음과 같습니다.

C:\Windows\system32>netstat -antb | findstr 50000
  TCP    0.0.0.0:50000          0.0.0.0:0              LISTENING

호스트에서 게스트 URL로 요청하는 동안 TCPDUMP 캡처된 패킷-

[root@phsita phsita_]# tcpdump -v -i enp0s8 port 80
tcpdump: listening on enp0s8, link-type EN10MB (Ethernet), capture size 65535 bytes
17:08:00.255009 IP (tos 0x0, ttl 128, id 8851, offset 0, flags [DF], proto TCP (6), length 52)
    82693-t430.corp.abc.com.58114 > phsita.http: Flags [S], cksum 0xca36 (correct), seq 2879587372, win 8192, options [mss 1460,nop,wscale 8,nop,nop,sackOK], length 0
17:08:00.505569 IP (tos 0x0, ttl 128, id 8853, offset 0, flags [DF], proto TCP (6), length 52)
    82693-t430.corp.abc.com.58115 > phsita.http: Flags [S], cksum 0xc579 (correct), seq 1429233499, win 8192, options [mss 1460,nop,wscale 8,nop,nop,sackOK], length 0
17:08:03.254847 IP (tos 0x0, ttl 128, id 8855, offset 0, flags [DF], proto TCP (6), length 52)
    82693-t430.corp.abc.com.58114 > phsita.http: Flags [S], cksum 0xca36 (correct), seq 2879587372, win 8192, options [mss 1460,nop,wscale 8,nop,nop,sackOK], length 0
17:08:03.505192 IP (tos 0x0, ttl 128, id 8857, offset 0, flags [DF], proto TCP (6), length 52)
    82693-t430.corp.abc.com.58115 > phsita.http: Flags [S], cksum 0xc579 (correct), seq 1429233499, win 8192, options [mss 1460,nop,wscale 8,nop,nop,sackOK], length 0
17:08:09.255273 IP (tos 0x0, ttl 128, id 8859, offset 0, flags [DF], proto TCP (6), length 48)
    82693-t430.corp.abc.com.58114 > phsita.http: Flags [S], cksum 0xde45 (correct), seq 2879587372, win 8192, options [mss 1460,nop,nop,sackOK], length 0
17:08:09.505718 IP (tos 0x0, ttl 128, id 8861, offset 0, flags [DF], proto TCP (6), length 48)
    82693-t430.corp.abc.com.58115 > phsita.http: Flags [S], cksum 0xd988 (correct), seq 1429233499, win 8192, options [mss 1460,nop,nop,sackOK], length 0
17:08:21.507198 IP (tos 0x0, ttl 128, id 8863, offset 0, flags [DF], proto TCP (6), length 52)
    82693-t430.corp.abc.com.58119 > phsita.http: Flags [S], cksum 0x9a4d (correct), seq 4194231732, win 8192, options [mss 1460,nop,wscale 8,nop,nop,sackOK], length 0
17:08:24.507418 IP (tos 0x0, ttl 128, id 8865, offset 0, flags [DF], proto TCP (6), length 52)
    82693-t430.corp.abc.com.58119 > phsita.http: Flags [S], cksum 0x9a4d (correct), seq 4194231732, win 8192, options [mss 1460,nop,wscale 8,nop,nop,sackOK], length 0
17:08:30.507292 IP (tos 0x0, ttl 128, id 8867, offset 0, flags [DF], proto TCP (6), length 48)
    82693-t430.corp.abc.com.58119 > phsita.http: Flags [S], cksum 0xae5c (correct), seq 4194231732, win 8192, options [mss 1460,nop,nop,sackOK], length 0

누구든지 도와주세요. 나는 여기서 일을 정말 중요한 것으로 만들려고 노력하고 있는데 이것은 네트워킹에만 충격을 받는 매우 어리석은 상황입니다.

도와주세요.

고마워요.

답변1

실제로 차단하는 것은 방화벽 자체였습니다.

TCP 포트 80에 대한 INPUT 체인에 규칙을 추가했지만 여전히 CentOS 7의 iptables의 광범위한 기본 구성으로 인해 일부 다른 체인의 일부 규칙이 VM에서 외부로의 트래픽을 차단하고 있었습니다.

방금 방화벽을 중지하여 시도했는데 이제 작동 중입니다.

관련 정보