Encaminhamento de porta para VM usando firewalld

1

Eu tenho procurado e não consegui encontrar nada sobre como resolver esse problema. Eu estou tentando configurar o encaminhamento de porta para uma VM (qemu) em um servidor do CentOS 7.

  • Amarrando-se para encaminhar qualquer entrada de 8050 para 192.168.100.50:8080.
  • Tentei usar o firewall-config e pesquisei por toda a web por vários dias.

Não consigo encontrar ninguém que tenha conseguido resolvê-lo sem voltar ao iptables.

SO do host:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    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: em1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000
    link/ether f0:4d:a2:09:c9:87 brd ff:ff:ff:ff:ff:ff
    inet XXX.XXX.49.99/29 brd XXX.XXX.49.103 scope global em1
       valid_lft forever preferred_lft forever
    inet6 :::f24d:a2ff:fe09:c987/64 scope link
       valid_lft forever preferred_lft forever
6: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN
    link/ether 52:54:00:b8:57:fb brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
7: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 500
    link/ether 52:54:00:b8:57:fb brd ff:ff:ff:ff:ff:ff
21: virbr1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
    link/ether 52:54:00:35:6f:b2 brd ff:ff:ff:ff:ff:ff
    inet 192.168.100.1/24 brd 192.168.100.255 scope global virbr1
       valid_lft forever preferred_lft forever
22: virbr1-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr1 state DOWN qlen 500
    link/ether 52:54:00:35:6f:b2 brd ff:ff:ff:ff:ff:ff
34: vnet1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master virbr1 state UNKNOWN qlen 500
    link/ether fe:54:00:32:25:24 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::fc54:ff:fe32:2524/64 scope link
       valid_lft forever preferred_lft forever
35: vnet0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master virbr1 state UNKNOWN qlen 500
    link/ether fe:54:00:6c:bf:44 brd ff:ff:ff:ff:ff:ff
    inet6 fe80::fc54:ff:fe6c:bf44/64 scope link
       valid_lft forever preferred_lft forever

VM:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    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:6c:bf:44 brd ff:ff:ff:ff:ff:ff
    inet 192.168.100.50/24 brd 192.168.100.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::5054:ff:fe6c:bf44/64 scope link
       valid_lft forever preferred_lft forever
    
por xzero121 09.05.2015 / 19:03

1 resposta

1

Acho que esta resposta no Serverfault responderá à sua pergunta:

No seu caso:

iptables -t nat -I PREROUTING -p tcp -d XXX.XXX.49.99 --dport 8050 -j DNAT --to-destination 192.168.100.50:8080

iptables -I FORWARD -m state -d 192.168.100.0/24 --state NEW,RELATED,ESTABLISHED -j ACCEPT

    
por 10.05.2015 / 20:56