ifdown 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #!/bin/bash
  2. ########################################################################
  3. # Begin /sbin/ifdown
  4. #
  5. # Description : Interface Down
  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. # Notes : the IFCONFIG variable is passed to the scripts found
  14. # in the /lib/services directory, to indicate what file the
  15. # service should source to get interface specifications.
  16. #
  17. ########################################################################
  18. RELEASE="7.0"
  19. USAGE="Usage: $0 [ -hV ] [--help] [--version] interface"
  20. VERSTR="LFS ifdown, version ${RELEASE}"
  21. while [ $# -gt 0 ]; do
  22. case "$1" in
  23. --help | -h) help="y"; break ;;
  24. --version | -V) echo "${VERSTR}"; exit 0 ;;
  25. -*) echo "ifup: ${1}: invalid option" >&2
  26. echo "${USAGE}" >& 2
  27. exit 2 ;;
  28. *) break ;;
  29. esac
  30. done
  31. if [ -n "$help" ]; then
  32. echo "${VERSTR}"
  33. echo "${USAGE}"
  34. echo
  35. cat << HERE_EOF
  36. ifdown is used to bring down a network interface. The interface
  37. parameter, e.g. eth0 or eth0:2, must match the trailing part of the
  38. interface specifications file, e.g. /etc/sysconfig/ifconfig.eth0:2.
  39. HERE_EOF
  40. exit 0
  41. fi
  42. file=/etc/sysconfig/ifconfig.${1}
  43. # Skip backup files
  44. [ "${file}" = "${file%""~""}" ] || exit 0
  45. . /lib/lsb/init-functions
  46. if [ ! -r "${file}" ]; then
  47. log_warning_msg "${file} is missing or cannot be accessed."
  48. exit 1
  49. fi
  50. . ${file}
  51. if [ "$IFACE" = "" ]; then
  52. log_failure_msg "${file} does not define an interface [IFACE]."
  53. exit 1
  54. fi
  55. # We only need to first service to bring down the interface
  56. S=`echo ${SERVICE} | cut -f1 -d" "`
  57. if ip link show ${IFACE} > /dev/null 2>&1; then
  58. if [ -n "${S}" -a -x "/lib/services/${S}" ]; then
  59. IFCONFIG=${file} /lib/services/${S} ${IFACE} down
  60. else
  61. MSG="Unable to process ${file}. Either "
  62. MSG="${MSG}the SERVICE variable was not set "
  63. MSG="${MSG}or the specified service cannot be executed."
  64. log_failure_msg "$MSG"
  65. exit 1
  66. fi
  67. else
  68. log_warning_msg "Interface ${1} doesn't exist."
  69. fi
  70. # Leave the interface up if there are additional interfaces in the device
  71. link_status=`ip link show ${IFACE} 2>/dev/null`
  72. if [ -n "${link_status}" ]; then
  73. if [ "$(echo "${link_status}" | grep UP)" != "" ]; then
  74. if [ "$(ip addr show ${IFACE} | grep 'inet ')" == "" ]; then
  75. log_info_msg "Bringing down the ${IFACE} interface..."
  76. ip link set ${IFACE} down
  77. evaluate_retval
  78. fi
  79. fi
  80. fi
  81. # End /sbin/ifdown