#!/bin/bash
# Filename: vip.sh
# Funtion: Add Virutual IP For Nginx role
# Author: Shuhui

ifconfig=/usr/sbin/ifconfig
echo=/usr/bin/echo

if [[ $UID -ne 0 ]]; then
	echo "Please use root role to run this script."
	exit 1
fi

function vip_on() {
	# Virutal Interface Turn on
	for no in {1..254}
	do
	  $ifconfig lo:$no 120.41.39.$no netmask 255.255.255.255
	  $echo "Add Interface:lo:$no [ ok ]"
	done
}

function vip_off() {
	# Virutal Interface Turn off
	for no in {1..254}
	do
	  $ifconfig lo:$no down
	  $echo "Remove Interface:lo:$no [ ok ]"
	done
}

case $1 in
	on)
		vip_on
		;;
	off)
		vip_off
		;;
	*)
		$echo "Usage: $0 on | off"
		exit 1
esac
