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.

Shell script to create KVM - Ubuntu instance

Please copy and paste the following in a shell
script and execute the file from command line:

ubuntu-vm-builder kvm hardy --domain vm-gdb --dest vm-gdb --arch i386 --hostname vm-gdb --mem 256 --user user --pass user --ip 192.168.122.99 --mirror http://ubuntu.media.mit.edu/ubuntu/ --components main,universe --addpkg vim --addpkg openssh-server --libvirt qemu:///system --addpkg iperf --addpkg gcc --addpkg g++

Default location/path for apt package download debian

/var/cache/apt/archives/