Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not send localhost as the name for dhclient #2930

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion azurelinuxagent/common/osutil/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -1154,12 +1154,15 @@ def set_hostname(self, hostname):
self._run_command_without_raising(["hostname", hostname], log_error=False)

def set_dhcp_hostname(self, hostname):
# ensure localhost is not sent to the dhcp server
if hostname.lower() == "localhost" or hostname.lower() == "localhost.localdomain":
hostname = ""
autosend = r'^[^#]*?send\s*host-name.*?(<hostname>|gethostname[(,)])'
dhclient_files = ['/etc/dhcp/dhclient.conf', '/etc/dhcp3/dhclient.conf', '/etc/dhclient.conf']
for conf_file in dhclient_files:
if not os.path.isfile(conf_file):
continue
if fileutil.findre_in_file(conf_file, autosend):
if hostname != "" and fileutil.findre_in_file(conf_file, autosend):
# Return if auto send host-name is configured
return
fileutil.update_conf_file(conf_file,
Expand Down
3 changes: 3 additions & 0 deletions azurelinuxagent/common/osutil/redhat.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ def set_hostname(self, hostname):
self._run_command_without_raising(["hostname", hostname], log_error=False)

def set_dhcp_hostname(self, hostname):
# ensure localhost is not sent to the dhcp server
if hostname.lower() == "localhost" or hostname.lower() == "localhost.localdomain":
hostname = ""
ifname = self.get_if_name()
filepath = "/etc/sysconfig/network-scripts/ifcfg-{0}".format(ifname)
fileutil.update_conf_file(filepath,
Expand Down
6 changes: 6 additions & 0 deletions azurelinuxagent/common/osutil/suse.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ def set_hostname(self, hostname):
)

def set_dhcp_hostname(self, hostname):
# ensure localhost is not sent to the dhcp server
if hostname.lower() == "localhost" or hostname.lower() == "localhost.localdomain":
# if the DHCLIENT_HOSTNAME_OPTION is empty it will not send a hostname to the dhcp server
# reference: https://manpages.opensuse.org/Tumbleweed/wicked/ifcfg-dhcp.5.en.html
hostname = ""

dhcp_config_file_path = '/etc/sysconfig/network/dhcp'
hostname_send_setting = fileutil.get_line_startingwith(
'DHCLIENT_HOSTNAME_OPTION', dhcp_config_file_path
Expand Down
Loading