Created
April 3, 2016 03:02
-
-
Save dylanmtaylor/3e16c569e5ef1b91d1da70c2f283ea5f to your computer and use it in GitHub Desktop.
How to forward requests from a host machine to a KVM guest and back using iptables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# echo 1 > /proc/sys/net/ipv4/ip_forward first | |
# 208.x.x.x is the host machine. 192.x.x.x is the guest machine | |
# This routes port 80 to the guest and back. | |
iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 192.x.x.x6:80 | |
iptables -t nat -A POSTROUTING -p tcp -d 192.x.x.x6 --dport 80 -j SNAT --to-source 208.x.x.x | |
# This routes port 2222 on the host to 22 on the guest machine | |
iptables -t nat -A PREROUTING -p tcp --dport 2222 -j DNAT --to-destination 192.x.x.x6:22 | |
iptables -t nat -A POSTROUTING -p tcp -d 192.x.x.x6 --dport 22 -j SNAT --to-source 208.x.x.x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment