WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: How to set hostname to DNS name  (Read 2446 times)

Offline fow0ryl

  • Newbie
  • *
  • Posts: 12
How to set hostname to DNS name
« on: October 17, 2017, 08:57:14 AM »
Hello,

I would like to run some thin clients with TC and rdesktop.
The hostname used by TC should be the same as the name provided by the DHCP Server.
My idea is to run ifconfig to get the ip of the machine. Then run a nslookup to find out the hostname.
This hostname could be used to change /etc/hostname and set by "hostname -F /etc/hostname.

But what's the right place to do that?
I could set a hostname in bootlocal. This works i.e when using the mac address to set a unique hostname.
But the network connection isn't established as that time, so I can't get the dns name.

And how to run the functions as root? /etc/hostname can't be changed as user...

Henning

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11634
Re: How to set hostname to DNS name
« Reply #1 on: October 17, 2017, 10:17:40 AM »
Hi fow0ryl
There are a couple different ways to do this. One way is to set up a script called HostSetup.sh containing:
Code: [Select]
#!/bin/sh

SEC=60

touch /home/tc/NoNetwork                          # Set the error flag

while [ $SEC -gt 0 ] ; do
   ifconfig | grep -q "Bcast" && break || sleep 1 # Break if the network is up, otherwise sleep for 1 second
   echo -ne "Waiting for IP $((SEC--))  \r"       # This echo is not required for normal use
done

if [ $SEC -gt 0 ]
then                                              # We only execute this section if $SEC is greater than zero
                                                  # Add your commands here.
 
       rm /home/tc/NoNetwork                      # Clear the error flag
fi


Add a line to bootlocal containing:
Code: [Select]
HostSetup.sh &This will launch the script in the background where it will wait for the network to come and then execute any required
commands. If the network does not come up, a file called  /home/tc/NoNetwork  will be left behind to indicate that.

Offline fow0ryl

  • Newbie
  • *
  • Posts: 12
Re: How to set hostname to DNS name (solved)
« Reply #2 on: October 17, 2017, 06:22:52 PM »
Hello,

thank you very much.
Setting up the hostname is working fine now.

Henning

Online Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11634
Re: How to set hostname to DNS name
« Reply #3 on: October 17, 2017, 08:08:52 PM »
Hi fow0ryl
Glad to hear it worked out for you.