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 if /sbin/ipfstat -i > /dev/null 2>&1; then
69 case "${ipfilter_enable}" in
71 if [ "${ipfilter_in_kernel}" -eq 0 ] && kldload ipl; then
73 echo "Kernel ipfilter module loaded."
74 elif [ "${ipfilter_in_kernel}" -eq 0 ]; then
75 echo "Warning: ipfilter kernel module failed to load."
78 if [ -r "${ipfilter_rules}" ]; then
80 ${ipfilter_program:-/sbin/ipf -Fa -f} \
81 "${ipfilter_rules}" ${ipfilter_flags}
82 case "${ipmon_enable}" in
85 ${ipmon_program:-/sbin/ipmon} ${ipmon_flags}
88 case "${ipfs_enable}" in
90 if [ -r "/var/db/ipf/ipstate.ipf" ]; then
92 eval ${ipfs_program:-/sbin/ipfs -R} \
99 echo -n ' NO IPF RULES'
102 case "${ipnat_enable}" in
104 if [ "${ipfilter_in_kernel}" -eq 0 ] && kldload ipl; then
106 echo "Kernel ipfilter module loaded."
107 elif [ "${ipfilter_in_kernel}" -eq 0 ]; then
108 echo "Warning: ipfilter kernel module failed to load."
110 if [ -r "${ipnat_rules}" ]; then
112 eval ${ipnat_program:-/sbin/ipnat -CF -f} \
113 "${ipnat_rules}" ${ipnat_flags}
115 echo -n ' NO IPNAT RULES'
120 # Set the domainname if we're using NIS
122 case ${nisdomainname} in
126 domainname ${nisdomainname}
133 # Initial ATM interface configuration
135 case ${atm_enable} in
137 if [ -r /etc/rc.atm ]; then
144 # Attempt to create cloned interfaces.
145 for ifn in ${cloned_interfaces}; do
146 ifconfig ${ifn} create
149 # Special options for sppp(4) interfaces go here. These need
150 # to go _before_ the general ifconfig section, since in the case
151 # of hardwired (no link1 flag) but required authentication, you
152 # cannot pass auth parameters down to the already running interface.
154 for ifn in ${sppp_interfaces}; do
155 eval spppcontrol_args=\$spppconfig_${ifn}
156 if [ -n "${spppcontrol_args}" ]; then
157 # The auth secrets might contain spaces; in order
158 # to retain the quotation, we need to eval them
160 eval spppcontrol ${ifn} ${spppcontrol_args}
167 # Set up all the network interfaces, calling startup scripts if needed
169 case ${network_interfaces} in
171 network_interfaces="`ifconfig -l`"
174 network_interfaces="${network_interfaces} ${cloned_interfaces}"
179 for ifn in ${network_interfaces}; do
180 if [ -r /etc/start_if.${ifn} ]; then
181 . /etc/start_if.${ifn}
185 # Do the primary ifconfig if specified
187 eval ifconfig_args=\$ifconfig_${ifn}
189 case ${ifconfig_args} in
193 # DHCP inits are done all in one go below
194 dhcp_interfaces="$dhcp_interfaces $ifn"
198 ifconfig ${ifn} ${ifconfig_args}
204 if [ ! -z "${dhcp_interfaces}" ]; then
205 ${dhcp_program:-/sbin/dhclient} ${dhcp_flags} ${dhcp_interfaces}
208 for ifn in ${network_interfaces}; do
209 # Check to see if aliases need to be added
213 eval ifconfig_args=\$ifconfig_${ifn}_alias${alias}
214 if [ -n "${ifconfig_args}" ]; then
215 ifconfig ${ifn} ${ifconfig_args} alias
217 alias=`expr ${alias} + 1`
223 # Do ipx address if specified
225 eval ifconfig_args=\$ifconfig_${ifn}_ipx
226 if [ -n "${ifconfig_args}" ]; then
227 ifconfig ${ifn} ${ifconfig_args}
232 for ifn in ${network_interfaces}; do
233 eval showstat=\$showstat_${ifn}
234 if [ ! -z ${showstat} ]; then
239 # ISDN subsystem startup
241 case ${isdn_enable} in
243 if [ -r /etc/rc.isdn ]; then
249 # Start user ppp if required. This must happen before natd.
251 case ${ppp_enable} in
253 # Establish ppp mode.
255 if [ "${ppp_mode}" != "ddial" -a "${ppp_mode}" != "direct" \
256 -a "${ppp_mode}" != "dedicated" \
257 -a "${ppp_mode}" != "background" ]; then
261 ppp_command="/usr/sbin/ppp -quiet -${ppp_mode}"
263 # Switch on NAT mode?
267 ppp_command="${ppp_command} -nat"
271 ppp_command="${ppp_command} ${ppp_profile}"
273 echo "Starting ppp as \"${ppp_user}\""
274 su -m ${ppp_user} -c "exec ${ppp_command}"
280 case ${ipfilter_enable} in
282 ${ipfilter_program:-/sbin/ipf -y}
285 case ${ipnat_enable} in
287 ${ipfilter_program:-/sbin/ipf -y}
292 # Initialize IP filtering using ipfw
294 if /sbin/ipfw -q flush > /dev/null 2>&1; then
300 case ${firewall_enable} in
302 if [ "${firewall_in_kernel}" -eq 0 ] && kldload ipfw; then
304 echo 'Kernel firewall module loaded'
305 elif [ "${firewall_in_kernel}" -eq 0 ]; then
306 echo 'Warning: firewall kernel module failed to load'
311 # Load the filters if required
313 case ${firewall_in_kernel} in
315 if [ -z "${firewall_script}" ]; then
316 firewall_script=/etc/rc.firewall
319 case ${firewall_enable} in
321 if [ -r "${firewall_script}" ]; then
322 . "${firewall_script}"
323 echo -n 'Firewall rules loaded, starting divert daemons:'
325 # Network Address Translation daemon
327 case ${natd_enable} in
329 if [ -n "${natd_interface}" ]; then
330 if echo ${natd_interface} | \
331 grep -q -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'; then
332 natd_ifarg="-a ${natd_interface}"
334 natd_ifarg="-n ${natd_interface}"
337 echo -n ' natd'; ${natd_program:-/sbin/natd} ${natd_flags} ${natd_ifarg}
344 elif [ "`ipfw l 65535`" = "65535 deny ip from any to any" ]; then
345 echo 'Warning: kernel has firewall functionality,' \
346 'but firewall rules are not enabled.'
347 echo ' All ip services are disabled.'
350 case ${firewall_logging} in
352 echo 'Firewall logging=YES'
353 sysctl -w net.inet.ip.fw.verbose=1 >/dev/null
364 # Additional ATM interface configuration
366 if [ -n "${atm_pass1_done}" ]; then
372 case ${defaultrouter} in
376 static_routes="default ${static_routes}"
377 route_default="default ${defaultrouter}"
381 # Set up any static routes. This should be done before router discovery.
383 if [ -n "${static_routes}" ]; then
384 for i in ${static_routes}; do
385 eval route_args=\$route_${i}
386 route add ${route_args}
390 echo -n 'Additional routing options:'
391 case ${tcp_extensions} in
395 echo -n ' tcp extensions=NO'
396 sysctl -w net.inet.tcp.rfc1323=0 >/dev/null
400 case ${icmp_bmcastecho} in
402 echo -n ' broadcast ping responses=YES'
403 sysctl -w net.inet.icmp.bmcastecho=1 >/dev/null
407 case ${icmp_drop_redirect} in
409 echo -n ' ignore ICMP redirect=YES'
410 sysctl -w net.inet.icmp.drop_redirect=1 >/dev/null
414 case ${icmp_log_redirect} in
416 echo -n ' log ICMP redirect=YES'
417 sysctl -w net.inet.icmp.log_redirect=1 >/dev/null
421 case ${gateway_enable} in
423 echo -n ' IP gateway=YES'
424 sysctl -w net.inet.ip.forwarding=1 >/dev/null
428 case ${forward_sourceroute} in
430 echo -n ' do source routing=YES'
431 sysctl -w net.inet.ip.sourceroute=1 >/dev/null
435 case ${accept_sourceroute} in
437 echo -n ' accept source routing=YES'
438 sysctl -w net.inet.ip.accept_sourceroute=1 >/dev/null
442 case ${tcp_keepalive} in
444 echo -n ' TCP keepalive=YES'
445 sysctl -w net.inet.tcp.always_keepalive=1 >/dev/null
449 case ${tcp_drop_synfin} in
451 echo -n ' drop SYN+FIN packets=YES'
452 sysctl -w net.inet.tcp.drop_synfin=1 >/dev/null
456 case ${ipxgateway_enable} in
458 echo -n ' IPX gateway=YES'
459 sysctl -w net.ipx.ipx.ipxforwarding=1 >/dev/null
463 case ${arpproxy_all} in
465 echo -n ' ARP proxyall=YES'
466 sysctl -w net.link.ether.inet.proxyall=1 >/dev/null
470 case ${ip_portrange_first} in
474 echo -n " ip_portrange_first=$ip_portrange_first"
475 sysctl -w net.inet.ip.portrange.first=$ip_portrange_first >/dev/null
479 case ${ip_portrange_last} in
483 echo -n " ip_portrange_last=$ip_portrange_last"
484 sysctl -w net.inet.ip.portrange.last=$ip_portrange_last >/dev/null
490 case ${ipsec_enable} in
492 if [ -f ${ipsec_file} ]; then
493 echo ' ipsec: enabled'
494 setkey -f ${ipsec_file}
496 echo ' ipsec: file not found'
501 echo -n 'Routing daemons:'
502 case ${router_enable} in
504 echo -n " ${router}"; ${router} ${router_flags}
508 case ${ipxrouted_enable} in
511 IPXrouted ${ipxrouted_flags} > /dev/null 2>&1
515 case ${mrouted_enable} in
517 echo -n ' mrouted'; mrouted ${mrouted_flags}
521 case ${rarpd_enable} in
523 echo -n ' rarpd'; rarpd ${rarpd_flags}
528 # Let future generations know we made it.
530 network_pass1_done=YES
534 echo -n 'Doing additional network setup:'
535 case ${named_enable} in
537 echo -n ' named'; ${named_program:-named} ${named_flags}
541 case ${ntpdate_enable} in
544 ${ntpdate_program:-ntpdate} ${ntpdate_flags} >/dev/null 2>&1
548 case ${xntpd_enable} in
550 echo -n ' ntpd'; ${xntpd_program:-ntpd} ${xntpd_flags}
554 case ${timed_enable} in
556 echo -n ' timed'; timed ${timed_flags}
560 case ${portmap_enable} in
562 echo -n ' rpcbind'; ${portmap_program:-/usr/sbin/rpcbind} \
565 # Start ypserv if we're an NIS server.
566 # Run rpc.ypxfrd and rpc.yppasswdd only on the NIS master server.
568 case ${nis_server_enable} in
570 echo -n ' ypserv'; ypserv ${nis_server_flags}
572 case ${nis_ypxfrd_enable} in
574 echo -n ' rpc.ypxfrd'
575 rpc.ypxfrd ${nis_ypxfrd_flags}
579 case ${nis_yppasswdd_enable} in
581 echo -n ' rpc.yppasswdd'
582 rpc.yppasswdd ${nis_yppasswdd_flags}
588 # Start ypbind if we're an NIS client
590 case ${nis_client_enable} in
592 echo -n ' ypbind'; ypbind ${nis_client_flags}
593 case ${nis_ypset_enable} in
595 echo -n ' ypset'; ypset ${nis_ypset_flags}
601 # Start keyserv if we are running Secure RPC
603 case ${keyserv_enable} in
605 echo -n ' keyserv'; keyserv ${keyserv_flags}
609 # Start ypupdated if we are running Secure RPC
610 # and we are NIS master
612 case ${rpc_ypupdated_enable} in
614 echo -n ' rpc.ypupdated'; rpc.ypupdated
621 if [ -n "${atm_pass2_done}" ]; then
626 network_pass2_done=YES
630 echo -n 'Starting final network daemons:'
632 case ${portmap_enable} in
634 case ${nfs_server_enable} in
636 # Handle absent nfs server support
637 nfsserver_in_kernel=0
638 if sysctl vfs.nfsrv >/dev/null 2>&1; then
639 nfsserver_in_kernel=1
641 kldload nfsserver && nfsserver_in_kernel=1
644 if [ -r /etc/exports -a \
645 ${nfsserver_in_kernel} -eq 1 ]; then
648 case ${weak_mountd_authentication} in
650 mountd_flags="${mountd_flags} -n"
654 mountd ${mountd_flags}
656 case ${nfs_reserved_port_only} in
658 echo -n ' NFS on reserved port only=YES'
659 sysctl -w vfs.nfsrv.nfs_privport=1 > /dev/null
663 echo -n ' nfsd'; nfsd ${nfs_server_flags}
665 case ${rpc_lockd_enable} in
667 echo -n ' rpc.lockd'; rpc.lockd
671 case ${rpc_statd_enable} in
673 echo -n ' rpc.statd'; rpc.statd
677 echo -n ' Warning: nfs server failed'
681 case ${single_mountd_enable} in
683 if [ -r /etc/exports ]; then
686 case ${weak_mountd_authentication} in
692 mountd ${mountd_flags}
699 case ${nfs_client_enable} in
701 if [ -n "${nfs_access_cache}" ]; then
702 echo -n " NFS access cache time=${nfs_access_cache}"
703 sysctl -w vfs.nfs.access_cache_timeout=${nfs_access_cache} >/dev/null
705 if [ -n "${nfs_bufpackets}" ]; then
706 sysctl -w vfs.nfs.bufpackets=${nfs_bufpackets} > /dev/null
711 # If /var/db/mounttab exists, some nfs-server has not been
712 # sucessfully notified about a previous client shutdown.
713 # If there is no /var/db/mounttab, we do nothing.
714 if [ -f /var/db/mounttab ]; then
718 case ${amd_enable} in
721 case ${amd_map_program} in
725 amd_flags="${amd_flags} `eval\
730 if [ -n "${amd_flags}" ]; then
732 > /var/run/amd.pid 2> /dev/null
741 case ${rwhod_enable} in
743 echo -n ' rwhod'; rwhod ${rwhod_flags}
747 # Kerberos servers run ONLY on the Kerberos server machine
748 case ${kerberos4_server_enable} in
750 case ${kerberos_stash} in
759 echo -n ' kerberosIV'
760 ${kerberos4_server} ${stash} >> /var/log/kerberos.log &
762 case ${kadmind4_server_enable} in
767 ${kadmind4_server} ${stash} >/dev/null 2>&1 &
775 case ${kerberos5_server_enable} in
778 ${kerberos5_server} &
780 case ${kadmind5_server_enable} in
789 case ${pppoed_enable} in
791 if [ -n "${pppoed_provider}" ]; then
792 pppoed_flags="${pppoed_flags} -p ${pppoed_provider}"
795 /usr/libexec/pppoed ${pppoed_flags} ${pppoed_interface}
799 case ${sshd_enable} in
801 if [ ! -f /etc/ssh/ssh_host_key ]; then
802 echo ' creating ssh RSA host key';
803 /usr/bin/ssh-keygen -N "" -f /etc/ssh/ssh_host_key
805 if [ ! -f /etc/ssh/ssh_host_dsa_key ]; then
806 echo ' creating ssh DSA host key';
807 /usr/bin/ssh-keygen -d -N "" -f /etc/ssh/ssh_host_dsa_key
813 network_pass3_done=YES
817 echo -n 'Additional TCP options:'
818 case ${log_in_vain} in
822 echo -n ' log_in_vain=YES'
823 sysctl -w net.inet.tcp.log_in_vain=1 >/dev/null
824 sysctl -w net.inet.udp.log_in_vain=1 >/dev/null
829 network_pass4_done=YES
832 network_gif_setup() {
833 case ${gif_interfaces} in
837 for i in ${gif_interfaces}; do
838 eval peers=\$gifconfig_$i
844 ifconfig $i create >/dev/null 2>&1
845 ifconfig $i tunnel ${peers}
853 convert_host_conf() {
855 nsswitch_conf=$1; shift;
857 /^[:blank:]*#/ { next } \
858 /(hosts|local|file)/ { nsswitch[c] = "files"; c++; next } \
859 /(dns|bind)/ { nsswitch[c] = "dns"; c++; next } \
860 /nis/ { nsswitch[c] = "nis"; c++; next } \
861 { printf "Warning: unrecognized line [%s]", $0 > "/dev/stderr" } \
864 for (i in nsswitch) printf "%s ", nsswitch[i]; \
866 }' < $host_conf > $nsswitch_conf