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}
135 # Set up all the network interfaces, calling startup scripts if needed
137 case ${network_interfaces} in
139 network_interfaces="`ifconfig -l`"
144 for ifn in ${network_interfaces}; do
145 if [ -r /etc/start_if.${ifn} ]; then
146 . /etc/start_if.${ifn}
150 # Do the primary ifconfig if specified
152 eval ifconfig_args=\$ifconfig_${ifn}
154 case ${ifconfig_args} in
158 # DHCP inits are done all in one go below
159 dhcp_interfaces="$dhcp_interfaces $ifn"
163 ifconfig ${ifn} ${ifconfig_args}
169 if [ ! -z "${dhcp_interfaces}" ]; then
170 ${dhcp_program:-/sbin/dhclient} ${dhcp_flags} ${dhcp_interfaces}
173 for ifn in ${network_interfaces}; do
174 # Check to see if aliases need to be added
178 eval ifconfig_args=\$ifconfig_${ifn}_alias${alias}
179 if [ -n "${ifconfig_args}" ]; then
180 ifconfig ${ifn} ${ifconfig_args} alias
182 alias=`expr ${alias} + 1`
188 # Do ipx address if specified
190 eval ifconfig_args=\$ifconfig_${ifn}_ipx
191 if [ -n "${ifconfig_args}" ]; then
192 ifconfig ${ifn} ${ifconfig_args}
197 for ifn in ${network_interfaces}; do
198 eval showstat=\$showstat_${ifn}
199 if [ ! -z ${showstat} ]; then
204 # ISDN subsystem startup
206 case ${isdn_enable} in
208 if [ -r /etc/rc.isdn ]; then
214 # Start user ppp if required. This must happen before natd.
216 case ${ppp_enable} in
218 # Establish ppp mode.
220 if [ "${ppp_mode}" != "ddial" -a "${ppp_mode}" != "direct" \
221 -a "${ppp_mode}" != "dedicated" \
222 -a "${ppp_mode}" != "background" ]; then
226 ppp_command="/usr/sbin/ppp -quiet -${ppp_mode}"
228 # Switch on NAT mode?
232 ppp_command="${ppp_command} -nat"
236 ppp_command="${ppp_command} ${ppp_profile}"
238 echo "Starting ppp as \"${ppp_user}\""
239 su -m ${ppp_user} -c "exec ${ppp_command}"
243 # Initialize IP filtering using ipfw
245 if /sbin/ipfw -q flush > /dev/null 2>&1; then
251 case ${firewall_enable} in
253 if [ "${firewall_in_kernel}" -eq 0 ] && kldload ipfw; then
255 echo 'Kernel firewall module loaded'
256 elif [ "${firewall_in_kernel}" -eq 0 ]; then
257 echo 'Warning: firewall kernel module failed to load'
262 # Load the filters if required
264 case ${firewall_in_kernel} in
266 if [ -z "${firewall_script}" ]; then
267 firewall_script=/etc/rc.firewall
270 case ${firewall_enable} in
272 if [ -r "${firewall_script}" ]; then
273 . "${firewall_script}"
274 echo -n 'Firewall rules loaded, starting divert daemons:'
276 # Network Address Translation daemon
278 case ${natd_enable} in
280 if [ -n "${natd_interface}" ]; then
281 if echo ${natd_interface} | \
282 grep -q -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'; then
283 natd_ifarg="-a ${natd_interface}"
285 natd_ifarg="-n ${natd_interface}"
288 echo -n ' natd'; ${natd_program:-/sbin/natd} ${natd_flags} ${natd_ifarg}
295 elif [ "`ipfw l 65535`" = "65535 deny ip from any to any" ]; then
296 echo 'Warning: kernel has firewall functionality,' \
297 'but firewall rules are not enabled.'
298 echo ' All ip services are disabled.'
301 case ${firewall_logging} in
303 echo 'Firewall logging=YES'
304 sysctl -w net.inet.ip.fw.verbose=1 >/dev/null
315 # Additional ATM interface configuration
317 if [ -n "${atm_pass1_done}" ]; then
323 case ${defaultrouter} in
327 static_routes="default ${static_routes}"
328 route_default="default ${defaultrouter}"
332 # Set up any static routes. This should be done before router discovery.
334 if [ -n "${static_routes}" ]; then
335 for i in ${static_routes}; do
336 eval route_args=\$route_${i}
337 route add ${route_args}
341 echo -n 'Additional routing options:'
342 case ${tcp_extensions} in
346 echo -n ' tcp extensions=NO'
347 sysctl -w net.inet.tcp.rfc1323=0 >/dev/null
351 case ${icmp_bmcastecho} in
353 echo -n ' broadcast ping responses=YES'
354 sysctl -w net.inet.icmp.bmcastecho=1 >/dev/null
358 case ${icmp_drop_redirect} in
360 echo -n ' ignore ICMP redirect=YES'
361 sysctl -w net.inet.icmp.drop_redirect=1 >/dev/null
365 case ${icmp_log_redirect} in
367 echo -n ' log ICMP redirect=YES'
368 sysctl -w net.inet.icmp.log_redirect=1 >/dev/null
372 case ${gateway_enable} in
374 echo -n ' IP gateway=YES'
375 sysctl -w net.inet.ip.forwarding=1 >/dev/null
379 case ${forward_sourceroute} in
381 echo -n ' do source routing=YES'
382 sysctl -w net.inet.ip.sourceroute=1 >/dev/null
386 case ${accept_sourceroute} in
388 echo -n ' accept source routing=YES'
389 sysctl -w net.inet.ip.accept_sourceroute=1 >/dev/null
393 case ${tcp_keepalive} in
395 echo -n ' TCP keepalive=YES'
396 sysctl -w net.inet.tcp.always_keepalive=1 >/dev/null
400 case ${tcp_drop_synfin} in
402 echo -n ' drop SYN+FIN packets=YES'
403 sysctl -w net.inet.tcp.drop_synfin=1 >/dev/null
407 case ${ipxgateway_enable} in
409 echo -n ' IPX gateway=YES'
410 sysctl -w net.ipx.ipx.ipxforwarding=1 >/dev/null
414 case ${arpproxy_all} in
416 echo -n ' ARP proxyall=YES'
417 sysctl -w net.link.ether.inet.proxyall=1 >/dev/null
421 case ${ip_portrange_first} in
425 echo -n " ip_portrange_first=$ip_portrange_first"
426 sysctl -w net.inet.ip.portrange.first=$ip_portrange_first >/dev/null
430 case ${ip_portrange_last} in
434 echo -n " ip_portrange_last=$ip_portrange_last"
435 sysctl -w net.inet.ip.portrange.last=$ip_portrange_last >/dev/null
441 case ${ipsec_enable} in
443 if [ -f ${ipsec_file} ]; then
444 echo ' ipsec: enabled'
445 setkey -f ${ipsec_file}
447 echo ' ipsec: file not found'
452 echo -n 'Routing daemons:'
453 case ${router_enable} in
455 echo -n " ${router}"; ${router} ${router_flags}
459 case ${ipxrouted_enable} in
462 IPXrouted ${ipxrouted_flags} > /dev/null 2>&1
466 case ${mrouted_enable} in
468 echo -n ' mrouted'; mrouted ${mrouted_flags}
472 case ${rarpd_enable} in
474 echo -n ' rarpd'; rarpd ${rarpd_flags}
479 # Let future generations know we made it.
481 network_pass1_done=YES
485 echo -n 'Doing additional network setup:'
486 case ${named_enable} in
488 echo -n ' named'; ${named_program:-named} ${named_flags}
492 case ${ntpdate_enable} in
495 ${ntpdate_program:-ntpdate} ${ntpdate_flags} >/dev/null 2>&1
499 case ${xntpd_enable} in
501 echo -n ' ntpd'; ${xntpd_program:-ntpd} ${xntpd_flags}
505 case ${timed_enable} in
507 echo -n ' timed'; timed ${timed_flags}
511 case ${portmap_enable} in
513 echo -n ' rpcbind'; ${portmap_program:-/usr/sbin/rpcbind} \
516 # Start ypserv if we're an NIS server.
517 # Run rpc.ypxfrd and rpc.yppasswdd only on the NIS master server.
519 case ${nis_server_enable} in
521 echo -n ' ypserv'; ypserv ${nis_server_flags}
523 case ${nis_ypxfrd_enable} in
525 echo -n ' rpc.ypxfrd'
526 rpc.ypxfrd ${nis_ypxfrd_flags}
530 case ${nis_yppasswdd_enable} in
532 echo -n ' rpc.yppasswdd'
533 rpc.yppasswdd ${nis_yppasswdd_flags}
539 # Start ypbind if we're an NIS client
541 case ${nis_client_enable} in
543 echo -n ' ypbind'; ypbind ${nis_client_flags}
544 case ${nis_ypset_enable} in
546 echo -n ' ypset'; ypset ${nis_ypset_flags}
552 # Start keyserv if we are running Secure RPC
554 case ${keyserv_enable} in
556 echo -n ' keyserv'; keyserv ${keyserv_flags}
560 # Start ypupdated if we are running Secure RPC
561 # and we are NIS master
563 case ${rpc_ypupdated_enable} in
565 echo -n ' rpc.ypupdated'; rpc.ypupdated
572 if [ -n "${atm_pass2_done}" ]; then
577 network_pass2_done=YES
581 echo -n 'Starting final network daemons:'
583 case ${portmap_enable} in
585 case ${nfs_server_enable} in
587 if [ -r /etc/exports ]; then
590 case ${weak_mountd_authentication} in
592 mountd_flags="${mountd_flags} -n"
596 mountd ${mountd_flags}
598 case ${nfs_reserved_port_only} in
600 echo -n ' NFS on reserved port only=YES'
601 sysctl -w vfs.nfs.nfs_privport=1 > /dev/null
605 echo -n ' nfsd'; nfsd ${nfs_server_flags}
607 if [ -n "${nfs_bufpackets}" ]; then
608 sysctl -w vfs.nfs.bufpackets=${nfs_bufpackets} > /dev/null
611 case ${rpc_lockd_enable} in
613 echo -n ' rpc.lockd'; rpc.lockd
617 case ${rpc_statd_enable} in
619 echo -n ' rpc.statd'; rpc.statd
625 case ${single_mountd_enable} in
627 if [ -r /etc/exports ]; then
630 case ${weak_mountd_authentication} in
636 mountd ${mountd_flags}
643 case ${nfs_client_enable} in
645 echo -n ' nfsiod'; nfsiod ${nfs_client_flags}
646 if [ -n "${nfs_access_cache}" ]; then
647 echo -n " NFS access cache time=${nfs_access_cache}"
648 sysctl -w vfs.nfs.access_cache_timeout=${nfs_access_cache} >/dev/null
653 # If /var/db/mounttab exists, some nfs-server has not been
654 # sucessfully notified about a previous client shutdown.
655 # If there is no /var/db/mounttab, we do nothing.
656 if [ -f /var/db/mounttab ]; then
660 case ${amd_enable} in
663 case ${amd_map_program} in
667 amd_flags="${amd_flags} `eval\
672 if [ -n "${amd_flags}" ]; then
674 > /var/run/amd.pid 2> /dev/null
683 case ${rwhod_enable} in
685 echo -n ' rwhod'; rwhod ${rwhod_flags}
689 # Kerberos runs ONLY on the Kerberos server machine
690 case ${kerberos_server_enable} in
692 case ${kerberos_stash} in
702 kerberos ${stash_flag} >> /var/log/kerberos.log &
704 case ${kadmind_server_enable} in
707 (sleep 20; kadmind ${stash_flag} >/dev/null 2>&1 &) &
714 case ${pppoed_enable} in
716 if [ -n "${pppoed_provider}" ]; then
717 pppoed_flags="${pppoed_flags} -p ${pppoed_provider}"
720 /usr/libexec/pppoed ${pppoed_flags} ${pppoed_interface}
724 case ${sshd_enable} in
726 if [ ! -f /etc/ssh/ssh_host_key ]; then
727 echo ' creating ssh RSA host key';
728 /usr/bin/ssh-keygen -N "" -f /etc/ssh/ssh_host_key
730 if [ ! -f /etc/ssh/ssh_host_dsa_key ]; then
731 echo ' creating ssh DSA host key';
732 /usr/bin/ssh-keygen -d -N "" -f /etc/ssh/ssh_host_dsa_key
738 network_pass3_done=YES
742 echo -n 'Additional TCP options:'
743 case ${log_in_vain} in
747 echo -n ' log_in_vain=YES'
748 sysctl -w net.inet.tcp.log_in_vain=1 >/dev/null
749 sysctl -w net.inet.udp.log_in_vain=1 >/dev/null
754 network_pass4_done=YES
757 network_gif_setup() {
758 case ${gif_interfaces} in
762 for i in ${gif_interfaces}; do
763 eval peers=\$gifconfig_$i
769 ifconfig $i tunnel ${peers}
777 convert_host_conf() {
779 nsswitch_conf=$1; shift;
781 /^[:blank:]*#/ { next } \
782 /(hosts|local|file)/ { nsswitch[c] = "files"; c++; next } \
783 /(dns|bind)/ { nsswitch[c] = "dns"; c++; next } \
784 /nis/ { nsswitch[c] = "nis"; c++; next } \
785 { printf "Warning: unrecognized line [%s]", $0 > "/dev/stderr" } \
788 for (i in nsswitch) printf "%s ", nsswitch[i]; \
790 }' < $host_conf > $nsswitch_conf