40 lines
1.1 KiB
Bash
40 lines
1.1 KiB
Bash
format_ip6_from_mac(){
|
|
local template=$1
|
|
IFS=':'; set $2; unset IFS
|
|
printf "$template" 0x${3} 0x${4} 0x${5} 0x${6}
|
|
}
|
|
|
|
add_ip6(){
|
|
local interface=$1
|
|
local ip=$2
|
|
local prefixlen=$3
|
|
if has ifconfig; then
|
|
if [[ "$OSTYPE" == "linux-gnu" ]]; then
|
|
ifconfig "$interface" inet6 del "$ip/$prefixlen" || true
|
|
ifconfig "$interface" inet6 add "$ip/$prefixlen"
|
|
else
|
|
ifconfig "$interface" inet6 del "$ip" prefixlen "$prefixlen" || true
|
|
ifconfig "$interface" inet6 add "$ip" prefixlen "$prefixlen"
|
|
fi
|
|
elif has ip; then
|
|
ip addr del "$ip/$prefixlen" dev "$interface" || true
|
|
ip addr add "$ip/$prefixlen" dev "$interface"
|
|
else
|
|
die "no suitable program found to configure the network interface, need iproute2 or ifconfig"
|
|
fi
|
|
}
|
|
|
|
add_ip4() {
|
|
local interface=$1
|
|
local ip=$2
|
|
local netmask=$3
|
|
if has ifconfig; then
|
|
ifconfig "$interface" "$ip" netmask "$netmask"
|
|
elif has ip; then
|
|
local cidr="$(mask2cidr $netmask)"
|
|
ip addr add "$ip/$cidr" dev "$interface"
|
|
else
|
|
die "no suitable program found to set ip address, need iproute2 or ifconfig"
|
|
fi
|
|
}
|