144 lines
4.2 KiB
Bash
144 lines
4.2 KiB
Bash
#!/bin/sh -
|
|
#
|
|
# $NetBSD: netstart,v 1.41 1997/08/04 06:09:49 lukem Exp $
|
|
# from: @(#)netstart 8.1 (Berkeley) 7/23/93
|
|
|
|
if [ -f /etc/rc.conf ]; then
|
|
. /etc/rc.conf
|
|
fi
|
|
|
|
# If $hostname is set, use it for my symbolic name, otherwise use /etc/myname
|
|
if [ -z "$hostname" ]; then
|
|
hostname=`cat /etc/myname`
|
|
fi
|
|
echo "hostname: $hostname"
|
|
hostname $hostname
|
|
|
|
# Check $domainname first, then /etc/defaultdomain, for domain name
|
|
if [ -z "$domainname" -a -f /etc/defaultdomain ]; then
|
|
domainname=`cat /etc/defaultdomain`
|
|
fi
|
|
if [ -n "$domainname" ]; then
|
|
echo "domainname: $domainname"
|
|
domainname $domainname
|
|
fi
|
|
|
|
# Flush all routes just to make sure it is clean
|
|
if [ "$flushroutes" = YES ]; then
|
|
route flush
|
|
fi
|
|
|
|
# Enable, flush and install packet filter rules before configuring interfaces.
|
|
if [ "$ipfilter" != NO ] && [ -f /etc/ipf.conf ]; then
|
|
echo 'installing packet filter rules ... '
|
|
ipf -E -Fa -f /etc/ipf.conf
|
|
fi
|
|
|
|
# Set the address for the first loopback interface, so that the auto-route
|
|
# from a newly configured interface's address to lo0 works correctly.
|
|
ifconfig lo0 inet localhost
|
|
|
|
# Configure all of the network interfaces listed in $net_interfaces;
|
|
# if $net_interfaces is DEFAULT, grab all interfaces from ifconfig.
|
|
# In the following, "xxN" stands in for interface names, like "le0".
|
|
# For any interfaces that has an $ifconfig_xxN variable associated,
|
|
# we do "ifconfig xxN $ifconfig_xxN".
|
|
# If there is no such variable, we take the contents of the file
|
|
# /etc/ifconfig.xxN, and run "ifconfig xxN" repeatedly, using each
|
|
# line of the file as the arguments for a seperate "ifconfig" invocation.
|
|
#
|
|
# In order to configure an interface reasonably, you at the very least
|
|
# need to specify "[addr_family] [hostname]" (as in "inet my.domain.org"),
|
|
# and probably a netmask (as in "netmask 0xffffffe0"). You will
|
|
# frequently need to specify a media type, as in "media UTP", for
|
|
# interface cards with multiple media connections that do not autoconfigure.
|
|
# see the ifconfig manual page for details.
|
|
|
|
if [ "$net_interfaces" != NO ]; then
|
|
if [ "$net_interfaces" = DEFAULT ]; then
|
|
tmp="`ifconfig -l`"
|
|
else
|
|
tmp="$net_interfaces"
|
|
fi
|
|
echo -n 'configuring network interfaces:'
|
|
for int in $tmp; do
|
|
eval `echo 'args=$ifconfig_'$int`
|
|
if [ -n "$args" ]; then
|
|
echo -n " $int"
|
|
ifconfig $int $args
|
|
elif [ -f /etc/ifconfig.$int ]; then
|
|
echo -n " $int"
|
|
(while read args; do
|
|
ifconfig $int $args
|
|
done) < /etc/ifconfig.$int
|
|
else
|
|
if [ "$net_interfaces" != DEFAULT ]; then
|
|
echo
|
|
echo -n "/etc/ifconfig.$int missing"
|
|
echo -n "& ifconfig_$int not set"
|
|
echo "; interface $int can't be configured"
|
|
fi
|
|
continue
|
|
fi
|
|
configured_interfaces="$configured_interfaces $int"
|
|
done
|
|
echo '.'
|
|
fi
|
|
|
|
# Check $defaultroute, then /etc/mygate, for the name of my gateway host.
|
|
# That name must be in /etc/hosts.
|
|
if [ -z "$defaultroute" -a -f /etc/mygate ]; then
|
|
defaultroute=`cat /etc/mygate`
|
|
fi
|
|
if [ -n "$defaultroute" ]; then
|
|
route add default $defaultroute
|
|
fi
|
|
|
|
# Check if each configured interface xxN has an $ifaliases_xxN variable
|
|
# associated, then configure additional IP addresses for that interface.
|
|
# The variable contains a list of "address netmask" pairs, with "netmask"
|
|
# set to "-" if the interface default netmask is to be used.
|
|
#
|
|
if [ -n "$configured_interfaces" ]; then
|
|
echo 'adding interface aliases:';
|
|
fi
|
|
for int in $configured_interfaces; do
|
|
eval `echo 'args=$ifaliases_'$int`
|
|
if [ -n "$args" ]; then
|
|
set -- $args
|
|
while [ $# -ge 2 ]; do
|
|
addr=$1 ; net=$2 ; shift 2
|
|
if [ "$net" = "-" ]; then
|
|
ifconfig $int inet alias $addr
|
|
else
|
|
ifconfig $int inet alias $addr netmask $net
|
|
fi
|
|
# Use loopback, not the wire
|
|
route add $addr localhost
|
|
done
|
|
fi
|
|
done
|
|
|
|
# /etc/ifaliases, if it exists, contains the names of additional IP
|
|
# addresses for each interface. It is formatted as a series of lines
|
|
# that contain
|
|
# address interface netmask
|
|
if [ -f /etc/ifaliases ]; then
|
|
echo 'adding interface aliases:';
|
|
(
|
|
while read addr int net; do
|
|
if [ -z "$net" ]; then
|
|
ifconfig $int inet alias $addr
|
|
else
|
|
ifconfig $int inet alias $addr netmask $net
|
|
fi
|
|
# use loopback, not the wire
|
|
route add $addr localhost
|
|
done
|
|
) < /etc/ifaliases
|
|
fi
|
|
|
|
if [ -s /etc/netstart.local ]; then
|
|
. /etc/netstart.local
|
|
fi
|