Основная OS Centos 6.8 (111.11.11.1), внутри виртуалка Windows Server (192.168.122.40)
Делал по такому приниципу:
создал файл в /etc/libvirt/hooks/qemu
spoiler#!/bin/bash
# used some from advanced script to have multiple ports: use an equal number of guest and host ports
# Update the following variables to fit your setup
Guest_name=vm5
Guest_ipaddr=192.168.122.40
Host_ipaddr=111.11.11.1
Host_port=( '8041' '8042' )
Guest_port=( '80' '443' )
length=$(( ${#Host_port[@]} - 1 ))
if [ "${1}" = "${Guest_name}" ]; then
if [ "${2}" = "stopped" ] || [ "${2}" = "reconnect" ]; then
for i in `seq 0 $length`; do
iptables -t nat -D PREROUTING -d ${Host_ipaddr} -p tcp --dport ${Host_port[$i]} -j DNAT --to ${Guest_ipaddr}:${Guest_port[$i]}
iptables -D FORWARD -d ${Guest_ipaddr}/32 -p tcp -m state --state NEW -m tcp --dport ${Guest_port[$i]} -j ACCEPT
done
fi
if [ "${2}" = "start" ] || [ "${2}" = "reconnect" ]; then
for i in `seq 0 $length`; do
iptables -t nat -A PREROUTING -d ${Host_ipaddr} -p tcp --dport ${Host_port[$i]} -j DNAT --to ${Guest_ipaddr}:${Guest_port[$i]}
iptables -I FORWARD -d ${Guest_ipaddr}/32 -p tcp -m state --state NEW -m tcp --dport ${Guest_port[$i]} -j ACCEPT
done
fi
fi
Далее
service libvirtd restart
и такая ошибка
Error starting domain: Hook script execution failed: internal error Child process (LC_ALL=C PATH=/sbin:/usr/sbin:/bin:/usr/bin /etc/libvirt/hooks/qemu wsvm prepare begin -) unexpected exit status 1: libvirt: error : cannot execute binary /etc/libvirt/hooks/qemu: No such file or directory
Traceback (most recent call last):
File "/usr/share/virt-manager/virtManager/asyncjob.py", line 44, in cb_wrapper
callback(asyncjob, *args, **kwargs)
File "/usr/share/virt-manager/virtManager/asyncjob.py", line 65, in tmpcb
callback(*args, **kwargs)
File "/usr/share/virt-manager/virtManager/domain.py", line 1125, in startup
self._backend.create()
File "/usr/lib64/python2.6/site-packages/libvirt.py", line 686, in create
if ret == -1: raise libvirtError ('virDomainCreate() failed', dom=self)
libvirtError: Hook script execution failed: internal error Child process (LC_ALL=C PATH=/sbin:/usr/sbin:/bin:/usr/bin /etc/libvirt/hooks/qemu wsvm prepare begin -) unexpected exit status 1: libvirt: error : cannot execute binary /etc/libvirt/hooks/qemu: No such file or directory