Re: [Q] Virtual hosts and routing...

1999-06-19 Thread David H. Silber
On Fri, Jun 18, 1999 at 09:17:56AM -0400, David H. Silber wrote:
 #  Set up a virtual interface.
 #
 #  Usage:
 #virtualif Interface IP number netmask broadcast [reset]
 virtualif() {

I didn't like that my previous solution, because it only dealt reasonably
with one physical interface at a time.  By making a virtual variable to
track the virtual interface for each physical interface, the virtualif()
function no longer requires that the administrator set up all of the
virtual interfaces for a given physical interface before setting up the
next physical interface.  This allows the administrator who maintains
separate domains over the the same network to group entries in the
/etc/init.d/network file in a more logical manner.  There is also no
longer a need to reset the counter manually.

#! /bin/sh
#
#  virtualif() - Set up a virtual interface.
#
#  Usage:
#virtualif Interface IP number Netmask Broadcast
#
#  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
#virtualif eth1 192.168.246.130 255.255.255.128 192.168.246.255
#virtualif eth0 192.168.246.4 255.255.255.128 192.168.246.127
#virtualif eth0 192.168.246.5 255.255.255.128 192.168.246.127
#virtualif eth0 192.168.246.6 255.255.255.128 192.168.246.127
#virtualif eth1 192.168.246.131 255.255.255.128 192.168.246.255
#virtualif eth2 10.10.10.1 255.255.255.0 192.168.246.255
#
#  virtualif() sets up a virtual network interface and adds a route so
#  that local references to the IP can be routed.  It keeps track of the
#  next available virtual interface for each physical interface, so that
#  you don't have to.
#
#  Installation:  Insert the virtualif() function at the top of the
#  /etc/init.d/network file.
#
#  $VCOUNTER contains the name of the counter of virtual interfaces for
#  the current physical interface.  This name is built from the string
#  ``COUNTER'', concatenated with the name of the physical interface.
#  By using eval, we can use this name as a variable.  Since applying
#  the name of a different physical interface to this scheme generates
#  a different variable name, we can keep a separate counter for each
#  physical interface.
#
#  Version 1.1
#
#  David H. Silber -- June 18, 1999
#  [EMAIL PROTECTED] -- http://www.orbits.com/~dhs
#
#  (I keep thinking that there ought to be a way to simplify this, but
#  it escapes me.  If you find a better way to do this, please send
#  email to the address above.)
virtualif() {
  INTERFACE=$1
  IP=$2
  NETMASK=$3
  BROADCAST=$4

  COUNTER='$COUNTER'

  VCOUNTER=`echo COUNTER$INTERFACE`
  if [ ! `eval echo $\`echo $VCOUNTER\`` ]
  then
eval $VCOUNTER=0
  fi

  #  Build the virtual interface name string.
  VIRTUAL=${INTERFACE}:`eval echo $\`echo $VCOUNTER\``

  #  The point of all of this is to:
  echo Creating virtual interface $VIRTUAL and local route for $IP.
  /sbin/ifconfig ${VIRTUAL} ${IP} netmask ${NETMASK} broadcast ${BROADCAST}
  /sbin/route add -host ${IP} ${VIRTUAL}

  #  Increment the virtual interface counter.
  eval $VCOUNTER=`/usr/bin/expr \`eval echo $\\\`echo $VCOUNTER\\\`\` + 1`
}


-- 
David H. Silber  --   http://www.orbits.com/~dhs/   --   [EMAIL PROTECTED]

  For custom software, see:http://www.SilberSoft.com/
  Palm OS / Linux Documentation:  http://www.orbits.com/Palm/  


Re: [Q] Virtual hosts and routing...

1999-06-18 Thread Jens B. Jorgensen
Well, I wouldn't worry about this. I also use an IP alias and I can't ping it 
from the
machine it's on either but I can ping it from any other machine. I won't even 
venture to
guess why this is. BTW, you shouldn't assign 216.178.140.255 as an address 
since this is
the broadcast address.

The Doctor What wrote:

 I have a network,  216.178.140.xxx, which my box is part of.  My box,
 bunny, has a main ethernet (eth0) ip as 216.178.140.4.  It's gateway is
 216.178.140.1, This is all class C of course.

 In addition, I have the whole block of IPs from 216.178.140.240 to
 216.178.140.255 all assigned as virtual ethernet devices: eth0:0 thru
 eth0:15.

 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.

 uname -a prints:
 Linux gerf 2.0.36 #2 Sun Feb 21 15:55:27 EST 1999 i686 unknown

 This is a Debian 2.1 system with updates from the master site.

 If I am missing any info, I can provide it.  Hopefully you can help as the
 documentiation is rather short, and doesn't mention any problems like
 this.

 Ciao!

 --
 If there's anything more important than my ego around, I want it caught and 
 shot now.
  --Zaphod (Hitchhikers Guide to the Galaxy)

 The Doctor What: fill in the blankhttp://www.gerf.org/~docwhat/
 [EMAIL PROTECTED](finger [EMAIL PROTECTED] for PGP key)
 KF6VNC

   

outName: out
   Type: Plain Text (text/plain)

--
Jens B. Jorgensen
[EMAIL PROTECTED]



Re: [Q] Virtual hosts and routing...

1999-06-18 Thread Mirek Kwasniak
On Thu, Jun 17, 1999 at 04:57:30PM -0500, The Doctor What wrote:
 I have a network,  216.178.140.xxx, which my box is part of.  My box,
 bunny, has a main ethernet (eth0) ip as 216.178.140.4.  It's gateway is
 216.178.140.1, This is all class C of course.
 
 In addition, I have the whole block of IPs from 216.178.140.240 to
 216.178.140.255 all assigned as virtual ethernet devices: eth0:0 thru
 eth0:15.

You can't use last (and first) adress in your newtork

 
 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

Mirek


Re: [Q] Virtual hosts and routing...

1999-06-18 Thread David H. Silber
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/   --   [EMAIL PROTECTED]

  For custom software, see:http://www.SilberSoft.com/
  Palm OS / Linux Documentation:  http://www.orbits.com/Palm/  


Re: [Q] Virtual hosts and routing...

1999-06-18 Thread David H. Silber
On Fri, Jun 18, 1999 at 09:17:56AM -0400, David H. Silber wrote:
 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.

Oops.  I forgot to mention that the virtualif function is placed at the
beginning of the /etc/init.d/network file.

-- 
David H. Silber  --   http://www.orbits.com/~dhs/   --   [EMAIL PROTECTED]

  For custom software, see:http://www.SilberSoft.com/
  Palm OS / Linux Documentation:  http://www.orbits.com/Palm/  


Re: [Q] Virtual hosts and routing...

1999-06-18 Thread The Doctor What
Since we are trading scripts, here is mine. I'd kinda like it if there
were some functions like this in, or better yet, included from the network
script.

Ciao!

-- 
Baldrick, you wouldn't see a subtle plan if it painted itself purple and 
danced naked on top of a harpsichord, singing 'Subtle Plans Are Here Again.'
--Edmund Blackadder II

The Doctor What: Un-Humble  http://www.gerf.org/~docwhat/
[EMAIL PROTECTED](finger [EMAIL PROTECTED] for PGP key)
KF6VNC
#!/bin/sh

# Local Network
ifconfig lo 127.0.0.1
route add -net 127.0.0.0

# This sets up the entire interface
#   and adds a default route to the ip
ipup() {
  echo \* Configuring ${IPADDR} ${IFACE}
  ifconfig ${IFACE} ${IPADDR} netmask ${NETMASK} broadcast ${BROADCAST}
  route add -host ${IPADDR} dev ${IFACE}
# The virtual IP docs say to do this, but it just break things as near as
# I can tell
#  route add -net ${NETWORK} ${IFACE}
  # This makes sure that the router can find us.
  [ ${MACADDR} ]  rarp -s ${IPADDR} ${MACADDR} ; \
  arp -s -i ${IFACE} ${IPADDR} ${MACADDR} pub

}



IPADDR=216.178.140.4
IFACE=eth0
NETMASK=255.255.255.0
NETWORK=216.178.140.0
BROADCAST=216.178.140.255
GATEWAY=216.178.140.1
MACADDR=00:10:4B:14:18:B5

ipup
[ ${GATEWAY} ]  route add ${GATEWAY} ${IFACE}
[ ${GATEWAY} ]  route add default gw ${GATEWAY} metric 1 ${IFACE}

IPADDR=216.178.140.240
IFACE=eth0:0
ipup

IPADDR=216.178.140.241
IFACE=eth0:1
ipup

IPADDR=216.178.140.242
IFACE=eth0:2
ipup

IPADDR=216.178.140.243
IFACE=eth0:3
ipup

IPADDR=216.178.140.244
IFACE=eth0:4
ipup

IPADDR=216.178.140.245
IFACE=eth0:5
ipup

IPADDR=216.178.140.246
IFACE=eth0:6
ipup

IPADDR=216.178.140.247
IFACE=eth0:7
ipup

IPADDR=216.178.140.248
IFACE=eth0:8
ipup

IPADDR=216.178.140.249
IFACE=eth0:9
ipup

IPADDR=216.178.140.250
IFACE=eth0:10
ipup

IPADDR=216.178.140.251
IFACE=eth0:11
ipup

IPADDR=216.178.140.252
IFACE=eth0:12
ipup

IPADDR=216.178.140.253
IFACE=eth0:13
ipup

IPADDR=216.178.140.254
IFACE=eth0:14
ipup

# This is broadcast, dummy!
#IPADDR=216.178.140.255
#IFACE=eth0:15
#ipup

exit


[Q] Virtual hosts and routing...

1999-06-17 Thread The Doctor What
I have a network,  216.178.140.xxx, which my box is part of.  My box,
bunny, has a main ethernet (eth0) ip as 216.178.140.4.  It's gateway is
216.178.140.1, This is all class C of course.

In addition, I have the whole block of IPs from 216.178.140.240 to
216.178.140.255 all assigned as virtual ethernet devices: eth0:0 thru
eth0:15.

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.  

uname -a prints:
Linux gerf 2.0.36 #2 Sun Feb 21 15:55:27 EST 1999 i686 unknown

This is a Debian 2.1 system with updates from the master site.

If I am missing any info, I can provide it.  Hopefully you can help as the
documentiation is rather short, and doesn't mention any problems like
this.

Ciao!

-- 
If there's anything more important than my ego around, I want it caught and 
shot now.
 --Zaphod (Hitchhikers Guide to the Galaxy)

The Doctor What: fill in the blankhttp://www.gerf.org/~docwhat/
[EMAIL PROTECTED](finger [EMAIL PROTECTED] for PGP key)
KF6VNC
Kernel IP routing table
Destination Gateway Genmask Flags Metric RefUse Iface
216.178.140.1   0.0.0.0 255.255.255.255 UH0  0  546 eth0
216.178.140.0   0.0.0.0 255.255.255.0   U 0  0 1484 eth0
127.0.0.0   0.0.0.0 255.0.0.0   U 0  0   37 lo
0.0.0.0 216.178.140.1   0.0.0.0 UG1  07 eth0
loLink encap:Local Loopback  
  inet addr:127.0.0.1  Bcast:127.255.255.255  Mask:255.0.0.0
  UP BROADCAST LOOPBACK RUNNING  MTU:3584  Metric:1
  RX packets:403781 errors:0 dropped:0 overruns:0 frame:0
  TX packets:403781 errors:0 dropped:0 overruns:0 carrier:0
  Collisions:0 

eth0  Link encap:Ethernet  HWaddr 00:10:4B:14:18:B5  
  inet addr:216.178.140.4  Bcast:216.178.140.255  Mask:255.255.255.0
  UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
  RX packets:5910744 errors:0 dropped:0 overruns:0 frame:0
  TX packets:3472409 errors:0 dropped:0 overruns:0 carrier:0
  Collisions:33775 
  Interrupt:11 Base address:0xd000 

eth0:0Link encap:Ethernet  HWaddr 00:10:4B:14:18:B5  
  inet addr:216.178.140.240  Bcast:216.178.140.255  Mask:255.255.255.0
  UP BROADCAST RUNNING  MTU:1500  Metric:1
  RX packets:0 errors:0 dropped:0 overruns:0 frame:0
  TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
  Collisions:0 

eth0:1Link encap:Ethernet  HWaddr 00:10:4B:14:18:B5  
  inet addr:216.178.140.241  Bcast:216.178.140.255  Mask:255.255.255.0
  UP BROADCAST RUNNING  MTU:1500  Metric:1
  RX packets:1 errors:0 dropped:0 overruns:0 frame:0
  TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
  Collisions:0 

eth0:2Link encap:Ethernet  HWaddr 00:10:4B:14:18:B5  
  inet addr:216.178.140.242  Bcast:216.178.140.255  Mask:255.255.255.0
  UP BROADCAST RUNNING  MTU:1500  Metric:1
  RX packets:2 errors:0 dropped:0 overruns:0 frame:0
  TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
  Collisions:0 

eth0:3Link encap:Ethernet  HWaddr 00:10:4B:14:18:B5  
  inet addr:216.178.140.243  Bcast:216.178.140.255  Mask:255.255.255.0
  UP BROADCAST RUNNING  MTU:1500  Metric:1
  RX packets:3 errors:0 dropped:0 overruns:0 frame:0
  TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
  Collisions:0 

eth0:4Link encap:Ethernet  HWaddr 00:10:4B:14:18:B5  
  inet addr:216.178.140.244  Bcast:216.178.140.255  Mask:255.255.255.0
  UP BROADCAST RUNNING  MTU:1500  Metric:1
  RX packets:4 errors:0 dropped:0 overruns:0 frame:0
  TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
  Collisions:0 

eth0:5Link encap:Ethernet  HWaddr 00:10:4B:14:18:B5  
  inet addr:216.178.140.245  Bcast:216.178.140.255  Mask:255.255.255.0
  UP BROADCAST RUNNING  MTU:1500  Metric:1
  RX packets:5 errors:0 dropped:0 overruns:0 frame:0
  TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
  Collisions:0 

eth0:6Link encap:Ethernet  HWaddr 00:10:4B:14:18:B5  
  inet addr:216.178.140.246  Bcast:216.178.140.255  Mask:255.255.255.0
  UP BROADCAST RUNNING  MTU:1500  Metric:1
  RX packets:6 errors:0 dropped:0 overruns:0 frame:0
  TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
  Collisions:0 

eth0:7Link encap:Ethernet  HWaddr 00:10:4B:14:18:B5  
  inet addr:216.178.140.247  Bcast:216.178.140.255  Mask:255.255.255.0
  UP BROADCAST RUNNING  MTU:1500  Metric:1
  RX packets:7 errors:0 dropped:0 overruns:0 frame:0
  TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
  Collisions:0 

eth0:8Link