diff options
author | Bill Nottingham <notting@redhat.com> | 2010-11-30 21:53:02 -0500 |
---|---|---|
committer | Bill Nottingham <notting@redhat.com> | 2010-11-30 21:53:02 -0500 |
commit | ff5befb95b133cc1da3f32ffcd9f3cef779244b6 (patch) | |
tree | c2f360e405892a0add6ac011917d96c3fe2374aa /sysconfig/network-scripts/ifup-eth | |
parent | d624aba089bd95acfe8f02bebb01c34a4f242216 (diff) | |
download | initscripts-ff5befb95b133cc1da3f32ffcd9f3cef779244b6.tar initscripts-ff5befb95b133cc1da3f32ffcd9f3cef779244b6.tar.gz initscripts-ff5befb95b133cc1da3f32ffcd9f3cef779244b6.tar.bz2 initscripts-ff5befb95b133cc1da3f32ffcd9f3cef779244b6.tar.xz initscripts-ff5befb95b133cc1da3f32ffcd9f3cef779244b6.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.
Diffstat (limited to 'sysconfig/network-scripts/ifup-eth')
-rwxr-xr-x | sysconfig/network-scripts/ifup-eth | 53 |
1 files changed, 31 insertions, 22 deletions
diff --git a/sysconfig/network-scripts/ifup-eth b/sysconfig/network-scripts/ifup-eth index cae00783..dd9fb5ea 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, @@ -214,7 +214,7 @@ else else expand_config - + [ -n "${ARP}" ] && \ ip link set dev ${REALDEVICE} $(toggle_value arp $ARP) @@ -241,27 +241,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 |