1
0

ipv4-static 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/bin/sh
  2. ########################################################################
  3. # Begin /lib/network-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. . /lib/lsb/init-functions
  16. . ${IFCONFIG}
  17. if [ -z "${IP}" ]; then
  18. log_failure_msg "IP variable missing from ${IFCONFIG}, cannot continue."
  19. exit 1
  20. fi
  21. if [ -z "${PREFIX}" -a -z "${PEER}" ]; then
  22. log_warning_msg "PREFIX variable missing from ${IFCONFIG}, assuming 24."
  23. PREFIX=24
  24. args="${args} ${IP}/${PREFIX}"
  25. elif [ -n "${PREFIX}" -a -n "${PEER}" ]; then
  26. log_failure_msg "PREFIX and PEER both specified in ${IFCONFIG}, cannot continue."
  27. exit 1
  28. elif [ -n "${PREFIX}" ]; then
  29. args="${args} ${IP}/${PREFIX}"
  30. elif [ -n "${PEER}" ]; then
  31. args="${args} ${IP} peer ${PEER}"
  32. fi
  33. if [ -n "${BROADCAST}" ]; then
  34. args="${args} broadcast ${BROADCAST}"
  35. fi
  36. if [ -n "${SOURCE}" ]; then
  37. args="${args} src ${SOURCE}"
  38. fi
  39. case "${2}" in
  40. up)
  41. MESSAGE="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. log_warning_msg "Gateway already setup; skipping." ${WARNING}
  47. else
  48. MESSAGE="Setting up default gateway..."
  49. ip route add default via ${GATEWAY} dev ${1}
  50. evaluate_retval
  51. fi
  52. fi
  53. ;;
  54. down)
  55. if [ -n "${GATEWAY}" ]; then
  56. MESSAGE="Removing default gateway..."
  57. ip route del default
  58. evaluate_retval
  59. fi
  60. MESSAGE="Removing IPv4 address ${IP} from the ${1} interface..."
  61. ip addr del ${args} dev ${1}
  62. evaluate_retval
  63. ;;
  64. *)
  65. echo "Usage: ${0} [interface] {up|down}"
  66. exit 1
  67. ;;
  68. esac
  69. # End /lib/network-services/ipv4-static