jrdeng / jrdeng.github.io

I'm using `jrdeng/i2site`
https://wuming.me
1 stars 0 forks source link

KVM/libvirt forwarding ports to guest via iptables #9

Open jrdeng opened 3 years ago

jrdeng commented 3 years ago
# 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 commented 3 years ago

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