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 "${ipnat_enable}" in
90 if [ -r "${ipnat_rules}" ]; then
92 eval ${ipnat_program:-/sbin/ipnat -CF -f} \
93 "${ipnat_rules}" ${ipnat_flags}
95 echo -n ' NO IPNAT RULES'
101 echo -n ' NO IPF RULES'
106 # Set the domainname if we're using NIS
108 case ${nisdomainname} in
112 domainname ${nisdomainname}
119 # Initial ATM interface configuration
121 case ${atm_enable} in
123 if [ -r /etc/rc.atm ]; then
130 # Special options for sppp(4) interfaces go here. These need
131 # to go _before_ the general ifconfig section, since in the case
132 # of hardwired (no link1 flag) but required authentication, you
133 # cannot pass auth parameters down to the already running interface.
135 for ifn in ${sppp_interfaces}; do
136 eval spppcontrol_args=\$spppconfig_${ifn}
137 if [ -n "${spppcontrol_args}" ]; then
138 # The auth secrets might contain spaces; in order
139 # to retain the quotation, we need to eval them
141 eval spppcontrol ${ifn} ${spppcontrol_args}
148 # Set up all the network interfaces, calling startup scripts if needed
150 case ${network_interfaces} in
152 network_interfaces="`ifconfig -l`"
157 for ifn in ${network_interfaces}; do
158 if [ -r /etc/start_if.${ifn} ]; then
159 . /etc/start_if.${ifn}
163 # Do the primary ifconfig if specified
165 eval ifconfig_args=\$ifconfig_${ifn}
167 case ${ifconfig_args} in
171 # DHCP inits are done all in one go below
172 dhcp_interfaces="$dhcp_interfaces $ifn"
176 ifconfig ${ifn} ${ifconfig_args}
182 if [ ! -z "${dhcp_interfaces}" ]; then
183 ${dhcp_program:-/sbin/dhclient} ${dhcp_flags} ${dhcp_interfaces}
186 for ifn in ${network_interfaces}; do
187 # Check to see if aliases need to be added
191 eval ifconfig_args=\$ifconfig_${ifn}_alias${alias}
192 if [ -n "${ifconfig_args}" ]; then
193 ifconfig ${ifn} ${ifconfig_args} alias
195 alias=`expr ${alias} + 1`
201 # Do ipx address if specified
203 eval ifconfig_args=\$ifconfig_${ifn}_ipx
204 if [ -n "${ifconfig_args}" ]; then
205 ifconfig ${ifn} ${ifconfig_args}
210 for ifn in ${network_interfaces}; do
211 eval showstat=\$showstat_${ifn}
212 if [ ! -z ${showstat} ]; then
217 # ISDN subsystem startup
219 case ${isdn_enable} in
221 if [ -r /etc/rc.isdn ]; then
227 # Start user ppp if required. This must happen before natd.
229 case ${ppp_enable} in
231 # Establish ppp mode.
233 if [ "${ppp_mode}" != "ddial" -a "${ppp_mode}" != "direct" \
234 -a "${ppp_mode}" != "dedicated" \
235 -a "${ppp_mode}" != "background" ]; then
239 ppp_command="/usr/sbin/ppp -quiet -${ppp_mode}"
241 # Switch on NAT mode?
245 ppp_command="${ppp_command} -nat"
249 ppp_command="${ppp_command} ${ppp_profile}"
251 echo "Starting ppp as \"${ppp_user}\""
252 su -m ${ppp_user} -c "exec ${ppp_command}"
256 # Initialize IP filtering using ipfw
258 if /sbin/ipfw -q flush > /dev/null 2>&1; then
264 case ${firewall_enable} in
266 if [ "${firewall_in_kernel}" -eq 0 ] && kldload ipfw; then
268 echo 'Kernel firewall module loaded'
269 elif [ "${firewall_in_kernel}" -eq 0 ]; then
270 echo 'Warning: firewall kernel module failed to load'
275 # Load the filters if required
277 case ${firewall_in_kernel} in
279 if [ -z "${firewall_script}" ]; then
280 firewall_script=/etc/rc.firewall
283 case ${firewall_enable} in
285 if [ -r "${firewall_script}" ]; then
286 . "${firewall_script}"
287 echo -n 'Firewall rules loaded, starting divert daemons:'
289 # Network Address Translation daemon
291 case ${natd_enable} in
293 if [ -n "${natd_interface}" ]; then
294 if echo ${natd_interface} | \
295 grep -q -E '^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$'; then
296 natd_ifarg="-a ${natd_interface}"
298 natd_ifarg="-n ${natd_interface}"
301 echo -n ' natd'; ${natd_program:-/sbin/natd} ${natd_flags} ${natd_ifarg}
308 elif [ "`ipfw l 65535`" = "65535 deny ip from any to any" ]; then
309 echo 'Warning: kernel has firewall functionality,' \
310 'but firewall rules are not enabled.'
311 echo ' All ip services are disabled.'
314 case ${firewall_logging} in
316 echo 'Firewall logging=YES'
317 sysctl -w net.inet.ip.fw.verbose=1 >/dev/null
328 # Additional ATM interface configuration
330 if [ -n "${atm_pass1_done}" ]; then
336 case ${defaultrouter} in
340 static_routes="default ${static_routes}"
341 route_default="default ${defaultrouter}"
345 # Set up any static routes. This should be done before router discovery.
347 if [ -n "${static_routes}" ]; then
348 for i in ${static_routes}; do
349 eval route_args=\$route_${i}
350 route add ${route_args}
354 echo -n 'Additional routing options:'
355 case ${tcp_extensions} in
359 echo -n ' tcp extensions=NO'
360 sysctl -w net.inet.tcp.rfc1323=0 >/dev/null
364 case ${icmp_bmcastecho} in
366 echo -n ' broadcast ping responses=YES'
367 sysctl -w net.inet.icmp.bmcastecho=1 >/dev/null
371 case ${icmp_drop_redirect} in
373 echo -n ' ignore ICMP redirect=YES'
374 sysctl -w net.inet.icmp.drop_redirect=1 >/dev/null
378 case ${icmp_log_redirect} in
380 echo -n ' log ICMP redirect=YES'
381 sysctl -w net.inet.icmp.log_redirect=1 >/dev/null
385 case ${gateway_enable} in
387 echo -n ' IP gateway=YES'
388 sysctl -w net.inet.ip.forwarding=1 >/dev/null
392 case ${forward_sourceroute} in
394 echo -n ' do source routing=YES'
395 sysctl -w net.inet.ip.sourceroute=1 >/dev/null
399 case ${accept_sourceroute} in
401 echo -n ' accept source routing=YES'
402 sysctl -w net.inet.ip.accept_sourceroute=1 >/dev/null
406 case ${tcp_keepalive} in
408 echo -n ' TCP keepalive=YES'
409 sysctl -w net.inet.tcp.always_keepalive=1 >/dev/null
413 case ${tcp_drop_synfin} in
415 echo -n ' drop SYN+FIN packets=YES'
416 sysctl -w net.inet.tcp.drop_synfin=1 >/dev/null
420 case ${ipxgateway_enable} in
422 echo -n ' IPX gateway=YES'
423 sysctl -w net.ipx.ipx.ipxforwarding=1 >/dev/null
427 case ${arpproxy_all} in
429 echo -n ' ARP proxyall=YES'
430 sysctl -w net.link.ether.inet.proxyall=1 >/dev/null
434 case ${ip_portrange_first} in
438 echo -n " ip_portrange_first=$ip_portrange_first"
439 sysctl -w net.inet.ip.portrange.first=$ip_portrange_first >/dev/null
443 case ${ip_portrange_last} in
447 echo -n " ip_portrange_last=$ip_portrange_last"
448 sysctl -w net.inet.ip.portrange.last=$ip_portrange_last >/dev/null
454 case ${ipsec_enable} in
456 if [ -f ${ipsec_file} ]; then
457 echo ' ipsec: enabled'
458 setkey -f ${ipsec_file}
460 echo ' ipsec: file not found'
465 echo -n 'Routing daemons:'
466 case ${router_enable} in
468 echo -n " ${router}"; ${router} ${router_flags}
472 case ${ipxrouted_enable} in
475 IPXrouted ${ipxrouted_flags} > /dev/null 2>&1
479 case ${mrouted_enable} in
481 echo -n ' mrouted'; mrouted ${mrouted_flags}
485 case ${rarpd_enable} in
487 echo -n ' rarpd'; rarpd ${rarpd_flags}
492 # Let future generations know we made it.
494 network_pass1_done=YES
498 echo -n 'Doing additional network setup:'
499 case ${named_enable} in
501 echo -n ' named'; ${named_program:-named} ${named_flags}
505 case ${ntpdate_enable} in
508 ${ntpdate_program:-ntpdate} ${ntpdate_flags} >/dev/null 2>&1
512 case ${xntpd_enable} in
514 echo -n ' ntpd'; ${xntpd_program:-ntpd} ${xntpd_flags}
518 case ${timed_enable} in
520 echo -n ' timed'; timed ${timed_flags}
524 case ${portmap_enable} in
526 echo -n ' rpcbind'; ${portmap_program:-/usr/sbin/rpcbind} \
529 # Start ypserv if we're an NIS server.
530 # Run rpc.ypxfrd and rpc.yppasswdd only on the NIS master server.
532 case ${nis_server_enable} in
534 echo -n ' ypserv'; ypserv ${nis_server_flags}
536 case ${nis_ypxfrd_enable} in
538 echo -n ' rpc.ypxfrd'
539 rpc.ypxfrd ${nis_ypxfrd_flags}
543 case ${nis_yppasswdd_enable} in
545 echo -n ' rpc.yppasswdd'
546 rpc.yppasswdd ${nis_yppasswdd_flags}
552 # Start ypbind if we're an NIS client
554 case ${nis_client_enable} in
556 echo -n ' ypbind'; ypbind ${nis_client_flags}
557 case ${nis_ypset_enable} in
559 echo -n ' ypset'; ypset ${nis_ypset_flags}
565 # Start keyserv if we are running Secure RPC
567 case ${keyserv_enable} in
569 echo -n ' keyserv'; keyserv ${keyserv_flags}
573 # Start ypupdated if we are running Secure RPC
574 # and we are NIS master
576 case ${rpc_ypupdated_enable} in
578 echo -n ' rpc.ypupdated'; rpc.ypupdated
585 if [ -n "${atm_pass2_done}" ]; then
590 network_pass2_done=YES
594 echo -n 'Starting final network daemons:'
596 case ${portmap_enable} in
598 case ${nfs_server_enable} in
600 if [ -r /etc/exports ]; then
603 case ${weak_mountd_authentication} in
605 mountd_flags="${mountd_flags} -n"
609 mountd ${mountd_flags}
611 case ${nfs_reserved_port_only} in
613 echo -n ' NFS on reserved port only=YES'
614 sysctl -w vfs.nfs.nfs_privport=1 > /dev/null
618 echo -n ' nfsd'; nfsd ${nfs_server_flags}
620 if [ -n "${nfs_bufpackets}" ]; then
621 sysctl -w vfs.nfs.bufpackets=${nfs_bufpackets} > /dev/null
624 case ${rpc_lockd_enable} in
626 echo -n ' rpc.lockd'; rpc.lockd
630 case ${rpc_statd_enable} in
632 echo -n ' rpc.statd'; rpc.statd
638 case ${single_mountd_enable} in
640 if [ -r /etc/exports ]; then
643 case ${weak_mountd_authentication} in
649 mountd ${mountd_flags}
656 case ${nfs_client_enable} in
658 echo -n ' nfsiod'; nfsiod ${nfs_client_flags}
659 if [ -n "${nfs_access_cache}" ]; then
660 echo -n " NFS access cache time=${nfs_access_cache}"
661 sysctl -w vfs.nfs.access_cache_timeout=${nfs_access_cache} >/dev/null
666 # If /var/db/mounttab exists, some nfs-server has not been
667 # sucessfully notified about a previous client shutdown.
668 # If there is no /var/db/mounttab, we do nothing.
669 if [ -f /var/db/mounttab ]; then
673 case ${amd_enable} in
676 case ${amd_map_program} in
680 amd_flags="${amd_flags} `eval\
685 if [ -n "${amd_flags}" ]; then
687 > /var/run/amd.pid 2> /dev/null
696 case ${rwhod_enable} in
698 echo -n ' rwhod'; rwhod ${rwhod_flags}
702 # Kerberos servers run ONLY on the Kerberos server machine
703 case ${kerberos4_server_enable} in
705 case ${kerberos_stash} in
714 echo -n ' kerberosIV'
715 ${kerberos4_server} ${stash} >> /var/log/kerberos.log &
717 case ${kadmind4_server_enable} in
722 ${kadmind4_server} ${stash} >/dev/null 2>&1 &
730 case ${kerberos5_server_enable} in
733 ${kerberos5_server} &
735 case ${kadmind5_server_enable} in
744 case ${pppoed_enable} in
746 if [ -n "${pppoed_provider}" ]; then
747 pppoed_flags="${pppoed_flags} -p ${pppoed_provider}"
750 /usr/libexec/pppoed ${pppoed_flags} ${pppoed_interface}
754 case ${sshd_enable} in
756 if [ ! -f /etc/ssh/ssh_host_key ]; then
757 echo ' creating ssh RSA host key';
758 /usr/bin/ssh-keygen -N "" -f /etc/ssh/ssh_host_key
760 if [ ! -f /etc/ssh/ssh_host_dsa_key ]; then
761 echo ' creating ssh DSA host key';
762 /usr/bin/ssh-keygen -d -N "" -f /etc/ssh/ssh_host_dsa_key
768 network_pass3_done=YES
772 echo -n 'Additional TCP options:'
773 case ${log_in_vain} in
777 echo -n ' log_in_vain=YES'
778 sysctl -w net.inet.tcp.log_in_vain=1 >/dev/null
779 sysctl -w net.inet.udp.log_in_vain=1 >/dev/null
784 network_pass4_done=YES
787 network_gif_setup() {
788 case ${gif_interfaces} in
792 for i in ${gif_interfaces}; do
793 eval peers=\$gifconfig_$i
799 ifconfig $i create tunnel ${peers}
807 convert_host_conf() {
809 nsswitch_conf=$1; shift;
811 /^[:blank:]*#/ { next } \
812 /(hosts|local|file)/ { nsswitch[c] = "files"; c++; next } \
813 /(dns|bind)/ { nsswitch[c] = "dns"; c++; next } \
814 /nis/ { nsswitch[c] = "nis"; c++; next } \
815 { printf "Warning: unrecognized line [%s]", $0 > "/dev/stderr" } \
818 for (i in nsswitch) printf "%s ", nsswitch[i]; \
820 }' < $host_conf > $nsswitch_conf