3 # Copyright (c) 1993 The FreeBSD Project
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions
9 # 1. Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
11 # 2. Redistributions in binary form must reproduce the above copyright
12 # notice, this list of conditions and the following disclaimer in the
13 # documentation and/or other materials provided with the distribution.
15 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 # From: @(#)netstart 5.9 (Berkeley) 3/30/91
31 # Note that almost all of the user-configurable behavior is no longer in
32 # this file, but rather in /etc/defaults/rc.conf. Please check that file
33 # first before contemplating any changes here. If you do need to change
34 # this file for some reason, we would like to know about it.
36 # First pass startup stuff.
39 echo -n 'Doing initial network setup:'
41 # Convert host.conf to nsswitch.conf if necessary
42 if [ -f "/etc/host.conf" ]; then
44 echo 'Warning: /etc/host.conf is no longer used'
45 if [ -f "/etc/nsswitch.conf" ]; then
46 echo ' /etc/nsswitch.conf will be used instead'
48 echo ' /etc/nsswitch.conf will be created for you'
49 convert_host_conf /etc/host.conf /etc/nsswitch.conf
53 # Set the host name if it is not already set
55 if [ -z "`hostname -s`" ]; then
60 # Establish ipfilter ruleset as early as possible (best in
61 # addition to IPFILTER_DEFAULT_BLOCK in the kernel config file)
63 case "${ipfilter_enable}" in
65 if [ -r "${ipfilter_rules}" ]; then
67 ${ipfilter_program:-/sbin/ipf -Fa -f} \
68 "${ipfilter_rules}" ${ipfilter_flags}
69 case "${ipmon_enable}" in
72 ${ipmon_program:-/sbin/ipmon} ${ipmon_flags}
75 case "${ipnat_enable}" in
77 if [ -r "${ipnat_rules}" ]; then
79 eval ${ipnat_program:-/sbin/ipnat -CF -f} \
80 "${ipnat_rules}" ${ipnat_flags}
82 echo -n ' NO IPNAT RULES'
88 echo -n ' NO IPF RULES'
93 # Set the domainname if we're using NIS
95 case ${nisdomainname} in
99 domainname ${nisdomainname}
106 # Initial ATM interface configuration
108 case ${atm_enable} in
110 if [ -r /etc/rc.atm ]; then
117 # Special options for sppp(4) interfaces go here. These need
118 # to go _before_ the general ifconfig section, since in the case
119 # of hardwired (no link1 flag) but required authentication, you
120 # cannot pass auth parameters down to the already running interface.
122 for ifn in ${sppp_interfaces}; do
123 eval spppcontrol_args=\$spppconfig_${ifn}
124 if [ -n "${spppcontrol_args}" ]; then
125 # The auth secrets might contain spaces; in order
126 # to retain the quotation, we need to eval them
128 eval spppcontrol ${ifn} ${spppcontrol_args}
132 # Set up all the network interfaces, calling startup scripts if needed
134 case ${network_interfaces} in
136 network_interfaces="`ifconfig -l`"
141 for ifn in ${network_interfaces}; do
142 if [ -r /etc/start_if.${ifn} ]; then
143 . /etc/start_if.${ifn}
147 # Do the primary ifconfig if specified
149 eval ifconfig_args=\$ifconfig_${ifn}
151 case ${ifconfig_args} in
155 # DHCP inits are done all in one go below
156 dhcp_interfaces="$dhcp_interfaces $ifn"
160 ifconfig ${ifn} ${ifconfig_args}
166 if [ ! -z "${dhcp_interfaces}" ]; then
167 ${dhcp_program:-/sbin/dhclient} ${dhcp_flags} ${dhcp_interfaces}
170 for ifn in ${network_interfaces}; do
171 # Check to see if aliases need to be added
175 eval ifconfig_args=\$ifconfig_${ifn}_alias${alias}
176 if [ -n "${ifconfig_args}" ]; then
177 ifconfig ${ifn} ${ifconfig_args} alias
179 alias=`expr ${alias} + 1`
185 # Do ipx address if specified
187 eval ifconfig_args=\$ifconfig_${ifn}_ipx
188 if [ -n "${ifconfig_args}" ]; then
189 ifconfig ${ifn} ${ifconfig_args}
194 for ifn in ${network_interfaces}; do
195 eval showstat=\$showstat_${ifn}
196 if [ ! -z ${showstat} ]; then
201 # ISDN subsystem startup
203 case ${isdn_enable} in
205 if [ -r /etc/rc.isdn ]; then
211 # Start user ppp if required. This must happen before natd.
213 case ${ppp_enable} in
215 # Establish ppp mode.
217 if [ "${ppp_mode}" != "ddial" -a "${ppp_mode}" != "direct" \
218 -a "${ppp_mode}" != "dedicated" \
219 -a "${ppp_mode}" != "background" ]; then
223 ppp_command="/usr/sbin/ppp -quiet -${ppp_mode}"
225 # Switch on NAT mode?
229 ppp_command="${ppp_command} -nat"
233 ppp_command="${ppp_command} ${ppp_profile}"
235 echo -n "Starting ppp as \"${ppp_user}\""
236 su -m ${ppp_user} -c "exec ${ppp_command}"
240 # Initialize IP filtering using ipfw
242 if /sbin/ipfw -q flush > /dev/null 2>&1; then
248 case ${firewall_enable} in
250 if [ "${firewall_in_kernel}" -eq 0 ] && kldload ipfw; then
252 echo 'Kernel firewall module loaded'
253 elif [ "${firewall_in_kernel}" -eq 0 ]; then
254 echo 'Warning: firewall kernel module failed to load'
259 # Load the filters if required
261 case ${firewall_in_kernel} in
263 if [ -z "${firewall_script}" ]; then
264 firewall_script=/etc/rc.firewall
267 case ${firewall_enable} in
269 if [ -r "${firewall_script}" ]; then
270 . "${firewall_script}"
271 echo -n 'Firewall rules loaded, starting divert daemons:'
273 # Network Address Translation daemon
275 case ${natd_enable} in
277 if [ -n "${natd_interface}" ]; then
278 if echo ${natd_interface} | \
279 grep -q -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'; then
280 natd_ifarg="-a ${natd_interface}"
282 natd_ifarg="-n ${natd_interface}"
285 echo -n ' natd'; ${natd_program:-/sbin/natd} ${natd_flags} ${natd_ifarg}
292 elif [ "`ipfw l 65535`" = "65535 deny ip from any to any" ]; then
293 echo 'Warning: kernel has firewall functionality,' \
294 'but firewall rules are not enabled.'
295 echo ' All ip services are disabled.'
298 case ${firewall_logging} in
300 echo 'Firewall logging=YES'
301 sysctl -w net.inet.ip.fw.verbose=1 >/dev/null
312 # Additional ATM interface configuration
314 if [ -n "${atm_pass1_done}" ]; then
320 case ${defaultrouter} in
324 static_routes="default ${static_routes}"
325 route_default="default ${defaultrouter}"
329 # Set up any static routes. This should be done before router discovery.
331 if [ -n "${static_routes}" ]; then
332 for i in ${static_routes}; do
333 eval route_args=\$route_${i}
334 route add ${route_args}
338 echo -n 'Additional routing options:'
339 case ${tcp_extensions} in
343 echo -n ' tcp extensions=NO'
344 sysctl -w net.inet.tcp.rfc1323=0 >/dev/null
348 case ${icmp_bmcastecho} in
350 echo -n ' broadcast ping responses=YES'
351 sysctl -w net.inet.icmp.bmcastecho=1 >/dev/null
355 case ${icmp_drop_redirect} in
357 echo -n ' ignore ICMP redirect=YES'
358 sysctl -w net.inet.icmp.drop_redirect=1 >/dev/null
362 case ${icmp_log_redirect} in
364 echo -n ' log ICMP redirect=YES'
365 sysctl -w net.inet.icmp.log_redirect=1 >/dev/null
369 case ${gateway_enable} in
371 echo -n ' IP gateway=YES'
372 sysctl -w net.inet.ip.forwarding=1 >/dev/null
376 case ${forward_sourceroute} in
378 echo -n ' do source routing=YES'
379 sysctl -w net.inet.ip.sourceroute=1 >/dev/null
383 case ${accept_sourceroute} in
385 echo -n ' accept source routing=YES'
386 sysctl -w net.inet.ip.accept_sourceroute=1 >/dev/null
390 case ${tcp_keepalive} in
392 echo -n ' TCP keepalive=YES'
393 sysctl -w net.inet.tcp.always_keepalive=1 >/dev/null
397 case ${tcp_drop_synfin} in
399 echo -n ' drop SYN+FIN packets=YES'
400 sysctl -w net.inet.tcp.drop_synfin=1 >/dev/null
404 case ${ipxgateway_enable} in
406 echo -n ' IPX gateway=YES'
407 sysctl -w net.ipx.ipx.ipxforwarding=1 >/dev/null
411 case ${arpproxy_all} in
413 echo -n ' ARP proxyall=YES'
414 sysctl -w net.link.ether.inet.proxyall=1 >/dev/null
418 case ${ip_portrange_first} in
422 echo -n " ip_portrange_first=$ip_portrange_first"
423 sysctl -w net.inet.ip.portrange.first=$ip_portrange_first >/dev/null
427 case ${ip_portrange_last} in
431 echo -n " ip_portrange_last=$ip_portrange_last"
432 sysctl -w net.inet.ip.portrange.last=$ip_portrange_last >/dev/null
438 case ${ipsec_enable} in
440 if [ -f ${ipsec_file} ]; then
441 echo ' ipsec: enabled'
442 setkey -f ${ipsec_file}
444 echo ' ipsec: file not found'
449 echo -n 'Routing daemons:'
450 case ${router_enable} in
452 echo -n " ${router}"; ${router} ${router_flags}
456 case ${ipxrouted_enable} in
459 IPXrouted ${ipxrouted_flags} > /dev/null 2>&1
463 case ${mrouted_enable} in
465 echo -n ' mrouted'; mrouted ${mrouted_flags}
469 case ${rarpd_enable} in
471 echo -n ' rarpd'; rarpd ${rarpd_flags}
476 # Let future generations know we made it.
478 network_pass1_done=YES
482 echo -n 'Doing additional network setup:'
483 case ${named_enable} in
485 echo -n ' named'; ${named_program:-named} ${named_flags}
489 case ${ntpdate_enable} in
492 ${ntpdate_program:-ntpdate} ${ntpdate_flags} >/dev/null 2>&1
496 case ${xntpd_enable} in
498 echo -n ' ntpd'; ${xntpd_program:-ntpd} ${xntpd_flags}
502 case ${timed_enable} in
504 echo -n ' timed'; timed ${timed_flags}
508 case ${portmap_enable} in
510 echo -n ' rpcbind'; ${portmap_program:-/usr/sbin/rpcbind} \
513 # Start ypserv if we're an NIS server.
514 # Run rpc.ypxfrd and rpc.yppasswdd only on the NIS master server.
516 case ${nis_server_enable} in
518 echo -n ' ypserv'; ypserv ${nis_server_flags}
520 case ${nis_ypxfrd_enable} in
522 echo -n ' rpc.ypxfrd'
523 rpc.ypxfrd ${nis_ypxfrd_flags}
527 case ${nis_yppasswdd_enable} in
529 echo -n ' rpc.yppasswdd'
530 rpc.yppasswdd ${nis_yppasswdd_flags}
536 # Start ypbind if we're an NIS client
538 case ${nis_client_enable} in
540 echo -n ' ypbind'; ypbind ${nis_client_flags}
541 case ${nis_ypset_enable} in
543 echo -n ' ypset'; ypset ${nis_ypset_flags}
549 # Start keyserv if we are running Secure RPC
551 case ${keyserv_enable} in
553 echo -n ' keyserv'; keyserv ${keyserv_flags}
557 # Start ypupdated if we are running Secure RPC
558 # and we are NIS master
560 case ${rpc_ypupdated_enable} in
562 echo -n ' rpc.ypupdated'; rpc.ypupdated
569 if [ -n "${atm_pass2_done}" ]; then
574 network_pass2_done=YES
578 echo -n 'Starting final network daemons:'
580 case ${portmap_enable} in
582 case ${nfs_server_enable} in
584 if [ -r /etc/exports ]; then
587 case ${weak_mountd_authentication} in
589 mountd_flags="${mountd_flags} -n"
593 mountd ${mountd_flags}
595 case ${nfs_reserved_port_only} in
597 echo -n ' NFS on reserved port only=YES'
598 sysctl -w vfs.nfs.nfs_privport=1 > /dev/null
602 echo -n ' nfsd'; nfsd ${nfs_server_flags}
604 if [ -n "${nfs_bufpackets}" ]; then
605 sysctl -w vfs.nfs.bufpackets=${nfs_bufpackets} > /dev/null
608 case ${rpc_lockd_enable} in
610 echo -n ' rpc.lockd'; rpc.lockd
614 case ${rpc_statd_enable} in
616 echo -n ' rpc.statd'; rpc.statd
622 case ${single_mountd_enable} in
624 if [ -r /etc/exports ]; then
627 case ${weak_mountd_authentication} in
633 mountd ${mountd_flags}
640 case ${nfs_client_enable} in
642 echo -n ' nfsiod'; nfsiod ${nfs_client_flags}
643 if [ -n "${nfs_access_cache}" ]; then
644 echo -n " NFS access cache time=${nfs_access_cache}"
645 sysctl -w vfs.nfs.access_cache_timeout=${nfs_access_cache} >/dev/null
650 # If /var/db/mounttab exists, some nfs-server has not been
651 # sucessfully notified about a previous client shutdown.
652 # If there is no /var/db/mounttab, we do nothing.
653 if [ -f /var/db/mounttab ]; then
657 case ${amd_enable} in
660 case ${amd_map_program} in
664 amd_flags="${amd_flags} `eval\
669 if [ -n "${amd_flags}" ]; then
671 > /var/run/amd.pid 2> /dev/null
680 case ${rwhod_enable} in
682 echo -n ' rwhod'; rwhod ${rwhod_flags}
686 # Kerberos runs ONLY on the Kerberos server machine
687 case ${kerberos_server_enable} in
689 case ${kerberos_stash} in
699 kerberos ${stash_flag} >> /var/log/kerberos.log &
701 case ${kadmind_server_enable} in
704 (sleep 20; kadmind ${stash_flag} >/dev/null 2>&1 &) &
711 case ${pppoed_enable} in
713 if [ -n "${pppoed_provider}" ]; then
714 pppoed_flags="${pppoed_flags} -p ${pppoed_provider}"
717 /usr/libexec/pppoed ${pppoed_flags} ${pppoed_interface}
721 case ${sshd_enable} in
723 if [ ! -f /etc/ssh/ssh_host_key ]; then
724 echo ' creating ssh RSA host key';
725 /usr/bin/ssh-keygen -N "" -f /etc/ssh/ssh_host_key
727 if [ ! -f /etc/ssh/ssh_host_dsa_key ]; then
728 echo ' creating ssh DSA host key';
729 /usr/bin/ssh-keygen -d -N "" -f /etc/ssh/ssh_host_dsa_key
735 network_pass3_done=YES
739 echo -n 'Additional TCP options:'
740 case ${log_in_vain} in
744 echo -n ' log_in_vain=YES'
745 sysctl -w net.inet.tcp.log_in_vain=1 >/dev/null
746 sysctl -w net.inet.udp.log_in_vain=1 >/dev/null
751 network_pass4_done=YES
754 convert_host_conf() {
756 nsswitch_conf=$1; shift;
758 /^[:blank:]*#/ { next } \
759 /(hosts|local|file)/ { nsswitch[c] = "files"; c++; next } \
760 /(dns|bind)/ { nsswitch[c] = "dns"; c++; next } \
761 /nis/ { nsswitch[c] = "nis"; c++; next } \
762 { printf "Warning: unrecognized line [%s]", $0 > "/dev/stderr" } \
765 for (i in nsswitch) printf "%s ", nsswitch[i]; \
767 }' < $host_conf > $nsswitch_conf