Hi,
I am currently writing the documentation for template creation and have run
across this problem with Debain.
Currently I have created a script which sets the hostname and adds a
/etc/hosts file, like Shankers, the script runs
from /etc/dhcp/dhclient-exit-hooks.d/sethostname with 744 permissions. It
does require the template to have a hostname of localhost for the script to
run.
Regards,
Marty
On Mon, Aug 19, 2013 at 1:02 PM, Gaspare A Silvestri <
[email protected]> wrote:
> Hi Shanker,
>
> thank you for your answer.
>
> Which way have we to use the indicated hook? Within the same password
> script, or as external script to execute at the machine startup?
>
> Thanks in advance,
>
> Gaspare
>
>
> On 19/08/2013 12:42, Shanker Balan wrote:
>
>> On 09-Aug-2013, at 9:42 AM, Prasanna Santhanam <[email protected]> wrote:
>>
>> FWIW, the debian image of our system VM is Debian 7 and uses the dhcp
>>> client from:
>>>
>>> deb
>>> http://http.us.debian.org/**debian<http://http.us.debian.org/debian>wheezy-backports
>>> main
>>> apt-get install dhcp3-client
>>>
>>> Can you try that and see if it works?
>>>
>>
>> Another FWIW: I just looked back at my scripts and I seem to creating a
>> DHCP exit hook as below on Debian templates.
>>
>> $ cat /etc/dhcp/dhclient-exit-hooks.**d/hostname
>> #!/bin/sh
>> #
>> # Update hostname from DHCP
>> #
>> if [ "$reason" != BOUND ] && [ "$reason" != RENEW ] && [ "$reason" !=
>> REBIND ] && [ "$reason" != REBOOT ]; then
>> return
>> fi
>>
>> hostname $new_host_name
>> echo $new_host_name > /etc/hostname
>>
>>
>> On Thu, Aug 08, 2013 at 09:52:07PM +0000, Musayev, Ilya wrote:
>>>
>>>> Perhaps, make sure you don't set the hostname in your template anywhere
>>>> in the config and use dhcp provided hostname instead?
>>>>
>>>> From: Netsons > Roberto Iervolino
>>>> [mailto:r.iervolino@netsons.**com<[email protected]>
>>>> ]
>>>> Sent: Thursday, August 08, 2013 3:10 AM
>>>> To: [email protected]
>>>> Subject: Re: Debian 7 does not get hostname from dhcp.
>>>>
>>>> There is a way to solve this known issue?
>>>>
>>>> Thanks.
>>>>
>>>> [cid:image001.png@01CE945F.**FFAC77E0]
>>>>
>>>> Supernova s.r.l.
>>>> Via G. Misiticoni, 3
>>>> 65126 - Pescara
>>>> ITALY
>>>>
>>>>
>>>> www.netsons.com<http://www.**netsons.com <http://www.netsons.com>>
>>>>
>>>> Roberto Iervolino
>>>> IT System Administrator - L2 Support
>>>>
>>>>
>>>> t. (+39) 085 45 100 52
>>>> m. (+39) 393 85 677 48
>>>> e. [email protected]<**mailto:[email protected]**>
>>>>
>>>>
>>>> [View Roberto Iervolino's profile on LinkedIn]<http://it.linkedin.**
>>>> com/pub/roberto-iervolino/70/**b81/3aa<http://it.linkedin.com/pub/roberto-iervolino/70/b81/3aa>
>>>> >
>>>>
>>>>
>>>>
>>>> Netsons? ? un marchio registrato dalla Supernova s.r.l.
>>>> Le informazioni trasmesse sono riservate alla persona o alla societ?
>>>> indicata come destinatario, e possono includere contenuti considerati
>>>> confidenziali. Ogni elaborazione, comunicazione, trasmissione o altro
>>>> utilizzo, anche azioni conseguenti alla conoscenza di queste informazioni
>>>> da parte di chiunque non sia espressamente indicato come destinatario ?
>>>> proibita. Nel caso abbiate ricevuto per errore questa comunicazione, siete
>>>> pregati di darne avviso a info [at] netsons.com ed eliminare ogni
>>>> stampa ed ogni traccia informatica. Il ricevente dovr? inoltre accertarsi
>>>> che gli eventuali allegati non contengano virus prima di aprirli. Qualunque
>>>> opinione o affermazione presentata in questo messaggio ? da ritenersi
>>>> propria dell'autore e non rappresenta necessariamente la posizione della
>>>> Societ?.
>>>>
>>>> The information transmitted is intended only for the person or entity
>>>> to which it is addressed and may contain confidential material. Any review,
>>>> retransmission, dissemination or other use of, or taking of any action in
>>>> reliance upon this information by persons or entities other than the
>>>> intended recipient is prohibited. If you received this in error, please
>>>> contact: info [at] netsons.com and delete the material from any
>>>> computer. If this email contains attachments you should ensure they are
>>>> checked for viruses before opening them. Any views or opinions presented
>>>> are solely those of the author and do not necessarily represent those of
>>>> the company.
>>>> Il 08/08/2013 00:14, David Nalley ha scritto:
>>>>
>>>> On Wed, Aug 7, 2013 at 12:36 PM, Netsons > Roberto Iervolino <
>>>>
>>>> [email protected]<**mailto:[email protected]**>> wrote:
>>>>
>>>>
>>>>
>>>> Hi,
>>>>
>>>>
>>>>
>>>> I've done a template using debian 7.0.0, when i deploy an istance from
>>>>
>>>> this template the VM at the first boot get correctly the hostname from
>>>> the
>>>>
>>>> DHCP server, then when I reboot the VM does not get the hostname from
>>>> the
>>>>
>>>> DHCP server, and the setted hostname is "localhost".
>>>>
>>>>
>>>>
>>>> I've also created other template using CentOS 6.4 and it works fine.
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> There is a known issue with debian 7.0.0? How can i solve it?
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> IIRC this is a known issue with Debian and the version of dhclient they
>>>>
>>>> ship.
>>>>
>>>>
>>>>
>>>> --David
>>>>
>>>>
>>>>
>>>>
>>> --
>>> Prasanna.,
>>>
>>> ------------------------
>>> Powered by BigRock.com
>>>
>>> --
>> @shankerbalan
>>
>> M: +91 98860 60539 | O: +91 (80) 67935867
>> [email protected] | www.shapeblue.com | Twitter:@shapeblue
>> ShapeBlue Services India LLP, 22nd floor, Unit 2201A, World Trade Centre,
>> Bangalore - 560 055
>>
>> This email and any attachments to it may be confidential and are intended
>> solely for the use of the individual to whom it is addressed. Any views or
>> opinions expressed are solely those of the author and do not necessarily
>> represent those of Shape Blue Ltd or related companies. If you are not the
>> intended recipient of this email, you must neither take any action based
>> upon its contents, nor copy or show it to anyone. Please contact the sender
>> if you believe you have received this email in error. Shape Blue Ltd is a
>> company incorporated in England & Wales. ShapeBlue Services India LLP is
>> operated under license from Shape Blue Ltd. ShapeBlue is a registered
>> trademark.
>>
>
>
>
>
#!/bin/sh
oldhostname=$(hostname -s)
if [ $oldhostname = 'localhost' ]
then
hostname=$(cat /var/lib/dhcp/dhclient.eth0.leases | awk ' /host-name/ { host
= $3 } END { printf host } ' | sed 's/[";]//g' )
fqdn="$hostname.$(cat /var/lib/dhcp/dhclient.eth0.leases | awk '
/domain-name/ { domain = $3 } END { printf domain } ' | sed 's/[";]//g')"
ip=$(cat /var/lib/dhcp/dhclient.eth0.leases | awk ' /fixed-address/ { lease
= $2 } END { printf lease } ' | sed 's/[";]//g')
echo "cloudstack-hostname: Hostname _localhost_ detected. Changing hostname
and adding hosts."
echo " Hostname: $hostname \n FQDN: $fqdn \n IP: $ip"
# Update /etc/hosts
awk -v i="$ip" -v f="$fqdn" -v h="$hostname" '/^127/{x=1} !/^127/ && x { x=0;
print i,f,h; } { print $0; }' /etc/hosts > /etc/hosts.dhcp.tmp
mv /etc/hosts /etc/hosts.dhcp.bak
mv /etc/hosts.dhcp.tmp /etc/hosts
# Rename Host
echo $hostname > /etc/hostname
hostname $hostname
# Recreate SSH2
dpkg-reconfig openssh-server
fi