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
27 # $FreeBSD: src/etc/rc.network,v 1.74.2.43 2003/02/08 21:10:25 gshapiro Exp $
28 # $DragonFly: src/etc/Attic/rc.network,v 1.2 2003/06/17 04:24:45 dillon Exp $
29 # From: @(#)netstart 5.9 (Berkeley) 3/30/91
32 # Note that almost all of the user-configurable behavior is no longer in
33 # this file, but rather in /etc/defaults/rc.conf. Please check that file
34 # first before contemplating any changes here. If you do need to change
35 # this file for some reason, we would like to know about it.
37 # First pass startup stuff.
40 echo -n 'Doing initial network setup:'
42 # Set the host name if it is not already set
44 if [ -z "`hostname -s`" ]; then
49 # Establish ipfilter ruleset as early as possible (best in
50 # addition to IPFILTER_DEFAULT_BLOCK in the kernel config file)
52 # check whether ipfilter and/or ipnat is enabled
54 case ${ipfilter_enable} in
59 case ${ipnat_enable} in
64 case ${ipfilter_active} in
66 # load ipfilter kernel module if needed
67 if ! sysctl net.inet.ipf.fr_pass > /dev/null 2>&1; then
69 echo 'IP-filter module loaded.'
71 echo 'Warning: IP-filter module failed to load.'
72 # avoid further errors
80 # start ipmon before loading any rules
81 case "${ipmon_enable}" in
84 ${ipmon_program:-/sbin/ipmon} ${ipmon_flags}
87 case "${ipfilter_enable}" in
89 if [ -r "${ipfilter_rules}" -o \
90 -r "${ipv6_ipfilter_rules}" ]; then
92 ${ipfilter_program:-/sbin/ipf} -Fa
93 if [ -r "${ipfilter_rules}" ]; then
94 ${ipfilter_program:-/sbin/ipf} \
95 -f "${ipfilter_rules}" \
98 if [ -r "${ipv6_ipfilter_rules}" ]; then
99 ${ipfilter_program:-/sbin/ipf} -6 \
100 -f "${ipv6_ipfilter_rules}" \
105 echo -n ' NO IPF RULES'
109 case "${ipnat_enable}" in
111 if [ -r "${ipnat_rules}" ]; then
113 eval ${ipnat_program:-/sbin/ipnat} -CF -f \
114 "${ipnat_rules}" ${ipnat_flags}
117 echo -n ' NO IPNAT RULES'
121 # restore filter/NAT state tables after loading the rules
122 case "${ipfs_enable}" in
124 if [ -r "/var/db/ipf/ipstate.ipf" ]; then
126 ${ipfs_program:-/sbin/ipfs} -R ${ipfs_flags}
127 # remove files to avoid reloading old state
128 # after an ungraceful shutdown
129 rm -f /var/db/ipf/ipstate.ipf
130 rm -f /var/db/ipf/ipnat.ipf
137 # Set the domainname if we're using NIS
139 case ${nisdomainname} in
143 domainname ${nisdomainname}
150 # Initial ATM interface configuration
152 case ${atm_enable} in
154 if [ -r /etc/rc.atm ]; then
161 # Attempt to create cloned interfaces.
162 for ifn in ${cloned_interfaces}; do
163 ifconfig ${ifn} create
166 # Special options for sppp(4) interfaces go here. These need
167 # to go _before_ the general ifconfig section, since in the case
168 # of hardwired (no link1 flag) but required authentication, you
169 # cannot pass auth parameters down to the already running interface.
171 for ifn in ${sppp_interfaces}; do
172 eval spppcontrol_args=\$spppconfig_${ifn}
173 if [ -n "${spppcontrol_args}" ]; then
174 # The auth secrets might contain spaces; in order
175 # to retain the quotation, we need to eval them
177 eval spppcontrol ${ifn} ${spppcontrol_args}
184 # Set up all the network interfaces, calling startup scripts if needed
186 case ${network_interfaces} in
188 network_interfaces="`ifconfig -l`"
191 network_interfaces="${network_interfaces} ${cloned_interfaces}"
196 for ifn in ${network_interfaces}; do
197 if [ -r /etc/start_if.${ifn} ]; then
198 . /etc/start_if.${ifn}
202 # Do the primary ifconfig if specified
204 eval ifconfig_args=\$ifconfig_${ifn}
206 case ${ifconfig_args} in
210 # DHCP inits are done all in one go below
211 dhcp_interfaces="$dhcp_interfaces $ifn"
215 ifconfig ${ifn} ${ifconfig_args}
221 if [ ! -z "${dhcp_interfaces}" ]; then
222 ${dhcp_program:-/sbin/dhclient} ${dhcp_flags} ${dhcp_interfaces}
225 for ifn in ${network_interfaces}; do
226 # Check to see if aliases need to be added
230 eval ifconfig_args=\$ifconfig_${ifn}_alias${alias}
231 if [ -n "${ifconfig_args}" ]; then
232 ifconfig ${ifn} ${ifconfig_args} alias
234 alias=$((${alias} + 1))
240 # Do ipx address if specified
242 eval ifconfig_args=\$ifconfig_${ifn}_ipx
243 if [ -n "${ifconfig_args}" ]; then
244 ifconfig ${ifn} ${ifconfig_args}
249 for ifn in ${network_interfaces}; do
250 eval showstat=\$showstat_${ifn}
251 if [ ! -z ${showstat} ]; then
256 # ISDN subsystem startup
258 case ${isdn_enable} in
260 if [ -r /etc/rc.isdn ]; then
266 # Start user ppp if required. This must happen before natd.
268 case ${ppp_enable} in
270 # Establish ppp mode.
272 if [ "${ppp_mode}" != "ddial" -a "${ppp_mode}" != "direct" \
273 -a "${ppp_mode}" != "dedicated" \
274 -a "${ppp_mode}" != "background" ]; then
278 ppp_command="/usr/sbin/ppp -quiet -${ppp_mode}"
280 # Switch on NAT mode?
284 ppp_command="${ppp_command} -nat"
288 ppp_command="${ppp_command} ${ppp_profile}"
290 echo "Starting ppp as \"${ppp_user}\""
291 su -m ${ppp_user} -c "exec ${ppp_command}"
295 # Re-Sync ipfilter so it picks up any new network interfaces
297 case ${ipfilter_active} in
299 ${ipfilter_program:-/sbin/ipf} -y ${ipfilter_flags} >/dev/null
302 unset ipfilter_active
304 # Initialize IP filtering using ipfw
306 if /sbin/ipfw -q flush > /dev/null 2>&1; then
312 case ${firewall_enable} in
314 if [ "${firewall_in_kernel}" -eq 0 ] && kldload ipfw; then
316 echo 'Kernel firewall module loaded'
317 elif [ "${firewall_in_kernel}" -eq 0 ]; then
318 echo 'Warning: firewall kernel module failed to load'
323 # Load the filters if required
325 case ${firewall_in_kernel} in
327 if [ -z "${firewall_script}" ]; then
328 firewall_script=/etc/rc.firewall
331 case ${firewall_enable} in
333 if [ -r "${firewall_script}" ]; then
334 . "${firewall_script}"
335 echo -n 'Firewall rules loaded, starting divert daemons:'
337 # Network Address Translation daemon
339 case ${natd_enable} in
341 if [ -n "${natd_interface}" ]; then
342 if echo ${natd_interface} | \
343 grep -q -E '^[0-9]+(\.[0-9]+){0,3}$'; then
344 natd_flags="$natd_flags -a ${natd_interface}"
346 natd_flags="$natd_flags -n ${natd_interface}"
349 echo -n ' natd'; ${natd_program:-/sbin/natd} ${natd_flags}
355 elif [ "`ipfw l 65535`" = "65535 deny ip from any to any" ]; then
356 echo 'Warning: kernel has firewall functionality,' \
357 'but firewall rules are not enabled.'
358 echo ' All ip services are disabled.'
361 case ${firewall_logging} in
363 echo 'Firewall logging=YES'
364 sysctl net.inet.ip.fw.verbose=1 >/dev/null
375 # Additional ATM interface configuration
377 if [ -n "${atm_pass1_done}" ]; then
383 case ${defaultrouter} in
387 static_routes="default ${static_routes}"
388 route_default="default ${defaultrouter}"
392 # Set up any static routes. This should be done before router discovery.
394 if [ -n "${static_routes}" ]; then
395 for i in ${static_routes}; do
396 eval route_args=\$route_${i}
397 route add ${route_args}
401 echo -n 'Additional routing options:'
402 case ${tcp_extensions} in
406 echo -n ' tcp extensions=NO'
407 sysctl net.inet.tcp.rfc1323=0 >/dev/null
411 case ${icmp_bmcastecho} in
413 echo -n ' broadcast ping responses=YES'
414 sysctl net.inet.icmp.bmcastecho=1 >/dev/null
418 case ${icmp_drop_redirect} in
420 echo -n ' ignore ICMP redirect=YES'
421 sysctl net.inet.icmp.drop_redirect=1 >/dev/null
425 case ${icmp_log_redirect} in
427 echo -n ' log ICMP redirect=YES'
428 sysctl net.inet.icmp.log_redirect=1 >/dev/null
432 case ${gateway_enable} in
434 echo -n ' IP gateway=YES'
435 sysctl net.inet.ip.forwarding=1 >/dev/null
439 case ${forward_sourceroute} in
441 echo -n ' do source routing=YES'
442 sysctl net.inet.ip.sourceroute=1 >/dev/null
446 case ${accept_sourceroute} in
448 echo -n ' accept source routing=YES'
449 sysctl net.inet.ip.accept_sourceroute=1 >/dev/null
453 case ${tcp_keepalive} in
455 echo -n ' TCP keepalive=YES'
456 sysctl net.inet.tcp.always_keepalive=1 >/dev/null
460 case ${tcp_drop_synfin} in
462 echo -n ' drop SYN+FIN packets=YES'
463 sysctl net.inet.tcp.drop_synfin=1 >/dev/null
467 case ${ipxgateway_enable} in
469 echo -n ' IPX gateway=YES'
470 sysctl net.ipx.ipx.ipxforwarding=1 >/dev/null
474 case ${arpproxy_all} in
476 echo -n ' ARP proxyall=YES'
477 sysctl net.link.ether.inet.proxyall=1 >/dev/null
481 case ${ip_portrange_first} in
485 echo -n " ip_portrange_first=$ip_portrange_first"
486 sysctl net.inet.ip.portrange.first=$ip_portrange_first >/dev/null
490 case ${ip_portrange_last} in
494 echo -n " ip_portrange_last=$ip_portrange_last"
495 sysctl net.inet.ip.portrange.last=$ip_portrange_last >/dev/null
501 case ${ipsec_enable} in
503 if [ -f ${ipsec_file} ]; then
504 echo ' ipsec: enabled'
505 setkey -f ${ipsec_file}
507 echo ' ipsec: file not found'
512 echo -n 'Routing daemons:'
513 case ${router_enable} in
515 echo -n " ${router}"; ${router} ${router_flags}
519 case ${ipxrouted_enable} in
522 IPXrouted ${ipxrouted_flags} > /dev/null 2>&1
526 case ${mrouted_enable} in
528 echo -n ' mrouted'; mrouted ${mrouted_flags}
532 case ${rarpd_enable} in
534 echo -n ' rarpd'; rarpd ${rarpd_flags}
539 # Let future generations know we made it.
541 network_pass1_done=YES
545 echo -n 'Doing additional network setup:'
546 case ${named_enable} in
548 echo -n ' named'; ${named_program:-named} ${named_flags}
552 case ${ntpdate_enable} in
555 ${ntpdate_program:-ntpdate} ${ntpdate_flags} >/dev/null 2>&1
559 case ${xntpd_enable} in
561 echo -n ' ntpd'; ${xntpd_program:-ntpd} ${xntpd_flags}
565 case ${timed_enable} in
567 echo -n ' timed'; timed ${timed_flags}
571 case ${portmap_enable} in
573 echo -n ' portmap'; ${portmap_program:-/usr/sbin/portmap} ${portmap_flags}
577 # Start ypserv if we're an NIS server.
578 # Run rpc.ypxfrd and rpc.yppasswdd only on the NIS master server.
580 case ${nis_server_enable} in
582 echo -n ' ypserv'; ypserv ${nis_server_flags}
584 case ${nis_ypxfrd_enable} in
586 echo -n ' rpc.ypxfrd'
587 rpc.ypxfrd ${nis_ypxfrd_flags}
591 case ${nis_yppasswdd_enable} in
593 echo -n ' rpc.yppasswdd'
594 rpc.yppasswdd ${nis_yppasswdd_flags}
600 # Start ypbind if we're an NIS client
602 case ${nis_client_enable} in
604 echo -n ' ypbind'; ypbind ${nis_client_flags}
605 case ${nis_ypset_enable} in
607 echo -n ' ypset'; ypset ${nis_ypset_flags}
613 # Start keyserv if we are running Secure RPC
615 case ${keyserv_enable} in
617 echo -n ' keyserv'; keyserv ${keyserv_flags}
621 # Start ypupdated if we are running Secure RPC and we are NIS master
623 case ${rpc_ypupdated_enable} in
625 echo -n ' rpc.ypupdated'; rpc.ypupdated
630 if [ -n "${atm_pass2_done}" ]; then
635 network_pass2_done=YES
639 echo -n 'Starting final network daemons:'
641 case ${nfs_server_enable} in
643 if [ -r /etc/exports ]; then
646 case ${weak_mountd_authentication} in
648 mountd_flags="${mountd_flags} -n"
652 mountd ${mountd_flags}
654 case ${nfs_reserved_port_only} in
656 echo -n ' NFS on reserved port only=YES'
657 sysctl vfs.nfs.nfs_privport=1 >/dev/null
661 echo -n ' nfsd'; nfsd ${nfs_server_flags}
663 case ${rpc_lockd_enable} in
665 echo -n ' rpc.lockd'; rpc.lockd
669 case ${rpc_statd_enable} in
671 echo -n ' rpc.statd'; rpc.statd
677 case ${single_mountd_enable} in
679 if [ -r /etc/exports ]; then
682 case ${weak_mountd_authentication} in
688 mountd ${mountd_flags}
695 case ${nfs_client_enable} in
698 # Handle absent nfs client support
699 if sysctl vfs.nfs >/dev/null 2>&1; then
702 kldload nfs && nfs_in_kernel=1
704 if [ ${nfs_in_kernel} -eq 1 ]
706 echo -n ' nfsiod'; nfsiod ${nfs_client_flags}
707 if [ -n "${nfs_access_cache}" ]; then
708 echo -n " NFS access cache time=${nfs_access_cache}"
709 sysctl vfs.nfs.access_cache_timeout=${nfs_access_cache} >/dev/null
712 if [ -n "${nfs_bufpackets}" ]; then
713 sysctl vfs.nfs.bufpackets=${nfs_bufpackets} \
717 case ${amd_enable} in
720 case ${amd_map_program} in
724 amd_flags="${amd_flags} `eval \
729 case "${amd_flags}" in
731 if [ -r /etc/amd.conf ]; then
735 echo 'Warning: amd will not load without arguments'
739 amd -p ${amd_flags} >/var/run/amd.pid \
749 # If /var/db/mounttab exists, some nfs-server has not been
750 # sucessfully notified about a previous client shutdown.
751 # If there is no /var/db/mounttab, we do nothing.
752 if [ -f /var/db/mounttab ]; then
756 case ${rwhod_enable} in
758 echo -n ' rwhod'; rwhod ${rwhod_flags}
762 # Kerberos servers run ONLY on the Kerberos server machine
763 case ${kerberos_server_enable} in
765 case ${kerberos_stash} in
774 echo -n ' kerberosIV'
775 kerberos ${stash_flag} >> /var/log/kerberos.log &
777 case ${kadmind_server_enable} in
782 kadmind ${stash_flag} >/dev/null 2>&1 &
790 case ${kerberos5_server_enable} in
793 ${kerberos5_server} &
795 case ${kadmind5_server_enable} in
804 case ${pppoed_enable} in
806 if [ -n "${pppoed_provider}" ]; then
807 pppoed_flags="${pppoed_flags} -p ${pppoed_provider}"
811 /usr/libexec/pppoed ${pppoed_flags} ${pppoed_interface}
812 set +f; set -${_opts}
816 case ${sshd_enable} in
818 if [ -x /usr/bin/ssh-keygen ]; then
819 if [ ! -f /etc/ssh/ssh_host_key ]; then
820 echo ' creating ssh1 RSA host key';
821 /usr/bin/ssh-keygen -t rsa1 -N "" \
822 -f /etc/ssh/ssh_host_key
824 if [ ! -f /etc/ssh/ssh_host_rsa_key ]; then
825 echo ' creating ssh2 RSA host key';
826 /usr/bin/ssh-keygen -t rsa -N "" \
827 -f /etc/ssh/ssh_host_rsa_key
829 if [ ! -f /etc/ssh/ssh_host_dsa_key ]; then
830 echo ' creating ssh2 DSA host key';
831 /usr/bin/ssh-keygen -t dsa -N "" \
832 -f /etc/ssh/ssh_host_dsa_key
839 network_pass3_done=YES
843 echo -n 'Additional TCP options:'
844 case ${log_in_vain} in
854 echo " invalid log_in_vain setting: ${log_in_vain}"
859 if [ "${log_in_vain}" -ne 0 ]; then
860 echo -n " log_in_vain=${log_in_vain}"
861 sysctl net.inet.tcp.log_in_vain="${log_in_vain}" >/dev/null
862 sysctl net.inet.udp.log_in_vain="${log_in_vain}" >/dev/null
866 network_pass4_done=YES
869 network_gif_setup() {
870 case ${gif_interfaces} in
874 for i in ${gif_interfaces}; do
875 eval peers=\$gifconfig_$i
881 ifconfig $i create >/dev/null 2>&1
882 ifconfig $i tunnel ${peers}