← history for chapter-9/kvm-firewall-NO-SQLITE.sh
4b024f91chapter-9/kvm-firewall-NO-SQLITE.sh21 lines⬡ raw↓ download
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/bash

# IMPORTANT: Change the "VM NAME" string to match your actual VM Name.
# In order to create rules to other VMs, just duplicate the below block and configure
# it accordingly.
if [ "${1}" = "debian-alpha" ]; then

 # Update the following variables to fit your setup
 GUEST_IP=....
 GUEST_PORT=...
 HOST_PORT=...

 if [ "${2}" = "stopped" ] || [ "${2}" = "reconnect" ]; then
 /sbin/iptables -D FORWARD -o virbr0 -p tcp -d $GUEST_IP --dport $GUEST_PORT -j ACCEPT
 /sbin/iptables -t nat -D PREROUTING -p tcp --dport $HOST_PORT -j DNAT --to $GUEST_IP:$GUEST_PORT
 fi
 if [ "${2}" = "start" ] || [ "${2}" = "reconnect" ]; then
 /sbin/iptables -I FORWARD -o virbr0 -p tcp -d $GUEST_IP --dport $GUEST_PORT -j ACCEPT
 /sbin/iptables -t nat -I PREROUTING -p tcp --dport $HOST_PORT -j DNAT --to $GUEST_IP:$GUEST_PORT
 fi
fi