1
0

ipv4-static 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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 "${LABEL}" ]; then
  33. args="${args} label ${LABEL}"
  34. fi
  35. if [ -n "${BROADCAST}" ]; then
  36. args="${args} broadcast ${BROADCAST}"
  37. fi
  38. case "${2}" in
  39. up)
  40. if [ "$(ip addr show ${1} 2>/dev/null | grep ${IP}/)" = "" ]; then
  41. # Cosmetic output
  42. if ! $(echo ${SERVICE} | grep -q " "); then
  43. log_info_msg2 "\n" # Terminate the previous message
  44. fi
  45. log_info_msg "Adding IPv4 address ${IP} to the ${1} interface..."
  46. ip addr add ${args} dev ${1}
  47. evaluate_retval
  48. else
  49. log_warning_msg "Cannot add IPv4 address ${IP} to ${1}. Already present."
  50. fi
  51. ;;
  52. down)
  53. if [ "$(ip addr show ${1} 2>/dev/null | grep ${IP}/)" != "" ]; then
  54. log_info_msg "Removing IPv4 address ${IP} from the ${1} interface..."
  55. ip addr del ${args} dev ${1}
  56. evaluate_retval
  57. fi
  58. if [ -n "${GATEWAY}" ]; then
  59. # Only remove the gateway if there are no remaining ipv4 addresses
  60. if [ "$(ip addr show ${1} 2>/dev/null | grep 'inet ')" != "" ]; then
  61. log_info_msg "Removing default gateway..."
  62. ip route del default
  63. evaluate_retval
  64. fi
  65. fi
  66. ;;
  67. *)
  68. echo "Usage: ${0} [interface] {up|down}"
  69. exit 1
  70. ;;
  71. esac
  72. # End /lib/services/ipv4-static