iptables - portforward

Started by hsp, 2024/04/03, 10:26:26

Previous topic - Next topic

hsp

Ich habe mir nach dieser Anleitung für libvirt ein hookscript angelegt für qemu zum portforward für ssh (NAT Network). Funktioniert auch bestens. Aber was nicht geht ist eine Verbindung von localhost (ssh -p 2222 localhost). Ich habe keine Ahnung waum. Jemand eine Idee was fehlt oder falsch ist?

https://wiki.libvirt.org/Networking.html#forwarding-incoming-connections

Hier der hookscript

#!/bin/bash
#
if [ "${1}" = "foobarbox" ]; then
#
# Update the following variables to fit your setup
GUEST_IP="192.168.122.19"
GUEST_PORT="22"
HOST_PORT="2222"
BRIDGE="virbr0"
#
    if [ "${2}" = "stopped" ] || [ "${2}" = "reconnect" ]; then
        /usr/sbin/iptables -D FORWARD -o $BRIDGE -d $GUEST_IP -j ACCEPT
        /usr/sbin/iptables -t nat -D PREROUTING -p tcp --dport $HOST_PORT -j DNAT --to $GUEST_IP:$GUEST_PORT
    fi
#
    if [ "${2}" = "start" ] || [ "${2}" = "reconnect" ]; then
        /usr/sbin/iptables -I FORWARD -o $BRIDGE -d $GUEST_IP -j ACCEPT
        /usr/sbin/iptables -t nat -I PREROUTING -p tcp --dport $HOST_PORT -j DNAT --to $GUEST_IP:$GUEST_PORT
    fi
fi



Danke...

hsp