2017-11-25 6 views
0

Ich verwende den NAT-Modus für Gast-Netzwerke. Ich brauche meine Maschinen, um von außerhalb des Gastes zugänglich zu sein. Ich habe iptables so eingerichtet, dass ein bestimmter Port auf dem Host auf Port 22 auf Gast weitergeleitet wird, aber das scheint nicht zu funktionieren.Port-Weiterleitung auf NAT mit KVM/QEMU

Ich habe diese Regeln:

# Port Forwardings 
-A PREROUTING -i eth0 -p tcp --dport 9867 -j DNAT --to-destination 192.168.122.136:22 

# Forward traffic through eth0 - Change to match you out-interface 
-A POSTROUTING -s 192.168.1.0/24 -o eth0 -j MASQUERADE 

Wenn ich ssh 192.168.122.136 von Host es perfekt funktioniert, aber wenn ich ssh 192.168.122.136 -p 9867 versuchen zeigt es ssh: connect to host 192.168.122.1 port 9867: Connection refused

I Port-Forwarding auf /etc/ufw/sysctl.conf

aktiviert haben mit iptables -t nat -L zeigt, dass die Regel auf iptable

DNAT  tcp -- anywhere    anywhere    tcp dpt:9867 to:192.168.122.136:22 
01 eingerichtet ist

Antwort

0

Gefunden meine Antwort here. grundlegend änderte ich das oben zu

# connections from outside 
iptables -t nat -A PREROUTING -p tcp --dport 9867 -j DNAT --to 192.168.122.136:22 
# for local connection 
iptables -t nat -A OUTPUT -p tcp --dport 9867 -j DNAT --to 192.168.122.136:22 

# Masquerade local subnet 
iptables -t nat -A POSTROUTING -s 192.168.122.0/24 -j MASQUERADE 
iptables -A FORWARD -o virbr0 -m state --state RELATED,ESTABLISHED -j ACCEPT 
iptables -A FORWARD -i virbr0 -o eth0 -j ACCEPT 
iptables -A FORWARD -i virbr0 -o lo -j ACCEPT