ipv4-static 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #!/bin/sh
  2. ########################################################################
  3. # Begin $network_devices/services/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. #
  10. # Version : 00.00
  11. #
  12. # Notes :
  13. #
  14. ########################################################################
  15. . /etc/sysconfig/rc
  16. . ${rc_functions}
  17. . ${IFCONFIG}
  18. if [ -z "${IP}" ]; then
  19. boot_mesg "IP variable missing from ${IFCONFIG}, cannot continue." ${FAILURE}
  20. echo_failure
  21. exit 1
  22. fi
  23. if [ -z "${PREFIX}" -a -z "${PEER}" ]; then
  24. boot_mesg -n "PREFIX variable missing from ${IFCONFIG}," ${WARNING}
  25. boot_mesg " assuming 24."
  26. echo_warning
  27. PREFIX=24
  28. args="${args} ${IP}/${PREFIX}"
  29. elif [ -n "${PREFIX}" -a -n "${PEER}" ]; then
  30. boot_mesg "PREFIX and PEER both specified in ${IFCONFIG}, cannot continue." ${FAILURE}
  31. echo_failure
  32. exit 1
  33. elif [ -n "${PREFIX}" ]; then
  34. args="${args} ${IP}/${PREFIX}"
  35. elif [ -n "${PEER}" ]; then
  36. args="${args} ${IP} peer ${PEER}"
  37. fi
  38. if [ -n "${BROADCAST}" ]; then
  39. args="${args} broadcast ${BROADCAST}"
  40. fi
  41. case "${2}" in
  42. up)
  43. boot_mesg "Adding IPv4 address ${IP} to the ${1} interface..."
  44. ip addr add ${args} dev ${1}
  45. evaluate_retval
  46. if [ -n "${GATEWAY}" ]; then
  47. if ip route | grep -q default; then
  48. boot_mesg "Gateway already setup; skipping." ${WARNING}
  49. echo_warning
  50. else
  51. boot_mesg "Setting up default gateway..."
  52. ip route add default via ${GATEWAY} dev ${1}
  53. evaluate_retval
  54. fi
  55. fi
  56. ;;
  57. down)
  58. if [ -n "${GATEWAY}" ]; then
  59. boot_mesg "Removing default gateway..."
  60. ip route del default
  61. evaluate_retval
  62. fi
  63. boot_mesg "Removing IPv4 address ${IP} from the ${1} interface..."
  64. ip addr del ${args} dev ${1}
  65. evaluate_retval
  66. ;;
  67. *)
  68. echo "Usage: ${0} [interface] {up|down}"
  69. exit 1
  70. ;;
  71. esac
  72. # End $network_devices/services/ipv4-static