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 # Generate host.conf for compatibility
43 if [ -f "/etc/nsswitch.conf" ]; then
45 generate_host_conf /etc/nsswitch.conf /etc/host.conf
48 # Convert host.conf to nsswitch.conf if necessary
50 if [ -f "/etc/host.conf" -a ! -f "/etc/nsswitch.conf" ]; then
52 echo 'Warning: /etc/host.conf is no longer used'
53 echo ' /etc/nsswitch.conf will be created for you'
54 convert_host_conf /etc/host.conf /etc/nsswitch.conf
57 # Set the host name if it is not already set
59 if [ -z "`hostname -s`" ]; then
64 # Establish ipfilter ruleset as early as possible (best in
65 # addition to IPFILTER_DEFAULT_BLOCK in the kernel config file)
67 # check whether ipfilter and/or ipnat is enabled
69 case ${ipfilter_enable} in
74 case ${ipnat_enable} in
79 case ${ipfilter_active} in
81 # load ipfilter kernel module if needed
82 if ! sysctl net.inet.ipf.fr_pass > /dev/null 2>&1; then
84 echo 'IP-filter module loaded.'
86 echo 'Warning: IP-filter module failed to load.'
87 # avoid further errors
95 # start ipmon before loading any rules
96 case "${ipmon_enable}" in
99 ${ipmon_program:-/sbin/ipmon} ${ipmon_flags}
102 case "${ipfilter_enable}" in
104 if [ -r "${ipfilter_rules}" -o \
105 -r "${ipv6_ipfilter_rules}" ]; then
107 ${ipfilter_program:-/sbin/ipf} -Fa
108 if [ -r "${ipfilter_rules}" ]; then
109 ${ipfilter_program:-/sbin/ipf} \
110 -f "${ipfilter_rules}" \
113 if [ -r "${ipv6_ipfilter_rules}" ]; then
114 ${ipfilter_program:-/sbin/ipf} -6 \
115 -f "${ipv6_ipfilter_rules}" \
120 echo -n ' NO IPF RULES'
124 case "${ipnat_enable}" in
126 if [ -r "${ipnat_rules}" ]; then
128 eval ${ipnat_program:-/sbin/ipnat} -CF -f \
129 "${ipnat_rules}" ${ipnat_flags}
132 echo -n ' NO IPNAT RULES'
136 # restore filter/NAT state tables after loading the rules
137 case "${ipfs_enable}" in
139 if [ -r "/var/db/ipf/ipstate.ipf" ]; then
141 ${ipfs_program:-/sbin/ipfs} -R ${ipfs_flags}
142 # remove files to avoid reloading old state
143 # after an ungraceful shutdown
144 rm -f /var/db/ipf/ipstate.ipf
145 rm -f /var/db/ipf/ipnat.ipf
152 # Set the domainname if we're using NIS
154 case ${nisdomainname} in
158 domainname ${nisdomainname}
165 # Initial ATM interface configuration
167 case ${atm_enable} in
169 if [ -r /etc/rc.atm ]; then
176 # Attempt to create cloned interfaces.
177 for ifn in ${cloned_interfaces}; do
178 ifconfig ${ifn} create
181 # Special options for sppp(4) interfaces go here. These need
182 # to go _before_ the general ifconfig section, since in the case
183 # of hardwired (no link1 flag) but required authentication, you
184 # cannot pass auth parameters down to the already running interface.
186 for ifn in ${sppp_interfaces}; do
187 eval spppcontrol_args=\$spppconfig_${ifn}
188 if [ -n "${spppcontrol_args}" ]; then
189 # The auth secrets might contain spaces; in order
190 # to retain the quotation, we need to eval them
192 eval spppcontrol ${ifn} ${spppcontrol_args}
199 # Set up all the network interfaces, calling startup scripts if needed
201 case ${network_interfaces} in
203 network_interfaces="`ifconfig -l`"
206 network_interfaces="${network_interfaces} ${cloned_interfaces}"
211 for ifn in ${network_interfaces}; do
212 _up=`ifconfig ${ifn} | head -1 | grep -v LOOPBACK | grep UP,`
213 if [ "$_up" != "" ]; then
214 # Interface is already up, so ignore it.
218 if [ -r /etc/start_if.${ifn} ]; then
219 . /etc/start_if.${ifn}
223 # Do the primary ifconfig if specified
225 eval ifconfig_args=\$ifconfig_${ifn}
227 case ${ifconfig_args} in
231 # DHCP inits are done all in one go below
232 dhcp_interfaces="$dhcp_interfaces $ifn"
236 ifconfig ${ifn} ${ifconfig_args}
242 if [ ! -z "${dhcp_interfaces}" ]; then
243 ${dhcp_program:-/sbin/dhclient} ${dhcp_flags} ${dhcp_interfaces}
246 for ifn in ${network_interfaces}; do
247 # Check to see if aliases need to be added
251 eval ifconfig_args=\$ifconfig_${ifn}_alias${alias}
252 if [ -n "${ifconfig_args}" ]; then
253 ifconfig ${ifn} ${ifconfig_args} alias
255 alias=$((${alias} + 1))
261 # Do ipx address if specified
263 eval ifconfig_args=\$ifconfig_${ifn}_ipx
264 if [ -n "${ifconfig_args}" ]; then
265 ifconfig ${ifn} ${ifconfig_args}
270 for ifn in ${network_interfaces}; do
271 eval showstat=\$showstat_${ifn}
272 if [ ! -z ${showstat} ]; then
277 # ISDN subsystem startup
279 case ${isdn_enable} in
281 if [ -r /etc/rc.isdn ]; then
287 # Start user ppp if required. This must happen before natd.
289 case ${ppp_enable} in
291 # Establish ppp mode.
293 if [ "${ppp_mode}" != "ddial" -a "${ppp_mode}" != "direct" \
294 -a "${ppp_mode}" != "dedicated" \
295 -a "${ppp_mode}" != "background" ]; then
299 ppp_command="/usr/sbin/ppp -quiet -${ppp_mode}"
301 # Switch on NAT mode?
305 ppp_command="${ppp_command} -nat"
309 ppp_command="${ppp_command} ${ppp_profile}"
311 echo "Starting ppp as \"${ppp_user}\""
312 su -m ${ppp_user} -c "exec ${ppp_command}"
316 # Re-Sync ipfilter so it picks up any new network interfaces
318 case ${ipfilter_active} in
320 ${ipfilter_program:-/sbin/ipf} -y ${ipfilter_flags} >/dev/null
323 unset ipfilter_active
325 # Initialize IP filtering using ipfw
327 if /sbin/ipfw -q flush > /dev/null 2>&1; then
333 case ${firewall_enable} in
335 if [ "${firewall_in_kernel}" -eq 0 ] && kldload ipfw; then
337 echo 'Kernel firewall module loaded'
338 elif [ "${firewall_in_kernel}" -eq 0 ]; then
339 echo 'Warning: firewall kernel module failed to load'
344 # Load the filters if required
346 case ${firewall_in_kernel} in
348 if [ -z "${firewall_script}" ]; then
349 firewall_script=/etc/rc.firewall
352 case ${firewall_enable} in
354 if [ -r "${firewall_script}" ]; then
355 . "${firewall_script}"
356 echo -n 'Firewall rules loaded, starting divert daemons:'
358 # Network Address Translation daemon
360 case ${natd_enable} in
362 if [ -n "${natd_interface}" ]; then
363 if echo ${natd_interface} | \
364 grep -q -E '^[0-9]+(\.[0-9]+){0,3}$'; then
365 natd_flags="$natd_flags -a ${natd_interface}"
367 natd_flags="$natd_flags -n ${natd_interface}"
370 echo -n ' natd'; ${natd_program:-/sbin/natd} ${natd_flags}
376 elif [ "`ipfw l 65535`" = "65535 deny ip from any to any" ]; then
377 echo 'Warning: kernel has firewall functionality,' \
378 'but firewall rules are not enabled.'
379 echo ' All ip services are disabled.'
382 case ${firewall_logging} in
384 echo 'Firewall logging=YES'
385 sysctl net.inet.ip.fw.verbose=1 >/dev/null
396 # Additional ATM interface configuration
398 if [ -n "${atm_pass1_done}" ]; then
404 case ${defaultrouter} in
408 static_routes="default ${static_routes}"
409 route_default="default ${defaultrouter}"
413 # Set up any static routes. This should be done before router discovery.
415 if [ -n "${static_routes}" ]; then
416 for i in ${static_routes}; do
417 eval route_args=\$route_${i}
418 route add ${route_args}
422 echo -n 'Additional routing options:'
423 case ${tcp_extensions} in
427 echo -n ' tcp extensions=NO'
428 sysctl net.inet.tcp.rfc1323=0 >/dev/null
432 case ${icmp_bmcastecho} in
434 echo -n ' broadcast ping responses=YES'
435 sysctl net.inet.icmp.bmcastecho=1 >/dev/null
439 case ${icmp_drop_redirect} in
441 echo -n ' ignore ICMP redirect=YES'
442 sysctl net.inet.icmp.drop_redirect=1 >/dev/null
446 case ${icmp_log_redirect} in
448 echo -n ' log ICMP redirect=YES'
449 sysctl net.inet.icmp.log_redirect=1 >/dev/null
453 case ${gateway_enable} in
455 echo -n ' IP gateway=YES'
456 sysctl net.inet.ip.forwarding=1 >/dev/null
460 case ${forward_sourceroute} in
462 echo -n ' do source routing=YES'
463 sysctl net.inet.ip.sourceroute=1 >/dev/null
467 case ${accept_sourceroute} in
469 echo -n ' accept source routing=YES'
470 sysctl net.inet.ip.accept_sourceroute=1 >/dev/null
474 case ${tcp_keepalive} in
476 echo -n ' TCP keepalive=NO'
477 sysctl net.inet.tcp.always_keepalive=0 >/dev/null
481 case ${tcp_drop_synfin} in
483 echo -n ' drop SYN+FIN packets=YES'
484 sysctl net.inet.tcp.drop_synfin=1 >/dev/null
488 case ${ipxgateway_enable} in
490 echo -n ' IPX gateway=YES'
491 sysctl net.ipx.ipx.ipxforwarding=1 >/dev/null
495 case ${arpproxy_all} in
497 echo -n ' ARP proxyall=YES'
498 sysctl net.link.ether.inet.proxyall=1 >/dev/null
502 case ${ip_portrange_first} in
506 echo -n " ip_portrange_first=$ip_portrange_first"
507 sysctl net.inet.ip.portrange.first=$ip_portrange_first >/dev/null
511 case ${ip_portrange_last} in
515 echo -n " ip_portrange_last=$ip_portrange_last"
516 sysctl net.inet.ip.portrange.last=$ip_portrange_last >/dev/null
522 case ${ipsec_enable} in
524 if [ -f ${ipsec_file} ]; then
525 echo ' ipsec: enabled'
526 setkey -f ${ipsec_file}
528 echo ' ipsec: file not found'
533 echo -n 'Routing daemons:'
534 case ${router_enable} in
536 echo -n " ${router}"; ${router} ${router_flags}
540 case ${ipxrouted_enable} in
543 IPXrouted ${ipxrouted_flags} > /dev/null 2>&1
547 case ${mrouted_enable} in
549 echo -n ' mrouted'; mrouted ${mrouted_flags}
553 case ${rarpd_enable} in
555 echo -n ' rarpd'; rarpd ${rarpd_flags}
560 # Let future generations know we made it.
562 network_pass1_done=YES
566 echo -n 'Doing additional network setup:'
567 case ${named_enable} in
569 echo -n ' named'; ${named_program:-named} ${named_flags}
573 case ${ntpdate_enable} in
576 ${ntpdate_program:-ntpdate} ${ntpdate_flags} >/dev/null 2>&1
580 case ${ntpd_enable} in
582 echo -n ' ntpd'; ${ntpd_program:-ntpd} ${ntpd_flags}
586 case ${timed_enable} in
588 echo -n ' timed'; timed ${timed_flags}
592 case ${rpcbind_enable} in
594 echo -n ' rpcbind'; ${rpcbind_program:-/usr/sbin/rpcbind} \
597 # Start ypserv if we're an NIS server.
598 # Run rpc.ypxfrd and rpc.yppasswdd only on the NIS master server.
600 case ${nis_server_enable} in
602 echo -n ' ypserv'; ypserv ${nis_server_flags}
604 case ${nis_ypxfrd_enable} in
606 echo -n ' rpc.ypxfrd'
607 rpc.ypxfrd ${nis_ypxfrd_flags}
611 case ${nis_yppasswdd_enable} in
613 echo -n ' rpc.yppasswdd'
614 rpc.yppasswdd ${nis_yppasswdd_flags}
620 # Start ypbind if we're an NIS client
622 case ${nis_client_enable} in
624 echo -n ' ypbind'; ypbind ${nis_client_flags}
625 case ${nis_ypset_enable} in
627 echo -n ' ypset'; ypset ${nis_ypset_flags}
633 # Start keyserv if we are running Secure RPC
635 case ${keyserv_enable} in
637 echo -n ' keyserv'; keyserv ${keyserv_flags}
641 # Start ypupdated if we are running Secure RPC
642 # and we are NIS master
644 case ${rpc_ypupdated_enable} in
646 echo -n ' rpc.ypupdated'; rpc.ypupdated
653 if [ -n "${atm_pass2_done}" ]; then
658 network_pass2_done=YES
662 echo -n 'Starting final network daemons:'
664 case ${rpcbind_enable} in
666 case ${nfs_server_enable} in
668 # Handle absent nfs server support
669 nfsserver_in_kernel=0
670 if sysctl vfs.nfsrv >/dev/null 2>&1; then
671 nfsserver_in_kernel=1
673 kldload nfsserver && nfsserver_in_kernel=1
676 if [ -r /etc/exports -a \
677 ${nfsserver_in_kernel} -eq 1 ]; then
680 case ${weak_mountd_authentication} in
682 mountd_flags="${mountd_flags} -n"
686 mountd ${mountd_flags}
688 case ${nfs_reserved_port_only} in
690 echo -n ' NFS on reserved port only=YES'
691 sysctl vfs.nfsrv.nfs_privport=1 > /dev/null
695 echo -n ' nfsd'; nfsd ${nfs_server_flags}
697 case ${rpc_statd_enable} in
699 echo -n ' rpc.statd'; rpc.statd
703 case ${rpc_lockd_enable} in
705 echo -n ' rpc.lockd'; rpc.lockd
709 echo -n ' Warning: nfs server failed'
713 case ${mountd_enable} in
715 if [ -r /etc/exports ]; then
718 case ${weak_mountd_authentication} in
724 mountd ${mountd_flags}
731 case ${nfs_client_enable} in
733 nfsclient_in_kernel=0
734 # Handle absent nfs client support
735 if sysctl vfs.nfs >/dev/null 2>&1; then
736 nfsclient_in_kernel=1
738 kldload nfsclient && nfsclient_in_kernel=1
741 if [ ${nfsclient_in_kernel} -eq 1 ]
743 if [ -n "${nfs_access_cache}" ]; then
744 echo -n " NFS access cache time=${nfs_access_cache}"
745 sysctl vfs.nfs.access_cache_timeout=${nfs_access_cache} >/dev/null
747 if [ -n "${nfs_bufpackets}" ]; then
748 sysctl vfs.nfs.bufpackets=${nfs_bufpackets} > /dev/null
750 case ${rpc_statd_enable} in
752 echo -n ' rpc.statd'; rpc.statd
756 case ${rpc_lockd_enable} in
758 echo -n ' rpc.lockd'; rpc.lockd
762 case ${amd_enable} in
765 case ${amd_map_program} in
769 amd_flags="${amd_flags} `eval\
774 case "${amd_flags}" in
776 if [ -r /etc/amd.conf ]; then
780 echo 'Warning: amd will not load without arguments'
784 amd -p ${amd_flags} \
792 echo 'Warning: NFS client kernel module failed to load'
798 # If /var/db/mounttab exists, some nfs-server has not been
799 # successfully notified about a previous client shutdown.
800 # If there is no /var/db/mounttab, we do nothing.
801 if [ -f /var/db/mounttab ]; then
808 case ${rwhod_enable} in
810 echo -n ' rwhod'; rwhod ${rwhod_flags}
814 # Kerberos servers run ONLY on the Kerberos server machine
815 case ${kerberos4_server_enable} in
817 case ${kerberos_stash} in
826 echo -n ' kerberosIV'
827 ${kerberos4_server} ${stash} >> /var/log/kerberos.log &
829 case ${kadmind4_server_enable} in
834 ${kadmind4_server} ${stash} >/dev/null 2>&1 &
842 case ${kerberos5_server_enable} in
845 ${kerberos5_server} &
847 case ${kadmind5_server_enable} in
856 case ${pppoed_enable} in
858 if [ -n "${pppoed_provider}" ]; then
859 pppoed_flags="${pppoed_flags} -p ${pppoed_provider}"
863 /usr/libexec/pppoed ${pppoed_flags} ${pppoed_interface}
864 set +f; set -${_opts}
868 case ${sshd_enable} in
870 if [ -x /usr/bin/ssh-keygen ]; then
871 if [ ! -f /etc/ssh/ssh_host_key ]; then
872 echo ' creating ssh1 RSA host key';
873 /usr/bin/ssh-keygen -t rsa1 -N "" \
874 -f /etc/ssh/ssh_host_key
876 if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then
877 echo ' creating ssh2 RSA host key';
878 /usr/bin/ssh-keygen -t rsa -N "" \
879 -f /etc/ssh/ssh_host_rsa_key
881 if [ ! -f /etc/ssh/ssh_host_dsa_key ]; then
882 echo ' creating ssh2 DSA host key';
883 /usr/bin/ssh-keygen -t dsa -N "" \
884 -f /etc/ssh/ssh_host_dsa_key
891 network_pass3_done=YES
895 echo -n 'Additional TCP options:'
896 case ${log_in_vain} in
906 echo " invalid log_in_vain setting: ${log_in_vain}"
911 [ "${log_in_vain}" -ne 0 ] && (
912 echo -n " log_in_vain=${log_in_vain}"
913 sysctl net.inet.tcp.log_in_vain="${log_in_vain}" >/dev/null
914 sysctl net.inet.udp.log_in_vain="${log_in_vain}" >/dev/null
917 network_pass4_done=YES
920 network_gif_setup() {
921 case ${gif_interfaces} in
925 for i in ${gif_interfaces}; do
926 eval peers=\$gifconfig_$i
932 ifconfig $i create >/dev/null 2>&1
933 ifconfig $i tunnel ${peers}
942 convert_host_conf() {
944 nsswitch_conf=$1; shift;
946 /^[:blank:]*#/ { next } \
947 /(hosts|local|file)/ { nsswitch[c] = "files"; c++; next } \
948 /(dns|bind)/ { nsswitch[c] = "dns"; c++; next } \
949 /nis/ { nsswitch[c] = "nis"; c++; next } \
950 { printf "Warning: unrecognized line [%s]", $0 > "/dev/stderr" } \
953 for (i in nsswitch) printf "%s ", nsswitch[i]; \
955 }' < $host_conf > $nsswitch_conf
958 generate_host_conf() {
959 nsswitch_conf=$1; shift;
964 xlat["files"] = "hosts";
965 xlat["dns"] = "bind";
969 sub(/^[\t ]*hosts:/, "") || cont {
974 cont = sub(/\\$/, "")
978 print "# Auto-generated from nsswitch.conf, do not edit"
980 for (n = 1; n <= ns; ++n) {
985 ' <$nsswitch_conf >$host_conf