ipv4-static 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/bin/sh
  2. ########################################################################
  3. # Begin /lib/boot/ipv4-static
  4. #
  5. # Description : IPV4 Static Boot Script
  6. #
  7. # Authors : Nathan Coulson - nathan@linuxfromscratch.org
  8. # Kevin P. Fleming - kpfleming@linuxfromscratch.org
  9. # Update : Bruce Dubbs - bdubbs@linuxfromscratch.org
  10. #
  11. # Version : LFS 7.0
  12. #
  13. ########################################################################
  14. . /lib/boot/functions
  15. . ${IFCONFIG}
  16. if [ -z "${IP}" ]; then
  17. boot_mesg "IP variable missing from ${IFCONFIG}, cannot continue." ${FAILURE}
  18. echo_failure
  19. exit 1
  20. fi
  21. if [ -z "${PREFIX}" -a -z "${PEER}" ]; then
  22. boot_mesg -n "PREFIX variable missing from ${IFCONFIG}," ${WARNING}
  23. boot_mesg " assuming 24."
  24. echo_warning
  25. PREFIX=24
  26. args="${args} ${IP}/${PREFIX}"
  27. elif [ -n "${PREFIX}" -a -n "${PEER}" ]; then
  28. boot_mesg "PREFIX and PEER both specified in ${IFCONFIG}, cannot continue." ${FAILURE}
  29. echo_failure
  30. exit 1
  31. elif [ -n "${PREFIX}" ]; then
  32. args="${args} ${IP}/${PREFIX}"
  33. elif [ -n "${PEER}" ]; then
  34. args="${args} ${IP} peer ${PEER}"
  35. fi
  36. if [ -n "${BROADCAST}" ]; then
  37. args="${args} broadcast ${BROADCAST}"
  38. fi
  39. case "${2}" in
  40. up)
  41. boot_mesg "Adding IPv4 address ${IP} to the ${1} interface..."
  42. ip addr add ${args} dev ${1}
  43. evaluate_retval
  44. if [ -n "${GATEWAY}" ]; then
  45. if ip route | grep -q default; then
  46. boot_mesg "Gateway already setup; skipping." ${WARNING}
  47. echo_warning
  48. else
  49. boot_mesg "Setting up default gateway..."
  50. ip route add default via ${GATEWAY} dev ${1}
  51. evaluate_retval
  52. fi
  53. fi
  54. ;;
  55. down)
  56. if [ -n "${GATEWAY}" ]; then
  57. boot_mesg "Removing default gateway..."
  58. ip route del default
  59. evaluate_retval
  60. fi
  61. boot_mesg "Removing IPv4 address ${IP} from the ${1} interface..."
  62. ip addr del ${args} dev ${1}
  63. evaluate_retval
  64. ;;
  65. *)
  66. echo "Usage: ${0} [interface] {up|down}"
  67. exit 1
  68. ;;
  69. esac
  70. # End /lib/boot/ipv4-static