포트 전달 VBox VM [닫기]

포트 전달 VBox VM [닫기]

일부 컴퓨터에는 VirtualBox를 실행하는 Ubuntu Server 14.04가 있습니다. 이 머신에는 OpenStack Fuel이 설치되어 있으며 인프라의 NIC 인터페이스(호스트 2개와 NAT 1개)를 변경할 수 없습니다.

머신 중 하나가 "연료 제어" 패널을 실행하고 있지만 호스트 인터페이스(10.20.0.2) 중 하나를 통해서만 액세스할 수 있습니다.

내 홈 네트워크는 192.168.25.x입니다. 호스트(Ubuntu) 외부에서는 192.168.25.25입니다.

이제 홈 네트워크에 Windows 컴퓨터가 있고 가상 머신(IP 10.20.0.2)에서 실행되는 연료 패널에 액세스해야 합니다.

필요한 것은 하드웨어 192.168.25.25 인터페이스에서 들어오는 것을 virtualbox 호스트 전용 10.20.0.X VM 인터페이스로 전달하여 IP 10.20.0.2에 도달하는 것입니다.

이것은 모든 인터페이스를 보여주는 내 호스트 ifconfig입니다.

root@AKRAB:~# ifconfig
lo        Link encap:Loopback Local
          inet end.: 127.0.0.1  Masc:255.0.0.0
          endereço inet6: ::1/128 Escopo:Máquina
          UP LOOPBACK RUNNING  MTU:65536  Métrica:1
          pacotes RX:19685 erros:0 descartados:0 excesso:0 quadro:0
          Pacotes TX:19685 erros:0 descartados:0 excesso:0 portadora:0
          colisões:0 txqueuelen:0
          RX bytes:7674590 (7.6 MB) TX bytes:7674590 (7.6 MB)

vboxnet0  Link encap:Ethernet  Endereço de HW 0a:00:27:00:00:00
          inet end.: 10.20.0.1  Bcast:10.20.0.255  Masc:255.255.255.0
          endereço inet6: fe80::800:27ff:fe00:0/64 Escopo:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Métrica:1
          pacotes RX:0 erros:0 descartados:0 excesso:0 quadro:0
          Pacotes TX:167 erros:0 descartados:0 excesso:0 portadora:0
          colisões:0 txqueuelen:1000
          RX bytes:0 (0.0 B) TX bytes:22260 (22.2 KB)

vboxnet1  Link encap:Ethernet  Endereço de HW 0a:00:27:00:00:01
          inet end.: 172.16.0.254  Bcast:172.16.0.255  Masc:255.255.255.0
          endereço inet6: fe80::800:27ff:fe00:1/64 Escopo:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Métrica:1
          pacotes RX:0 erros:0 descartados:0 excesso:0 quadro:0
          Pacotes TX:437 erros:0 descartados:0 excesso:0 portadora:0
          colisões:0 txqueuelen:1000
          RX bytes:0 (0.0 B) TX bytes:137886 (137.8 KB)

vboxnet2  Link encap:Ethernet  Endereço de HW 0a:00:27:00:00:02
          inet end.: 172.16.1.1  Bcast:172.16.1.255  Masc:255.255.255.0
          endereço inet6: fe80::800:27ff:fe00:2/64 Escopo:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Métrica:1
          pacotes RX:0 erros:0 descartados:0 excesso:0 quadro:0
          Pacotes TX:464 erros:0 descartados:0 excesso:0 portadora:0
          colisões:0 txqueuelen:1000
          RX bytes:0 (0.0 B) TX bytes:150336 (150.3 KB)

wlan0     Link encap:Ethernet  Endereço de HW 00:13:46:94:18:c1
          inet end.: 192.168.25.25  Bcast:192.168.25.255  Masc:255.255.255.0
          endereço inet6: fe80::213:46ff:fe94:18c1/64 Escopo:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Métrica:1
          pacotes RX:2354945 erros:0 descartados:4 excesso:0 quadro:0
          Pacotes TX:1237088 erros:0 descartados:0 excesso:0 portadora:0
          colisões:0 txqueuelen:1000
          RX bytes:3455421823 (3.4 GB) TX bytes:103231994 (103.2 MB)

root@AKRAB:~#

wlan0 외부 인터페이스(내 홈 네트워크)와 vboxnet0이 내가 액세스하려는 네트워크(10.20.0.2)를 숨기는 것을 볼 수 있습니다.

대상을 포함하여 이러한 모든 주소는 정적입니다. 가상 머신에서 접속하려는 포트 번호는 8443(Mirantis Fuel Dashboard)입니다.

성공하지 못한 채 이것을 시도했습니다.

root@AKRAB:~# iptables -I FORWARD -d 10.20.0.2 -m comment --comment "Accept to forward Fuel DashBoard traffic" -m tcp -p tcp --dport 8443 -j ACCEPT
root@AKRAB:~# iptables -t nat -I PREROUTING -m tcp -p tcp --dport 8443 -m comment --comment "redirect pkts to virtual machine" -j DNAT --to-destination 10.20.0.2:8443
root@AKRAB:~# iptables -t nat -I POSTROUTING -m comment --comment "NAT the src ip" -d 10.20.0.2 -o vboxnet0 -j MASQUERADE

결과:

root@AKRAB:~# iptables -nvL FORWARD
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 ACCEPT     tcp  --  *      *       10.20.0.2            0.0.0.0/0            /* Accept to forward Fuel DashBoard return traffic */ tcp spt:8443
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            10.20.0.2            /* Accept to forward Fuel DashBoard traffic */ tcp dpt:8443

그리고

root@AKRAB:~# iptables -t nat -nvL
Chain PREROUTING (policy ACCEPT 73 packets, 6145 bytes)
 pkts bytes target     prot opt in     out     source               destination
   18   912 DNAT       tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:8443 /* redirect pkts to virtual machine */ to:10.20.0.2:8443

Chain INPUT (policy ACCEPT 73 packets, 6145 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 759 packets, 47828 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain POSTROUTING (policy ACCEPT 759 packets, 47828 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 MASQUERADE  all  --  *      vboxnet0  0.0.0.0/0            10.20.0.2            /* NAT the src ip */

답변1

iptables 규칙은 괜찮은 것 같지만 IP 전달 활성화를 놓쳤을 수도 있습니다. 다음을 사용해 보세요.

echo 1 > /proc/sys/net/ipv4/ip_forward

그런 다음 iptables 규칙이 일치하는지 확인하십시오.

iptables -t nat -nvL
iptables -nvL FORWARD

관련 정보