ipv4-static 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #!/bin/sh
  2. ########################################################################
  3. # Begin /lib/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. # Update : Bruce Dubbs - bdubbs@linuxfromscratch.org
  10. #
  11. # Version : LFS 7.0
  12. #
  13. ########################################################################
  14. . /lib/lsb/init-functions
  15. . ${IFCONFIG}
  16. if [ -z "${IP}" ]; then
  17. log_failure_msg "\nIP variable missing from ${IFCONFIG}, cannot continue."
  18. exit 1
  19. fi
  20. if [ -z "${PREFIX}" -a -z "${PEER}" ]; then
  21. log_warning_msg "\nPREFIX variable missing from ${IFCONFIG}, assuming 24."
  22. PREFIX=24
  23. args="${args} ${IP}/${PREFIX}"
  24. elif [ -n "${PREFIX}" -a -n "${PEER}" ]; then
  25. log_failure_msg "\nPREFIX and PEER both specified in ${IFCONFIG}, cannot continue."
  26. exit 1
  27. elif [ -n "${PREFIX}" ]; then
  28. args="${args} ${IP}/${PREFIX}"
  29. elif [ -n "${PEER}" ]; then
  30. args="${args} ${IP} peer ${PEER}"
  31. fi
  32. if [ -n "${BROADCAST}" ]; then
  33. args="${args} broadcast ${BROADCAST}"
  34. fi
  35. case "${2}" in
  36. up)
  37. if [ "$(ip addr show ${1} 2>/dev/null | grep ${IP}/)" == "" ]; then
  38. # Cosmetic output not needed for multiple services
  39. if ! $(echo ${SERVICE} | grep -q " "); then
  40. log_info_msg2 "\n" # Terminate the previous message
  41. fi
  42. log_info_msg "Adding IPv4 address ${IP} to the ${1} interface..."
  43. ip addr add ${args} dev ${1}
  44. evaluate_retval
  45. else
  46. log_warning_msg "Cannot add IPv4 address ${IP} to ${1}. Already present."
  47. fi
  48. ;;
  49. down)
  50. if [ "$(ip addr show ${1} 2>/dev/null | grep ${IP}/)" != "" ]; then
  51. log_info_msg "Removing IPv4 address ${IP} from the ${1} interface..."
  52. ip addr del ${args} dev ${1}
  53. evaluate_retval
  54. fi
  55. if [ -n "${GATEWAY}" ]; then
  56. # Only remove the gateway if ther are no remaining ipv4 addresses
  57. if [ "$(ip addr show ${1} 2>/dev/null | grep 'inet ')" != "" ]; then
  58. log_info_msg "Removing default gateway..."
  59. ip route del default
  60. evaluate_retval
  61. fi
  62. fi
  63. ;;
  64. *)
  65. echo "Usage: ${0} [interface] {up|down}"
  66. exit 1
  67. ;;
  68. esac
  69. # End /lib/services/ipv4-static