Re: [Q] Virtual hosts and routing...
On Fri, Jun 18, 1999 at 12:28:37PM +0200, Mirek Kwasniak wrote:
> On Thu, Jun 17, 1999 at 04:57:30PM -0500, The Doctor What wrote:
> > However, if I log into the system (usually at 216.178.140.240, eth0:0) and
> > try to ping any of my other virtual ips, I get no response. I hav
> > included the route -n and ifconfig output as an attachment.
>
> Try add routes for your ip-aliases:
>
> route add -host 216.178.140.240 eth0:0
> ...
> route add -host 216.178.140.224 eth0:14
This is something that has been bothering me for a while. I want to
thank Doctor What for mentioning the problem and Mirek Kwasniak for the
solution.
Since I have a large number of virtual addresses, I wrote a little
function to perform the ifconfig & route operations together. As a
bonus side benefit, I no longer have to manually number the virtual
interfaces. I'm posting the function so that other people can make
use of this refinement.
# IFCOUNTER counts the virtual interfaces.
IFCOUNTER=0
# Set up a virtual interface.
#
# Usage:
# virtualif <Interface> <IP number> <netmask> <broadcast> [reset]
#
# Example:
# virtualif eth0 192.168.246.1 255.255.255.128 192.168.246.127
# virtualif eth0 192.168.246.2 255.255.255.128 192.168.246.127
# virtualif eth0 192.168.246.3 255.255.255.128 192.168.246.127
# virtualif eth1 192.168.246.129 255.255.255.128 192.168.246.255 reset
# virtualif eth1 192.168.246.130 255.255.255.128 192.168.246.255
#
# The use of the reset flag starts the virtual interface counter from zero.
#
virtualif() {
INTERFACE=$1
IP=$2
NETMASK=$3
BROADCAST=$4
RESET=$5
# When specified, reset the counter so that a second interface can
# have its own series of virtual interfaces.
if [ ${RESET} ]
then
IFCOUNTER=0
fi
# Build the virtual interface name string.
VIRTUAL=${INTERFACE}:${IFCOUNTER}
# The point of all of this is to:
/sbin/ifconfig ${VIRTUAL} ${IP} netmask ${NETMASK} broadcast ${BROADCAST}
/sbin/route add -host ${IP} ${VIRTUAL}
# Increment the virtual interface counter.
IFCOUNTER=`/usr/bin/expr ${IFCOUNTER} + 1`
}
Despite the examples mentioned, I set shell variables for the netmask(s)
and broadcast address(es) to enhance readability and to avoid mistakes
in typing. I also use shell variables to give names to the IP addresses,
so the calls tend to look like:
WWWORBITSCOM=207.199.167.12
WWWSILBERSOFTCOM=207.199.167.14
virtualif eth0 ${WWWORBITSCOM} ${NETMASK} ${BROADCAST}
virtualif eth0 ${WWWSILBERSOFTCOM} ${NETMASK} ${BROADCAST}
I hope this helps someone,
David H. Silber
--
David H. Silber -- http://www.orbits.com/~dhs/ -- dhs@orbits.com
For custom software, see: http://www.SilberSoft.com/
Palm OS / Linux Documentation: http://www.orbits.com/Palm/
Reply to: