hv_set_ifconfig.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/bin/bash
  2. # This example script activates an interface based on the specified
  3. # configuration.
  4. #
  5. # In the interest of keeping the KVP daemon code free of distro specific
  6. # information; the kvp daemon code invokes this external script to configure
  7. # the interface.
  8. #
  9. # The only argument to this script is the configuration file that is to
  10. # be used to configure the interface.
  11. #
  12. # Each Distro is expected to implement this script in a distro specific
  13. # fashion. For instance on Distros that ship with Network Manager enabled,
  14. # this script can be based on the Network Manager APIs for configuring the
  15. # interface.
  16. #
  17. # This example script is based on a RHEL environment.
  18. #
  19. # Here is the format of the ip configuration file:
  20. #
  21. # HWADDR=macaddr
  22. # IF_NAME=interface name
  23. # DHCP=yes (This is optional; if yes, DHCP is configured)
  24. #
  25. # IPADDR=ipaddr1
  26. # IPADDR_1=ipaddr2
  27. # IPADDR_x=ipaddry (where y = x + 1)
  28. #
  29. # NETMASK=netmask1
  30. # NETMASK_x=netmasky (where y = x + 1)
  31. #
  32. # GATEWAY=ipaddr1
  33. # GATEWAY_x=ipaddry (where y = x + 1)
  34. #
  35. # DNSx=ipaddrx (where first DNS address is tagged as DNS1 etc)
  36. #
  37. # IPV6 addresses will be tagged as IPV6ADDR, IPV6 gateway will be
  38. # tagged as IPV6_DEFAULTGW and IPV6 NETMASK will be tagged as
  39. # IPV6NETMASK.
  40. #
  41. # The host can specify multiple ipv4 and ipv6 addresses to be
  42. # configured for the interface. Furthermore, the configuration
  43. # needs to be persistent. A subsequent GET call on the interface
  44. # is expected to return the configuration that is set via the SET
  45. # call.
  46. #
  47. echo "IPV6INIT=yes" >> $1
  48. echo "NM_CONTROLLED=no" >> $1
  49. echo "PEERDNS=yes" >> $1
  50. echo "ONBOOT=yes" >> $1
  51. dhcp=$(grep "DHCP" $1 2>/dev/null)
  52. if [ "$dhcp" != "" ];
  53. then
  54. echo "BOOTPROTO=dhcp" >> $1;
  55. fi
  56. cp $1 /etc/sysconfig/network-scripts/
  57. interface=$(echo $1 | awk -F - '{ print $2 }')
  58. /sbin/ifdown $interface 2>/dev/null
  59. /sbin/ifup $interfac 2>/dev/null