3 # $NetBSD: network,v 1.29 2001/01/11 17:56:16 itojun Exp $
4 # $FreeBSD: src/etc/rc.d/network,v 1.3 2002/08/12 10:04:32 schweikh Exp $
5 # $DragonFly: src/etc/rc.d/Attic/network,v 1.1 2003/07/24 06:35:37 dillon Exp $
8 # REQUIRE: ipfilter ipsec mountcritlocal root tty sysctl
13 start_cmd="network_start"
14 stop_cmd="network_stop"
18 # set hostname, turn on network
20 echo "Starting network."
22 # If $hostname is set, use it for my Internet name,
23 # otherwise use /etc/myname
25 if [ -z "$hostname" ] && [ -f /etc/myname ]; then
26 hostname=`cat /etc/myname`
28 if [ -n "$hostname" ]; then
29 echo "Hostname: $hostname"
32 # Don't warn about it if we're going to run
33 # DHCP later, as we will probably get the
34 # hostname at that time.
36 if ! checkyesno dhclient && [ -z "`hostname`" ]; then
37 warn "\$hostname not set."
41 # Check $domainname first, then /etc/defaultdomain,
42 # for NIS/YP domain name
44 if [ -z "$domainname" ] && [ -f /etc/defaultdomain ]; then
45 domainname=`cat /etc/defaultdomain`
47 if [ -n "$domainname" ]; then
48 echo "NIS domainname: $domainname"
49 domainname $domainname
52 # Flush all routes just to make sure it is clean
53 if checkyesno flushroutes; then
57 # Set the address for the first loopback interface, so that the
58 # auto-route from a newly configured interface's address to lo0
61 # NOTE: obscure networking problems may occur if lo0 isn't configured...
63 ifconfig lo0 inet 127.0.0.1
65 # According to RFC1122, 127.0.0.0/8 should not leave the node.
67 route add -inet 127.0.0.0 -netmask 0xff000000 127.0.0.1 -reject
69 # IPv6 routing setups, and host/router mode selection.
71 if ifconfig lo0 inet6 >/dev/null 2>&1; then
72 # We have IPv6 support in kernel.
74 # disallow link-local unicast dest without outgoing scope
77 route add -inet6 fe80:: -prefixlen 10 ::1 -reject
79 # disallow site-local unicast dest without outgoing scope
81 # If you configure site-locals without scope id (it is
82 # permissible config for routers that are not on scope
83 # boundary), you may want to comment the following one out.
85 if ! checkyesno ip6sitelocal; then
86 route add -inet6 fec0:: -prefixlen 10 ::1 -reject
89 # disallow "internal" addresses to appear on the wire.
91 route add -inet6 ::ffff:0.0.0.0 -prefixlen 96 ::1 -reject
93 # disallow packets to malicious IPv4 compatible prefix
95 route add -inet6 ::224.0.0.0 -prefixlen 100 ::1 -reject
96 route add -inet6 ::127.0.0.0 -prefixlen 104 ::1 -reject
97 route add -inet6 ::0.0.0.0 -prefixlen 104 ::1 -reject
98 route add -inet6 ::255.0.0.0 -prefixlen 104 ::1 -reject
100 # disallow packets to malicious 6to4 prefix
102 route add -inet6 2002:e000:: -prefixlen 20 ::1 -reject
103 route add -inet6 2002:7f00:: -prefixlen 24 ::1 -reject
104 route add -inet6 2002:0000:: -prefixlen 24 ::1 -reject
105 route add -inet6 2002:ff00:: -prefixlen 24 ::1 -reject
107 # Completely disallow packets to IPv4 compatible prefix.
108 # This may conflict with RFC1933 under following circumstances:
109 # (1) An IPv6-only KAME node tries to originate packets to IPv4
110 # compatible destination. The KAME node has no IPv4
111 # compatible support. Under RFC1933, it should transmit
112 # native IPv6 packets toward IPv4 compatible destination,
113 # hoping it would reach a router that forwards the packet
114 # toward auto-tunnel interface.
115 # (2) An IPv6-only node originates a packet to IPv4 compatible
116 # destination. A KAME node is acting as an IPv6 router, and
117 # asked to forward it.
118 # Due to rare use of IPv4 compatible address, and security
119 # issues with it, we disable it by default.
121 route add -inet6 ::0.0.0.0 -prefixlen 96 ::1 -reject
123 sysctl net.inet6.ip6.forwarding=0 >/dev/null
124 sysctl net.inet6.ip6.accept_rtadv=0 >/dev/null
126 # backward compatibility
128 if [ -z "$ip6mode" ] && [ -n "$ip6forwarding" ]; then
129 warn 'Please migrate to newer rc.conf' \
130 '(use ip6mode, not ip6forwarding)'
131 if checkyesno ip6forwarding; then
133 elif checkyesno rtsol; then
142 echo 'IPv6 mode: router'
143 sysctl net.inet6.ip6.forwarding=1 >/dev/null
147 echo 'IPv6 mode: autoconfigured host'
148 sysctl net.inet6.ip6.accept_rtadv=1 >/dev/null
152 echo 'IPv6 mode: host'
155 *) echo 'WARNING: invalid value in ip6mode'
161 # Configure all of the network interfaces listed in $net_interfaces;
162 # if $auto_ifconfig is YES, grab all interfaces from ifconfig.
163 # In the following, "xxN" stands in for interface names, like "le0".
164 # For any interfaces that has an $ifconfig_xxN variable associated,
165 # we do "ifconfig xxN $ifconfig_xxN".
166 # If there is no such variable, we take the contents of the file
167 # /etc/ifconfig.xxN, and run "ifconfig xxN" repeatedly, using each
168 # line of the file as the arguments for a separate "ifconfig"
171 # In order to configure an interface reasonably, you at the very least
172 # need to specify "[addr_family] [hostname]" (e.g "inet my.domain.org"),
173 # and probably a netmask (as in "netmask 0xffffffe0"). You will
174 # frequently need to specify a media type, as in "media UTP", for
175 # interface cards with multiple media connections that do not
176 # autoconfigure. See the ifconfig manual page for details.
178 # Note that /etc/ifconfig.xxN takes multiple lines. The following
179 # configuration is possible:
180 # inet 10.1.1.1 netmask 0xffffff00
181 # inet 10.1.1.2 netmask 0xffffff00 alias
182 # inet6 fec0::1 prefixlen 64 alias
184 # You can put shell script fragment into /etc/ifconfig.xxN by
185 # starting a line with "!". Refer to ifconfig.if(5) for details.
187 if [ "$net_interfaces" != NO ]; then
188 if checkyesno auto_ifconfig; then
190 for cloner in `ifconfig -C 2>/dev/null`; do
191 for int in /etc/ifconfig.${cloner}[0-9]*; do
192 [ ! -f $int ] && break
193 tmp="$tmp ${int##*.}"
197 tmp="$net_interfaces"
199 echo -n 'Configuring network interfaces:'
201 eval args=\$ifconfig_$int
202 if [ -n "$args" ]; then
205 elif [ -f /etc/ifconfig.$int ]; then
208 [ -z "$args" ] && continue
219 done < /etc/ifconfig.$int
221 if ! checkyesno auto_ifconfig; then
224 "/etc/ifconfig.$int missing and ifconfig_$int not set;"
225 warn "interface $int not configured."
229 configured_interfaces="$configured_interfaces $int"
234 # Check $defaultroute, then /etc/mygate, for the name of my gateway
235 # host. That name must be in /etc/hosts.
237 if [ -z "$defaultroute" ] && [ -f /etc/mygate ]; then
238 defaultroute=`cat /etc/mygate`
240 if [ -n "$defaultroute" ]; then
241 route add default $defaultroute
244 # Check if each configured interface xxN has an $ifaliases_xxN variable
245 # associated, then configure additional IP addresses for that interface.
246 # The variable contains a list of "address netmask" pairs, with
247 # "netmask" set to "-" if the interface default netmask is to be used.
249 # Note that $ifaliases_xxN works only with certain configurations and
250 # considered not recommended. Use /etc/ifconfig.xxN if possible.
253 if [ -n "$configured_interfaces" ]; then
254 echo "Adding interface aliases:"
255 done_aliases_message=yes
257 for int in $configured_interfaces; do
258 eval args=\$ifaliases_$int
259 if [ -n "$args" ]; then
261 while [ $# -ge 2 ]; do
262 addr=$1 ; net=$2 ; shift 2
263 if [ "$net" = "-" ]; then
264 # for compatibility only, obsolete
265 ifconfig $int inet alias $addr
267 ifconfig $int inet alias $addr \
270 # Use loopback, not the wire
271 route add $addr 127.0.0.1
276 # /etc/ifaliases, if it exists, contains the names of additional IP
277 # addresses for each interface. It is formatted as a series of lines
279 # address interface netmask
281 # Note that /etc/ifaliases works only with certain cases only and its
282 # use is not recommended. Use /etc/ifconfig.xxN instead.
285 if [ -f /etc/ifaliases ]; then
286 if [ "$done_aliases_message" != yes ]; then
287 echo "Adding interface aliases:"
289 while read addr int net; do
290 if [ -z "$net" ]; then
291 # for compatibility only, obsolete
292 ifconfig $int inet alias $addr
294 ifconfig $int inet alias $addr netmask $net
296 # use loopback, not the wire
297 route add $addr 127.0.0.1
298 done < /etc/ifaliases
301 # IPv6 interface autoconfiguration.
303 if ifconfig lo0 inet6 >/dev/null 2>&1; then
304 # wait till DAD is completed. always invoke it in case
305 # if are configured manually by ifconfig
307 dadcount=`sysctl -n net.inet6.ip6.dad_count 2>/dev/null`
311 if checkyesno rtsol; then
312 if [ "$ip6mode" = "autohost" ]; then
313 echo 'Sending router solicitation...'
318 "ip6mode must be set to 'autohost' to use rtsol."
321 # wait till DAD is completed, for global addresses
322 # configured by router advert message.
330 if [ -s /etc/netstart.local ]; then
331 sh /etc/netstart.local start
337 echo "Stopping network."
340 if [ -s /etc/netstart.local ]; then
341 sh /etc/netstart.local stop
344 echo "Deleting aliases."
345 if [ -f /etc/ifaliases ]; then
346 while read addr int net; do
347 ifconfig $int inet delete $addr
348 done < /etc/ifaliases
351 for int in `ifconfig -lu`; do
352 eval args=\$ifaliases_$int
353 if [ -n "$args" ]; then
355 while [ $# -ge 2 ]; do
356 addr=$1 ; net=$2 ; shift 2
357 ifconfig $int inet delete $addr
364 echo -n 'Downing network interfaces:'
365 if [ "$net_interfaces" != NO ]; then
366 if checkyesno auto_ifconfig; then
369 tmp="$net_interfaces"
372 eval args=\$ifconfig_$int
373 if [ -n "$args" ] || [ -f /etc/ifconfig.$int ]; then