Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KVM/libvirt forwarding ports to guest via iptables #9

Open
jrdeng opened this issue Jan 7, 2021 · 1 comment
Open

KVM/libvirt forwarding ports to guest via iptables #9

jrdeng opened this issue Jan 7, 2021 · 1 comment

Comments

@jrdeng
Copy link
Owner

jrdeng commented Jan 7, 2021

# connections from outside
sudo iptables -I FORWARD -o virbr0 -d  192.168.122.226 -j ACCEPT
sudo iptables -t nat -A PREROUTING -p tcp --dport 8006 -j DNAT --to 192.168.122.226:8006
sudo iptables -t nat -A POSTROUTING -s 192.168.122.0/24 -j MASQUERADE

# local subnet
sudo iptables -A FORWARD -o virbr0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i virbr0 -o enp0s31f6 -j ACCEPT
sudo iptables -A FORWARD -i virbr0 -o lo -j ACCEPT

# save to persistent rules
sudo service netfilter-persistent save
sudo service netfilter-persistent reload

refer to: https://aboullaite.me/kvm-qemo-forward-ports-with-iptables/

@jrdeng
Copy link
Owner Author

jrdeng commented Jan 12, 2021

第一条 FORWARD 要用 -I,用-A不行。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant