diff options
author | David Kaspar [Dee'Kej] <dkaspar@redhat.com> | 2017-05-02 23:17:19 +0200 |
---|---|---|
committer | Dee'Kej <deekej@linuxmail.org> | 2017-05-03 11:53:09 +0200 |
commit | c087ea1d7d0e21865a763b0d7e0bc8d3557d1830 (patch) | |
tree | b2c060e23952be86de2ffb07fc71ad4e66bee7d3 | |
parent | e37d6b2c4dc1db8e31d9c230fab929cbc83648b6 (diff) | |
download | initscripts-c087ea1d7d0e21865a763b0d7e0bc8d3557d1830.tar initscripts-c087ea1d7d0e21865a763b0d7e0bc8d3557d1830.tar.gz initscripts-c087ea1d7d0e21865a763b0d7e0bc8d3557d1830.tar.bz2 initscripts-c087ea1d7d0e21865a763b0d7e0bc8d3557d1830.tar.xz initscripts-c087ea1d7d0e21865a763b0d7e0bc8d3557d1830.zip |
DHCP_FQDN and DHCP_SEND_HOSTNAME introduced
The way DHCP_HOSTNAME is being sent to DHCP server has been completely
reworked...
DHCP_FQDN now allows user to specify fully qualified domain name to be
sent to DHCP server instead of just using simple hostname. This option
takes precedence before DHCP_HOSTNAME variable.
DHCP_SEND_HOSTNAME can be used to tell initscripts to not send either
DHCP_HOSTNAME or DHCP_FQDN to DHCP server.
Both of these options should behave same as they do in NetworkManager.
-rw-r--r-- | examples/networking/ifcfg-eth-dhcp | 5 | ||||
-rw-r--r-- | sysconfig.txt | 12 | ||||
-rwxr-xr-x | sysconfig/network-scripts/ifup-eth | 20 | ||||
-rw-r--r-- | sysconfig/network-scripts/network-functions | 32 |
4 files changed, 53 insertions, 16 deletions
diff --git a/examples/networking/ifcfg-eth-dhcp b/examples/networking/ifcfg-eth-dhcp index 2dd687ab..58d46bf8 100644 --- a/examples/networking/ifcfg-eth-dhcp +++ b/examples/networking/ifcfg-eth-dhcp @@ -7,5 +7,8 @@ DEVICE=eth0 BOOTPROTO=dhcp HWADDR=00:11:22:33:44:55 ONBOOT=yes -DHCP_HOSTNAME=host1 +# WARNING: When both DHCP_HOSTNAME and DHCP_FQDN are specified, +# only DHCP_FQDN will be used. +DHCP_HOSTNAME=host1 +DHCP_FQDN=host1.foo.bar.com diff --git a/sysconfig.txt b/sysconfig.txt index 08243f11..f09c6d8b 100644 --- a/sysconfig.txt +++ b/sysconfig.txt @@ -550,8 +550,18 @@ Files in /etc/sysconfig/network-scripts/ With this option set to 'yes' (1), when a dhcp configured interface is brought down with 'ifdown', the lease will be released. Otherwise, leases are not released. - DHCP_HOSTNAME=<name> + + DHCP_SEND_HOSTNAME=yes|no|1|0 + Tells initscripts whether the DHCP_HOSTNAME or DHCP_FQDN options (below) + should be sent to DHCP server. + DHCP_HOSTNAME=<hostname> Sends the specified hostname to the DHCP server. + DHCP_FQDN=<fully.qualified.domain.name> + Sends the specified FQDN to the DHCP server. + + Please note when both DHCP_HOSTNAME and DHCP_FQDN are specified, + only DHCP_FQDN will be used. (Same behaviour as with NetworkManager.) + DHCLIENT_IGNORE_GATEWAY=yes|no|1|0 If set to 'yes', it will cause dhclient-script to ignore any $GATEWAY setting that may be in the ifcfg file for this interface. diff --git a/sysconfig/network-scripts/ifup-eth b/sysconfig/network-scripts/ifup-eth index b6a883f6..3da5c16b 100755 --- a/sysconfig/network-scripts/ifup-eth +++ b/sysconfig/network-scripts/ifup-eth @@ -186,13 +186,9 @@ if [ -n "${DYNCONFIG}" ] && [ -x /sbin/dhclient ]; then generate_config_file_name generate_lease_file_name - if is_hostname_set; then - # We already have the hostname ->> send it to DHCP: - DHCLIENTARGS="${DHCLIENTARGS} -H ${DHCP_HOSTNAME:-${HOSTNAME%%.*}} ${ONESHOT} -q ${DHCLIENTCONF} -lf ${LEASEFILE} -pf /var/run/dhclient-${DEVICE}.pid" - else - # We need to acquire the hostname: - DHCLIENTARGS="${DHCLIENTARGS} ${DHCP_HOSTNAME:+-H $DHCP_HOSTNAME} ${ONESHOT} -q ${DHCLIENTCONF} -lf ${LEASEFILE} -pf /var/run/dhclient-${DEVICE}.pid" - fi + # Initialize the dhclient args and obtain the hostname options if needed: + DHCLIENTARGS="${DHCLIENTARGS} ${ONESHOT} -q ${DHCLIENTCONF} -lf ${LEASEFILE} -pf /var/run/dhclient-${DEVICE}.pid" + set_hostname_options DHCLIENTARGS echo echo -n $"Determining IP information for ${DEVICE}..." @@ -335,13 +331,9 @@ if is_true "${DHCPV6C}" && [ -x /sbin/dhclient ]; then echo echo -n $"Determining IPv6 information for ${DEVICE}..." - if is_hostname_set; then - # We already have the hostname ->> send it to DHCP: - DHCLIENTARGS="-6 -1 ${DHCPV6C_OPTIONS} ${DHCLIENTCONF} -lf ${LEASEFILE} -pf /var/run/dhclient6-${DEVICE}.pid -H ${DHCP_HOSTNAME:-${HOSTNAME%%.*}} ${DEVICE}" - else - # We need to acquire the hostname: - DHCLIENTARGS="-6 -1 ${DHCPV6C_OPTIONS} ${DHCLIENTCONF} -lf ${LEASEFILE} -pf /var/run/dhclient6-${DEVICE}.pid ${DHCP_HOSTNAME:+-H $DHCP_HOSTNAME} ${DEVICE}" - fi + # Initialize the dhclient args for IPv6 and obtain the hostname options if needed: + DHCLIENTARGS="-6 -1 ${DHCPV6C_OPTIONS} ${DHCLIENTCONF} -lf ${LEASEFILE} -pf /var/run/dhclient6-${DEVICE}.pid ${DEVICE}" + set_hostname_options DHCLIENTARGS if /sbin/dhclient $DHCLIENTARGS; then echo $" done." diff --git a/sysconfig/network-scripts/network-functions b/sysconfig/network-scripts/network-functions index 850cc3ff..1867c38a 100644 --- a/sysconfig/network-scripts/network-functions +++ b/sysconfig/network-scripts/network-functions @@ -397,6 +397,38 @@ need_hostname () fi } +set_hostname_options () +{ + # User explicitly requires to *not* send DHCP_HOSTNAME, DHCP_FQDN or HOSTNAME: + is_false "${DHCP_SEND_HOSTNAME}" && return + + if [[ -n "${DHCP_HOSTNAME}" && -n "${DHCP_FQDN}" ]]; then + net_log $"Both 'DHCP_HOSTNAME=${DHCP_HOSTNAME}' and 'DHCP_FQDN=${DHCP_FQDN}' are configured... Using DHCP_FQDN." warning + fi + + local hostname_options='' + + # DHCP_FQDN takes precedence before DHCP_HOSTNAME -- as it does in NetworkManager, + # and DHCP_HOSTNAME takes precedence before HOSTNAME: + if [[ -n "${DHCP_FQDN}" ]]; then + hostname_options="-F ${DHCP_FQDN}" + elif [[ -n "${DHCP_HOSTNAME}" ]]; then + hostname_options="-H ${DHCP_HOSTNAME}" + elif is_hostname_set; then + # We need to truncate the hostname in case it is the FQDN: + hostname_options="-H ${HOSTNAME%%.*}" + else + # Nothing to send to the DHCP server: + # ['(none)', 'localhost' or 'localhost.localdomain' are not valid] + return + fi + + # Append the hostname options to the content of passed variable name: + eval "$1='${!1} ${hostname_options}'" + + return +} + set_hostname () { hostname $1 |