aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBill Nottingham <notting@redhat.com>2010-11-30 21:53:02 -0500
committerPetr Lautrbach <plautrba@redhat.com>2010-12-06 15:50:44 +0100
commitc93923134c5e1dc5536caeea64a74329bfb69c7e (patch)
tree45e9facf4c1f727e9f729f085bd80993cc0ab7db
parent9eb05ee238224f84c3322d6331b72b378de05480 (diff)
downloadinitscripts-c93923134c5e1dc5536caeea64a74329bfb69c7e.tar
initscripts-c93923134c5e1dc5536caeea64a74329bfb69c7e.tar.gz
initscripts-c93923134c5e1dc5536caeea64a74329bfb69c7e.tar.bz2
initscripts-c93923134c5e1dc5536caeea64a74329bfb69c7e.tar.xz
initscripts-c93923134c5e1dc5536caeea64a74329bfb69c7e.zip
Support multiple IP addreses via IPADDRn, PREFIXn (or NETMASKn) (#633984) Adapted from <jklimes@redhat.com>
In addition to legacy IP aliases, this commit adds a support for configuring mupliple IPs via single ifcfg file. It uses the same syntax and behaviour as NetworkManager.
-rw-r--r--sysconfig.txt18
-rwxr-xr-xsysconfig/network-scripts/ifup-eth53
-rw-r--r--sysconfig/network-scripts/network-functions36
3 files changed, 71 insertions, 36 deletions
diff --git a/sysconfig.txt b/sysconfig.txt
index e3486bbf..ea4e9740 100644
--- a/sysconfig.txt
+++ b/sysconfig.txt
@@ -511,8 +511,18 @@ Files in /etc/sysconfig/network-scripts/
Most important for PPP. Only used in front ends.
DEVICE=<name of physical device (except dynamically-allocated PPP
devices where it is the "logical name")>
- IPADDR=
- NETMASK=
+ IPADDRn=
+ PREFIXn=
+ Network prefix. It is used for all configurations except aliases
+ and ippp devices. It takes precedence over NETMASK when both
+ PREFIX and NETMASK are set.
+ NETMASKn=
+ Subnet mask; just useful for aliases and ippp devices. For all other
+ configurations, use PREFIX instead.
+
+ The "n" is expected to be consecutive positive integers starting from 0.
+ It can be omitted if there is only one address being configured.
+
GATEWAY=
METRIC=
Metric for the default route using GATEWAY
@@ -928,8 +938,8 @@ Files in /etc/sysconfig/network-scripts/
NETMASKn=<network/prefix mask>
GATEWAYn=<next-hop router/gateway IP address>
- The "n" can be any integer number, but is expected to be consecutive
- positive integers starting from 0. For example:
+ The "n" is expected to be consecutive positive integers starting from 0.
+ For example:
ADDRESS0=192.168.2.0
NETMASK0=255.255.255.0
diff --git a/sysconfig/network-scripts/ifup-eth b/sysconfig/network-scripts/ifup-eth
index 6c365721..e4be0b4c 100755
--- a/sysconfig/network-scripts/ifup-eth
+++ b/sysconfig/network-scripts/ifup-eth
@@ -1,6 +1,6 @@
#!/bin/bash
# Network Interface Configuration System
-# Copyright (c) 1996-2009 Red Hat, Inc. all rights reserved.
+# Copyright (c) 1996-2010 Red Hat, Inc. all rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2,
@@ -219,7 +219,7 @@ else
else
expand_config
-
+
[ -n "${ARP}" ] && \
ip link set dev ${REALDEVICE} $(toggle_value arp $ARP)
@@ -246,27 +246,36 @@ else
SRC=
fi
- if [ "${REALDEVICE}" != "lo" ]; then
- if ! LC_ALL=C ip addr ls ${REALDEVICE} | LC_ALL=C grep -q "${IPADDR}/${PREFIX}" ; then
- if ! /sbin/arping -q -c 2 -w 3 -D -I ${REALDEVICE} ${IPADDR} ; then
- echo $"Error, some other host already uses address ${IPADDR}."
- exit 1
- fi
- if ! ip addr add ${IPADDR}/${PREFIX} \
- brd ${BROADCAST:-+} dev ${REALDEVICE} ${SCOPE} label ${DEVICE}; then
- echo $"Error adding address ${IPADDR} for ${DEVICE}."
- fi
- fi
-
- if [ -n "$SRCADDR" ]; then
- sysctl -w "net.ipv4.conf.${REALDEVICE}.arp_filter=1" >/dev/null 2>&1
- fi
+ # set IP address(es)
+ for idx in {0..256} ; do
+ if [ -z "${ipaddr[$idx]}" ]; then
+ break
+ fi
- # update ARP cache of neighboring computers
- /sbin/arping -q -A -c 1 -I ${REALDEVICE} ${IPADDR}
- ( sleep 2;
- /sbin/arping -q -U -c 1 -I ${REALDEVICE} ${IPADDR} ) > /dev/null 2>&1 < /dev/null &
- fi
+ if ! LC_ALL=C ip addr ls ${REALDEVICE} | LC_ALL=C grep -q "${ipaddr[$idx]}/${prefix[$idx]}" ; then
+ [ "${REALDEVICE}" != "lo" ] && \
+ if ! /sbin/arping -q -c 2 -w 3 -D -I ${REALDEVICE} ${ipaddr[$idx]} ; then
+ echo $"Error, some other host already uses address ${ipaddr[$idx]}."
+ exit 1
+ fi
+
+ if ! ip addr add ${ipaddr[$idx]}/${prefix[$idx]} \
+ brd ${broadcast[$idx]:-+} dev ${REALDEVICE} ${SCOPE} label ${DEVICE}; then
+ echo $"Error adding address ${ipaddr[$idx]} for ${DEVICE}."
+ fi
+ fi
+
+ if [ -n "$SRCADDR" ]; then
+ sysctl -w "net.ipv4.conf.${REALDEVICE}.arp_filter=1" >/dev/null 2>&1
+ fi
+
+ # update ARP cache of neighboring computers
+ if [ "${REALDEVICE}" != "lo" ]; then
+ /sbin/arping -q -A -c 1 -I ${REALDEVICE} ${ipaddr[$idx]}
+ ( sleep 2;
+ /sbin/arping -q -U -c 1 -I ${REALDEVICE} ${ipaddr[$idx]} ) > /dev/null 2>&1 < /dev/null &
+ fi
+ done
# Set a default route.
if [ "${DEFROUTE}" != "no" ] && [ -z "${GATEWAYDEV}" -o "${GATEWAYDEV}" = "${REALDEVICE}" ]; then
diff --git a/sysconfig/network-scripts/network-functions b/sysconfig/network-scripts/network-functions
index 3fc7e947..01419fc0 100644
--- a/sysconfig/network-scripts/network-functions
+++ b/sysconfig/network-scripts/network-functions
@@ -150,20 +150,36 @@ source_config ()
expand_config ()
{
- if [ -z "${NETMASK}" ]; then
- eval $(/bin/ipcalc --netmask ${IPADDR})
- fi
+ local i=0 val
+ for idx in '' {0..255} ; do
+ ipaddr[$i]=$(eval echo '$'IPADDR$idx)
+ if [ -z "${ipaddr[$i]}" ]; then
+ [ "$idx" ] && [ $idx -gt 2 ] && break
+ continue
+ fi
+ prefix[$i]=$(eval echo '$'PREFIX$idx)
+ netmask[$i]=$(eval echo '$'NETMASK$idx)
+ broadcast[$i]=$(eval echo '$'BROADCAST$idx)
- if [ -z "${PREFIX}" ]; then
- eval $(/bin/ipcalc --prefix ${IPADDR} ${NETMASK})
- fi
+ if [ "${netmask[$i]}x" = "x" ]; then
+ val=$(/bin/ipcalc --netmask "${ipaddr[$i]}")
+ netmask[$i]=${val##NETMASK=}
+ fi
- if [ -z "${BROADCAST}" ]; then
- eval $(/bin/ipcalc --broadcast ${IPADDR} ${NETMASK})
- fi
+ if [ "${prefix[$i]}x" = "x" ]; then
+ val=$(/bin/ipcalc --prefix ${ipaddr[$i]} ${netmask[$i]})
+ prefix[$i]=${val##PREFIX=}
+ fi
+
+ if [ "${broadcast[$i]}x" = "x" ]; then
+ val=$(/bin/ipcalc --broadcast ${ipaddr[$i]} ${netmask[$i]})
+ broadcast[$i]=${val##BROADCAST=}
+ fi
+ i=$((i+1))
+ done
if [ -z "${NETWORK}" ]; then
- eval $(/bin/ipcalc --network ${IPADDR} ${NETMASK})
+ eval $(/bin/ipcalc --network ${ipaddr[0]} ${netmask[0]})
fi
}