Results 1 to 6 of 6

Thread: Can (how do) I send hostname to dhclient.conf

  1. #1
    Join Date
    Jan 2006
    Location
    Not heaven... Iowa
    Beans
    Hidden!
    Distro
    Ubuntu

    Can (how do) I send hostname to dhclient.conf

    Code:
    send host-name "myhostname";
    Rather than hardcode in the name of my hostname:
    I'd rather use the environment variable $HOSTNAME.

    Code:
    send host-name $HOSTNAME;
    This doesn't work - apparently needs the quotes to indicate text.

    Code:
    send host-name "$HOSTNAME";
    This works, but names the machine $HOSTNAME.

    Is it even possible to do what I'm attempting?
    Linux User #415691 Ubuntu User #8629
    Iowa Team (LoCo): [Wiki] [Launchpad]
    IRC channel: #ubuntu-us-ia on irc.freenode.net

  2. #2
    Join Date
    Feb 2006
    Beans
    1,270
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Can (how do) I send hostname to dhclient.conf

    Quote Originally Posted by Iowan View Post
    Is it even possible to do what I'm attempting?
    A quick look throught `man dhclient.conf` suggests that the answer is no. dhclient.conf isn't a shell script, so the $ syntax won't work. I couldn't find any way to use an environment variable in the file.

    Doesn't dhclient send the contents of /etc/hostname by default?
    Last edited by skymt; October 12th, 2006 at 02:24 PM.
    Are you Listening?
    Are you a Hero?
    Are you Sleeping?

  3. #3
    Join Date
    Apr 2005
    Beans
    214
    Distro
    Edgy Eft Testing

    Re: Can (how do) I send hostname to dhclient.conf

    If it doesn't automatically pick up on /etc/hostname, you can alter the startup script to fill it in for you. Make a template file (called dhclient.conf.sh or something) that when run, creates your dhclient.conf file with the correct hostname. Hackish, but it would work. Seems like there should be a solution to this already though.

  4. #4
    Join Date
    Jan 2006
    Location
    Not heaven... Iowa
    Beans
    Hidden!
    Distro
    Ubuntu

    Re: Can (how do) I send hostname to dhclient.conf

    Quote Originally Posted by skymt View Post
    Doesn't dhclient send the contents /etc/hostname by default?
    Not quite sure what you mean...
    Code:
    send host-name ;
    I tried this - just to see if it'd take the default hostname...
    This is the same as leaving the line commented out.

    Thanks for all (both) the input!
    Linux User #415691 Ubuntu User #8629
    Iowa Team (LoCo): [Wiki] [Launchpad]
    IRC channel: #ubuntu-us-ia on irc.freenode.net

  5. #5
    Join Date
    Feb 2006
    Beans
    1,270
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Can (how do) I send hostname to dhclient.conf

    Quote Originally Posted by Iowan View Post
    Not quite sure what you mean...
    Code:
    send host-name ;
    I tried this - just to see if it'd take the default hostname...
    This is the same as leaving the line commented out.

    Thanks for all (both) the input!
    Yeah. I left out "of". I meant it sends the contents of /etc/hostname. For example, if the file /etc/hostname contains "foo.bar.net", dhclient should send foo.bar.net as the hostname.
    Are you Listening?
    Are you a Hero?
    Are you Sleeping?

  6. #6
    Join Date
    May 2009
    Beans
    2

    Re: Can (how do) I send hostname to dhclient.conf

    Update for anyone finding this via Google etc.: On dhclient versions >= 4.2.x you can now do
    Code:
    send host-name = gethostname();

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •