I just need to rename the hostnames of all the Desktops based on their IP Addresses. For example if the IP address is 172.29.72.25 hostname should be assigned as node25, if the IP address is 172.29.72.26 hostname should be node26 etc etc. I have keybased ssh access to all these hosts. I thing this is possible via bash script, can someone help me? Thanks in advance.
|
|
Hostname is stored in Where
For each IP, we cut the last field off, prefix it with "node" and write it to /etc/hostname Now, that ought to work, but it will only work if your user has write privileges to /etc/hostname, which by default, standard users don't have on Ubuntu. What you can do is feed your password to sudo via STDIN ; e.g. Don't, of course, write your password to a plain text file in your home folder... So, altogether
-- edit If you want to rewrite the hosts file on each machine, you could add a little awk to the mix ; replace the pattern
This will replace all hostnames for IP addresses in your subnet with "nodeN" where N is the last quad of the IP address. So we add these commands to the
|
|||||
|
