diff --git a/azurelinuxagent/common/osutil/redhat.py b/azurelinuxagent/common/osutil/redhat.py index 312dd1608..4b46a97ad 100644 --- a/azurelinuxagent/common/osutil/redhat.py +++ b/azurelinuxagent/common/osutil/redhat.py @@ -164,3 +164,15 @@ def restart_if(self, ifname, retries=3, wait=5): time.sleep(wait) else: logger.warn("exceeded restart retries") + + def set_dhcp_hostname(self, hostname): + """ + Recent RHEL distributions use network manager instead of sysconfig files + to configure network interfaces + """ + ifname = self.get_if_name() + + return_code = shellutil.run("nmcli device modify {0} ipv4.dhcp-hostname {1} ipv6.dhcp-hostname {1}".format(ifname, hostname)) + + if return_code != 0: + logger.error("failed to set DHCP hostname for interface {0}: return code {1}".format(ifname, return_code))