# get an ip using the following priority: # 1st, use kernel cmd line ip= (kexec or fonz reloaded) # 2nd, use defaults stored in flash # 3d, try to read vendor sib.conf # 4th, try to use a dhcp server # 5th, find and use a non-used ip address from 192.168.1.254 to 230 range if grep -q "ip=" /proc/cmdline; then logger -s "IP from kernel cmdline, kernel brings eth0 up" cip="kip" eval $(cat /proc/cmdline) ns=$(echo $ip | awk -F: '{ print $3 }') if test -n "$ns"; then echo "nameserver $ns" >> /etc/resolv.conf fi hn="$(echo $ip | awk -F: '{ print $5 }')" if test -n "$hn"; then domain=$(echo $hn | cut -d"." -f2) hostname $(echo $hn | cut -d"." -f1) fi ifconfig eth0 up elif test $no_defaults = "0"; then logger -s "IP from flash-defaults" cip="def" ifup eth0 else res=$(loadsave_settings -rs) if test $? = 0; then logger -s "IP from sib.conf" cip="sib" eval $res ifconfig eth0 up $ip netmask $mask route add default gw $gw echo "nameserver $ns1" >> /etc/resolv.conf if test -n "$ns2"; then echo "nameserver $ns2" >> /etc/resolv.conf fi hostname $host else ifconfig eth0 up sleep 3 udhcpc -Sfqns /dev/null if test $? = 0; then logger -s "IP from dhcp server" cip="dhcp" else logger -s "Fixed IP" ifconfig eth0 0.0.0.0 sleep 3 for i in $(seq 254 -1 230); do res=$(arping -Dw 2 192.168.1.$i) st = $? logger -s "$res" if test $? = 0; then break; fi done logger -s "using 192.168.1.$i" ifconfig eth0 192.168.1.$i cip="fip" fi fi # setup minimum network services (httpd is mandatory) case $cip in "kip" | "fip" | "sib") # set hostname/hostip hostip=$(ifconfig eth0 | awk '/inet addr/ { print substr($2, 6) }') netmask=$(ifconfig eth0 | awk '/inet addr/ { print substr($4, 6) }') eval $(ipcalc -n $hostip $netmask) # evaluate NETWORK gateway=$(route -n | awk '$1 == "0.0.0.0" { print $2 }') broadcast=$(ifconfig eth0 | awk '/inet addr/ { print substr($3, 7) }') mtu=$(ifconfig eth0 | awk '/MTU/{print substr($5,5)}') if test "$(hostname)" = "(none)"; then hostname -F /etc/hostname fi if test -z "$domain"; then domain=$(awk '/(domain|search)/{print $2}' /etc/resolv.conf) if test -z "$domain"; then domain="localnet"; fi fi echo "$hostip $(hostname).$domain $(hostname)" >> /etc/hosts # set httpd hosts allow/deny sed -i "s|^A:.*#!# Allow local net.*$|A:$NETWORK/$netmask #!# Allow local net|" /etc/httpd.conf # set smb.conf hosts allow and workgroup sed -i "s|hosts allow = \([^ ]*\) \([^ ]*\)\(.*$\)|hosts allow = 127. $NETWORK/${subnet}\3|" /etc/sam #sed -i "s/workgroup =.*$/workgroup = $domain/" /etc/samba/smb.conf cat<<-EOF > /etc/network/interfaces auto lo iface lo inet loopback auto eth0 iface eth0 inet static address $hostip netmask $netmask broadcast $broadcast gateway $gateway mtu $mtu EOF ;; "dhcp") cat<<-EOF > /etc/network/interfaces auto lo iface lo inet loopback auto eth0 iface eth0 inet dhcp client udhcpc EOF ifup eth0 ;; "def") hostname -F /etc/hostname ;; esac