OVH Community, your new community space.

ubuntu add ip ipv6 range script


gigabit
01-10-2009, 20:43
Oh right then fair enough, Ive never used Debian before

gregoryfenton
01-10-2009, 20:40
Ubuntu/debian based systems unfortunately doesn't allow you to add one address and netmask it to cover a range. A rather large oversight in this day and age (thanks OVH!), hence the script.

gigabit
01-10-2009, 20:30
Surly you only need to add the IP and the netmask once?

gregoryfenton
01-10-2009, 16:42
Having been given gazillions of ipv6 addresses with my server I thought it would be easy to assign them all to the server. Boy was I wrong

In that vein I wrote this bash script.

Hope it helps someone

keywords: ipv4 ipv6 ubuntu multiple ip addresses range

A simple way to add a range of IP addresses:

addrange.sh
Code:
#!/bin/sh
if [ "$#" -ne "4" ]; then
        echo Usage:
        echo " $0 interface ip range netmask"
        echo " examples:"
        echo "  1) Assuming you want to bind the IP range 192.168.0.1..192.168.0.254 to eth0 with netmask 255.255.255.0:"
        echo "  $0 eth0 192.168.0. 1..254 255.255.255.0"
        echo "  2) Assuming you want to bind the IPv6 range 2001:41d0:1:5000::1-2001:41d0:1:5000::254 to eth0 with netmask /$
        echo "  $0 eth0 2001:41d0:1:5000:: 1..254 56"
else
        echo "Attempting to assign the IP range $2($3) to interface $1 with netmask $4"
        for ip in $(eval echo "{$3}"); do ifconfig -v $1 add $2$ip netmask $4; done
fi