I solved it! Cost me couple of days...
The network topology looks like this:
Code:
Internet---------[Virtual Host Server]
WAN------------[[em1|virbr0]-------------LAN]
x.x.104.49-------[[em1|virbr0]-------------192.168.122.0/24]
I like the abstraction of packet flow of the IPtables provided by Jan Engelhardt:
nf-packet-flow.jpg
Therefore, the simple investigation of image above, manual and some internet sources could pretty easy lead to this final rule:
Code:
iptables -t nat -I PREROUTING -p tcp -d x.x.104.49 --dport 22 -j DNAT --to-destination 192.168.122.20:22
iptables -I FORWARD -m state -d 192.168.122.20/24 --state NEW,RELATED,ESTABLISHED -j ACCEPT
If something does not work to delete existing rules from every iptables table, execute the following commands:
Code:
iptables -X
iptables -F
iptables -t nat -F
iptables -t nat -X
iptables -t mangle -F
iptables -t mangle -X
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
To reset iptables rules to original libvirt rules set:
Code:
service libvirt-bin restart
The result will looks like this:
Code:
# Generated by iptables-save v1.4.21 on Sun Jan 18 23:25:54 2015
*mangle
:PREROUTING ACCEPT [272:19236]
:INPUT ACCEPT [92:12036]
:FORWARD ACCEPT [179:7160]
:OUTPUT ACCEPT [76:13256]
:POSTROUTING ACCEPT [255:20416]
-A POSTROUTING -o virbr0 -p udp -m udp --dport 68 -j CHECKSUM --checksum-fill
COMMIT
# Completed on Sun Jan 18 23:25:54 2015
# Generated by iptables-save v1.4.21 on Sun Jan 18 23:25:54 2015
*nat
:PREROUTING ACCEPT [2:80]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [4:240]
:POSTROUTING ACCEPT [6:320]
-A POSTROUTING -s 192.168.122.0/24 -d 224.0.0.0/24 -j RETURN
-A POSTROUTING -s 192.168.122.0/24 -d 255.255.255.255/32 -j RETURN
-A POSTROUTING -s 192.168.122.0/24 ! -d 192.168.122.0/24 -p tcp -j MASQUERADE --to-ports 1024-65535
-A POSTROUTING -s 192.168.122.0/24 ! -d 192.168.122.0/24 -p udp -j MASQUERADE --to-ports 1024-65535
-A POSTROUTING -s 192.168.122.0/24 ! -d 192.168.122.0/24 -j MASQUERADE
COMMIT
# Completed on Sun Jan 18 23:25:54 2015
# Generated by iptables-save v1.4.21 on Sun Jan 18 23:25:54 2015
*filter
:INPUT ACCEPT [92:12036]
:FORWARD ACCEPT [179:7160]
:OUTPUT ACCEPT [76:13256]
-A INPUT -i virbr0 -p udp -m udp --dport 53 -j ACCEPT
-A INPUT -i virbr0 -p tcp -m tcp --dport 53 -j ACCEPT
-A INPUT -i virbr0 -p udp -m udp --dport 67 -j ACCEPT
-A INPUT -i virbr0 -p tcp -m tcp --dport 67 -j ACCEPT
-A FORWARD -d 192.168.122.0/24 -o virbr0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -s 192.168.122.0/24 -i virbr0 -j ACCEPT
-A FORWARD -i virbr0 -o virbr0 -j ACCEPT
-A FORWARD -o virbr0 -j REJECT --reject-with icmp-port-unreachable
-A FORWARD -i virbr0 -j REJECT --reject-with icmp-port-unreachable
-A OUTPUT -o virbr0 -p udp -m udp --dport 68 -j ACCEPT
COMMIT
# Completed on Sun Jan 18 23:25:54 2015
Save rules:
Code:
iptables-save > /etc/iptables/rules.v4
or:
Code:
service iptables-persistent save
Sources:
http://www.bctes.com/nat-linux-iptables.html
http://www.atrixnet.com/red-hat-libv...stops-working/
http://serverfault.com/questions/170...n-libvirt-kvm/
Bookmarks