hv_set_ifconfig.sh 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/bin/bash
  2. # SPDX-License-Identifier: GPL-2.0
  3. # This example script activates an interface based on the specified
  4. # configuration.
  5. #
  6. # In the interest of keeping the KVP daemon code free of distro specific
  7. # information; the kvp daemon code invokes this external script to configure
  8. # the interface.
  9. #
  10. # The only argument to this script is the configuration file that is to
  11. # be used to configure the interface.
  12. #
  13. # Each Distro is expected to implement this script in a distro specific
  14. # fashion. For instance, on Distros that ship with Network Manager enabled,
  15. # this script can be based on the Network Manager APIs for configuring the
  16. # interface.
  17. #
  18. # This example script is based on a RHEL environment.
  19. #
  20. # Here is the ifcfg format of the ip configuration file:
  21. #
  22. # HWADDR=macaddr
  23. # DEVICE=interface name
  24. # BOOTPROTO=<protocol> (where <protocol> is "dhcp" if DHCP is configured
  25. # or "none" if no boot-time protocol should be used)
  26. #
  27. # IPADDR0=ipaddr1
  28. # IPADDR1=ipaddr2
  29. # IPADDRx=ipaddry (where y = x + 1)
  30. #
  31. # NETMASK0=netmask1
  32. # NETMASKx=netmasky (where y = x + 1)
  33. #
  34. # GATEWAY=ipaddr1
  35. # GATEWAYx=ipaddry (where y = x + 1)
  36. #
  37. # DNSx=ipaddrx (where first DNS address is tagged as DNS1 etc)
  38. #
  39. # IPV6 addresses will be tagged as IPV6ADDR, IPV6 gateway will be
  40. # tagged as IPV6_DEFAULTGW and IPV6 NETMASK will be tagged as
  41. # IPV6NETMASK.
  42. #
  43. # Here is the keyfile format of the ip configuration file:
  44. #
  45. # [ethernet]
  46. # mac-address=macaddr
  47. # [connection]
  48. # interface-name=interface name
  49. #
  50. # [ipv4]
  51. # method=<protocol> (where <protocol> is "auto" if DHCP is configured
  52. # or "manual" if no boot-time protocol should be used)
  53. #
  54. # address1=ipaddr1/plen
  55. # address2=ipaddr2/plen
  56. #
  57. # gateway=gateway1;gateway2
  58. #
  59. # dns=dns1;
  60. #
  61. # [ipv6]
  62. # address1=ipaddr1/plen
  63. # address2=ipaddr2/plen
  64. #
  65. # gateway=gateway1;gateway2
  66. #
  67. # dns=dns1;dns2
  68. #
  69. # The host can specify multiple ipv4 and ipv6 addresses to be
  70. # configured for the interface. Furthermore, the configuration
  71. # needs to be persistent. A subsequent GET call on the interface
  72. # is expected to return the configuration that is set via the SET
  73. # call.
  74. #
  75. echo "IPV6INIT=yes" >> $1
  76. echo "NM_CONTROLLED=no" >> $1
  77. echo "PEERDNS=yes" >> $1
  78. echo "ONBOOT=yes" >> $1
  79. cp $1 /etc/sysconfig/network-scripts/
  80. umask 0177
  81. interface=$(echo $2 | awk -F - '{ print $2 }')
  82. filename="${2##*/}"
  83. sed '/\[connection\]/a autoconnect=true' $2 > /etc/NetworkManager/system-connections/${filename}
  84. /sbin/ifdown $interface 2>/dev/null
  85. /sbin/ifup $interface 2>/dev/null