3
0

simple.script 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/sh
  2. # udhcpc script edited by Tim Riker <Tim@Rikers.org>
  3. RESOLV_CONF="/etc/resolv.conf"
  4. [ -n "$1" ] || { echo "Error: should be called from udhcpc"; exit 1; }
  5. NETMASK=""
  6. [ -n "$subnet" ] && NETMASK="netmask $subnet"
  7. BROADCAST="broadcast +"
  8. [ -n "$broadcast" ] && BROADCAST="broadcast $broadcast"
  9. case "$1" in
  10. deconfig)
  11. echo "Setting IP address 0.0.0.0 on $interface"
  12. ifconfig $interface 0.0.0.0
  13. ;;
  14. renew|bound)
  15. echo "Setting IP address $ip on $interface"
  16. ifconfig $interface $ip $NETMASK $BROADCAST
  17. if [ -n "$router" ] ; then
  18. echo "Deleting routers"
  19. while route del default gw 0.0.0.0 dev $interface ; do
  20. :
  21. done
  22. metric=0
  23. for i in $router ; do
  24. echo "Adding router $i"
  25. if [ "$subnet" = "255.255.255.255" ]; then
  26. # special case for /32 subnets:
  27. # /32 instructs kernel to always use routing for all outgoing packets
  28. # (they can never be sent to local subnet - there is no local subnet for /32).
  29. # Used in datacenters, avoids the need for private ip-addresses between two hops.
  30. ip route add $i dev $interface
  31. fi
  32. route add default gw $i dev $interface metric $((metric++))
  33. done
  34. fi
  35. echo "Recreating $RESOLV_CONF"
  36. # If the file is a symlink somewhere (like /etc/resolv.conf
  37. # pointing to /run/resolv.conf), make sure things work.
  38. realconf=$(readlink -f "$RESOLV_CONF" 2>/dev/null || echo "$RESOLV_CONF")
  39. tmpfile="$realconf-$$"
  40. > "$tmpfile"
  41. [ -n "$domain" ] && echo "search $domain" >> "$tmpfile"
  42. for i in $dns ; do
  43. echo " Adding DNS server $i"
  44. echo "nameserver $i" >> "$tmpfile"
  45. done
  46. mv "$tmpfile" "$realconf"
  47. ;;
  48. esac
  49. exit 0