PATCH: Adding unique hostname generation with cheatcode
Change Log:
* Version 1.0 - Fri Jan 20, 2006
Added /etc/hosts modification
* Version 1.0 - Thu Dec 01, 2005
Initial design
Disclaimer:
Always needed cause you just never know how people will interpret things. Please people, use this at your own risk. Whilst this method has and continues to work for me, I will not be held responsible for anything that might go wrong, due to an ommision or typo in this document. I too, like you, am human and do make mistakes.
Preface:
This howto assumes an intermediate level of knowledge for bash scripting and knoppix remastering. It was posted becuase a few people asked for an example. There are many ways to do this, and this for the moment satisfies my needs. Note: It may not satisfy yours.
Modification:
To achieve this I modify knoppix-autoconfig in the source directory of the remaster. By default the hostname is set to "Knoppix" by the command at line 493.
I replace this line with the following (# Heavily commented for the unsure)Code:hostname "Knoppix"
Usage:Code:# If booting live and not from an install if [ -z "$INSTALLED" ] then # Check if the hostname cheatcode was passed at the boot prompt if checkbootparam "hostname" then # Grab the value passed with the "hostname" cheatcode HN="$(getbootparam 'hostname')" # If it was auto if [ "$HN" = "auto" ] then # Generate the hostname as "Knoppix" and append the Mac Address of eth0 HN="Knoppix-$(ifconfig eth0 | grep HWaddr | awk '{print $5}' | sed s/://g)" fi # If no "hostname" cheatcode was supplied then use default "Knoppix" else HN="Knoppix" fi # If running from a HDD install then grab the hostname from the file /etc/hostname else # Get the default hostname from HDD HN="$(cat /etc/hostname)" fi # Update /etc/hostname and /etc/hosts (/etc is writeable live boot, or hdd boot) echo $HN > /etc/hostname sed -i s/^127\.0\.0\.1.*/127\.0\.0\.1\t$HN\ localhost/ /etc/hosts # Set the hostname hostname $HN
If it is not apparent this script will provide some flexability, allowing default, explicit or auto generation of the hostname.
Example of default generation (no "hostname" cheatcode supplied):
Code:boot: knoppixExample of explicit generation ("hostname" cheatcode supplied with arbitrary name)The hostname for this example is "Knoppix"
Code:boot: knoppix hostname=computer_1Example of auto generation ("hostname" cheatcode supplied with "auto" name)The hostname for this example is "computer_1"
Code:boot: knoppix hostname=autoClosing:The hostname for this example is "Knoppix-MACADDRESS"
Please feel free to use and modify this code as you see fit, it can be made more generic, which I will get around to when the need arises. Please let me know if you have any suggestions or improvements.
HP Workstation Z640 2x Xeon E5-2623V4 32GB Ram 2x 256GB SSD Quadro 2000 Linux GA
$249.99
Dell T7810 Workstation 1x E5-2603 v3 16GB RAM Nvidia QUADRO +cables
$120.00
Dell Precision 5810 Workstation Xeon E5-1650 6C 3.5GHz 16GB 500GB Win10 K2200
$115.94
HP Z230 Workstation Towers Xeon E3-1231 V3 3.20ghz 8GB Ram NO HDD
$39.96
SR1XP Intel Xeon E5-2680 v3 12 Core 30MB 2.5GHz LGA 2011-3 Grade A Processor
$3.87
Genuine Intel Xeon E5-2680V4 2.40Ghz 14-Core 35MB LGA2011 CPU P/N: SR2N7
$14.99
Intel Xeon Silver 4214R 12-Core 2.40GHz CPU / SRG1W
$299.99
Intel Xeon E5-2699 v3 2.3GHz 18-Core 45MB 145W LGA2011-3 CPU/Processor SR1XD
$40.99
Intel Xeon Gold 6146 3.2Ghz 12-Core 165W FCLGA3647 CPU/Processor SR3MA
$254.99
Dell Poweredge R730xd LFF 14-Bay 2U Server | Choose Your CPU & RAM Config
$489.99