Friday, March 19, 2010

Shell script fo enable Nating for virtual machine (KVM)

Please copy and paste this script in a file and execute.

int=$1
ext=$2
echo 1 > /proc/sys/net/ipv4/ip_forward
/sbin/iptables -t nat -A POSTROUTING -o $ext -j MASQUERADE
/sbin/iptables -A FORWARD -i $ext -o $int -m state --state RELATED,ESTABLISHED -j ACCEPT
/sbin/iptables -A FORWARD -i $int -o $ext -j ACCEPT



The script can be invoked as:

scriptname vnet0 eth1


where vnet0 will be your internal interface, and eth1 is your outbound interface.

0 comments:

Post a Comment