Results 1 to 10 of 10

Thread: How to Set the Hostname to KNOPPIX-MAC Address (SOLVED)

  1. #1
    Junior Member
    Join Date
    Sep 2007
    Location
    Baton Rouge, Louisiana
    Posts
    9

    How to Set the Hostname to KNOPPIX-MAC Address (SOLVED)

    Brief background - I am remastering a KNOPPIX 5.1.1 CD for Disaster recovery. We have 200 users, and in the event of a hurricane, I want to be able to grab our old bareboned PC's out of storage, set them up in a temporary office, pop in the KNOPPIX CD and have them automaticall boot up, grab an IP, and connect via Ctrix client to out storage center.

    KNOPPIX is able to do all of that. It's a wonderful product, although I admit it took this Windows guy a bit of getting used to).

    Problem - When I boot two PC's with my remastered KNOPPIX CD, everything works beatufully. Except one thing. Both PC's show the same hostname in the DNS server. Both are named KNOPPIX. I need these PC's to have unigue names. My initial thought is to append the MAC address to the hostname KNOPPIX. For example KNOPPIX-00B2C56488. But I can't figure out how to edit the KNOPPIX image accordingly.

    I can find the hostname file that contains only the text KNOPPIX, and the hostname.sh that seems to call teh hostname file to gain the hostname. I just can't fingure out how to make it pull the MAC address and append it to the hostname KNOPPIX.

    Any help would be greatly appreciated! And please remeber, I'm a beginner...and this is my first time playing with any Linux based OS.

    Thank you,

    Brandon

  2. #2
    Junior Member
    Join Date
    Sep 2007
    Location
    Baton Rouge, Louisiana
    Posts
    9
    okay a quick update. I have figured out from reading for hours on hours that in a root shell, the command:

    ifconfig eth0 | grep HWaddr | awk '{print $5}' | sed s/://g

    will return my MAC address removing the colons. This would work perfetly. So I edited the hostname.sh to read:

    [ -f /etc/hostname ] && HOSTNAME="$(ifconfig eth0 | grep HWaddr | awk '{print $5}' | sed s/://g)"

    and when I execute that script, I get the error awk command not found. What am I missing. If I remove everything after the grep HWaddr, it works fine, it just returns: eth0 Link encap:ethernet 00:B0:45:09:C1:B2.

    SOMEONE PLEASE HELP. I can't afford to lose the hair I have left...

    Brandon

  3. #3
    Junior Member
    Join Date
    Sep 2007
    Location
    Baton Rouge, Louisiana
    Posts
    9

    Partially fixed. Creating ISO to test

    I had to open the knoppix-autoconfig located in /etc/init.d and replace line 493 which reads:

    hostname=knoppix

    with the following:

    HN="Knoppix-$(ifconfig eth0 | grep HWaddr | awk '{print $5}' | sed s/://g)"
    echo $HN > /etc/hostname
    sed -i s/^127\.0\.0\.1.*/127\.0\.0\.1\t$HN\ localhost/ /etc/hosts

    hostname $HN

    I'll let you know if it works...

  4. #4
    Member registered user
    Join Date
    Dec 2006
    Posts
    44
    Be aware that the environment variable PATH will change during boot, as it goes through the boot up scripts. That is probably why your script didn't find awk. You may have more luck if you write the full path to awk in the script.

  5. #5
    Junior Member
    Join Date
    Sep 2007
    Location
    Baton Rouge, Louisiana
    Posts
    9
    You may be right, after editing the knoppix-autoconfig to read:

    HN="Knoppix-$(ifconfig eth0 | grep HWaddr | awk '{print $5}' | sed s/://g)"
    echo $HN > /etc/hostname
    sed -i s/^127\.0\.0\.1.*/127\.0\.0\.1\t$HN\ localhost/ /etc/hosts

    hostname $HN

    I now get eth hostname "knoppix-"

    So apparently it's reading the file, but not pulling hte MAC address. Either knoppix doesn't know the MAC address at the time when the knoppix-autoconfig script runs, or you're connrect and the script isn't running properly due to the path. What is the proper path to AWK? /usr/lib/awk? Is that what I need in that script to get it to work?

    Thanks for your reply. I need all the help I can get...

  6. #6
    Member registered user
    Join Date
    Dec 2006
    Posts
    44
    $ type grep
    grep is /bin/grep

    $ type awk
    awk is /usr/bin/awk

    The PATH is set in /etc/profile or /etc/bashrc that were run when you opened the command shell. That PATH is probably different from the active PATH during boot. When you run the script from the command line, you may be fooled by that. It seems that /bin is in the PATH during boot (the script finds grep) , but /usr/bin is not (awk not found).

    Try to put the entire output from ifconfig into a file. That should show if the MAC address is known at the time or not.

  7. #7
    Junior Member
    Join Date
    Sep 2007
    Location
    Baton Rouge, Louisiana
    Posts
    9

    need a new script at bootup

    okat, editing the knoppix-auto-config seems to work. It properly renames the PC hostname. However, knoppix is apprently sending its information to the DHCP server prior to it being renamed. I have figured out that the following command will request a new DHCP lease from the server and correct the problem:

    sudo ifdown eth0 && sudo ifup eth0

    however, that line won't work if inserted in the knoppix-auto-config. So I wrote a new file namde sudo.sh that contains only the above command followed by exit. Can anyone tell me where I need to place this command to have it run just before the OS finishes loading?

    Thank you,

    Brandon

  8. #8
    Junior Member
    Join Date
    Sep 2007
    Location
    Baton Rouge, Louisiana
    Posts
    9

    Solved

    Problem solved. Here's a recap of what I did to resolve the problem.

    Edited the knoppix-autoconfig by deleting the following line at line 490:

    hostname knoppix

    Then inserted the following lines much later in the script. at lines 1215 to be exact:

    HN="Knoppix-$(ifconfig eth0 | grep HWaddr | awk '{print $5}' | sed s/://g)"
    echo $HN > /etc/hostname
    sed -i s/^127\.0\.0\.1.*/127\.0\.0\.1\t$HN\ localhost/ /etc/hosts
    hostname $HN

    finally I had to request a new lease since the KNOPPIX OS had already received it's DHCP lease, and DHCPC has already received the KNOPPIX hostname of (none).domain.com. And just in case you're wondering why I didn't put the above text prior to the knoppix OS requesting a DHCP lease...it seems that until knoppix requests the lease from the DHCP server, it is unaware it has a network card or a MAC addresss. Trust me I tried putting thost hostname commands everywhere in that damn script.

    Now I needed a new lease from DHCP only in order to send my new hostname up to it. Therefore, I opened the knoppix.sh file and added a line 11 to read:

    sudo ifdown eth0 && sudo ifup eth0

    I'm sure there's a better way to do this, but after wasting 12 CD's this was the best I could do. For some reason the sudo command would return an error if placed in the knoppix-autoconfig file. I tried to create my own shell script and place it in the Autostart directory (failed), the rc5.d directory (Failed), as well as the init.d directory (failed). So I tried to add it to a couple scripts, and this is the one that worked. Good luck to anyone needing this information.

    Thank you all,

    Brandon

  9. #9
    Member registered user
    Join Date
    Jun 2004
    Posts
    89
    If you really wasted 12 CDs, then you should use QEMU, kvm, VMware, Virtualbox, Xen or some other virtualization platform to test your CD images. It's really easy and saves you a lot of time burning images. It's even more convenient than using rewritable CDs.

    Thanks for your write-up of this.

  10. #10
    Administrator Site Admin-
    Join Date
    Apr 2003
    Location
    USA
    Posts
    5,441
    Quote Originally Posted by mcreel
    If you really wasted 12 CDs, then you should use QEMU, kvm, VMware, Virtualbox, Xen or some other virtualization platform to test your CD images. ....
    VMWare is really nice, but a simple approach to this issue is a CDRW.

Similar Threads

  1. hostname by dhcp (PARTIALLY SOLVED)
    By bvsantos in forum Customising & Remastering
    Replies: 1
    Last Post: 10-22-2007, 05:18 PM
  2. hostname, domainname, /home/knoppix
    By burnst001@hawaii.rr.com in forum Hdd Install / Debian / Apt
    Replies: 0
    Last Post: 06-01-2006, 08:12 PM
  3. Help! Knoppix 4.0.2 CD upon bootup, changed my Hostname
    By Terry Kemmerer in forum Networking
    Replies: 6
    Last Post: 02-21-2006, 07:19 AM
  4. Knoppix changed my HOSTNAME env var?
    By kclawson in forum General Support
    Replies: 1
    Last Post: 12-03-2003, 02:18 AM
  5. Replies: 4
    Last Post: 06-03-2003, 11:58 PM

Posting Permissions

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


Fanxiang SSD 4TB 2TB 1TB PS5 SSD M.2 NVME SSD 7300MBS PCIe 4.0 Solid State Drive picture

Fanxiang SSD 4TB 2TB 1TB PS5 SSD M.2 NVME SSD 7300MBS PCIe 4.0 Solid State Drive

$269.99



Kingshark M.2 2242 2280 SSD 128GB 256GB 512GB 1TB Internal Solid State Drive Lot picture

Kingshark M.2 2242 2280 SSD 128GB 256GB 512GB 1TB Internal Solid State Drive Lot

$179.99



Fanxiang 4TB 2TB 1TB SSD 550MB/s 2.5'' SATA III Internal Solid State Drive lot picture

Fanxiang 4TB 2TB 1TB SSD 550MB/s 2.5'' SATA III Internal Solid State Drive lot

$219.99



Netac 1TB 2TB 512GB Internal SSD 2.5'' SATA III 6Gb/s Solid State Drive lot picture

Netac 1TB 2TB 512GB Internal SSD 2.5'' SATA III 6Gb/s Solid State Drive lot

$119.99



Patriot P210 128GB 256GB 512GB 1TB 2TB 2.5

Patriot P210 128GB 256GB 512GB 1TB 2TB 2.5" SATA 3 6GB/s Internal SSD PC/MAC Lot

$19.99



Patriot P300 128G 256GB 512GB 1TB 2TB M.2 2280 PCIe Gen3x4 NVMe Internal SSD Lot picture

Patriot P300 128G 256GB 512GB 1TB 2TB M.2 2280 PCIe Gen3x4 NVMe Internal SSD Lot

$16.99



Crucial MX500 CT250MX500SSD1 250 GB SATA III 2.5 in Solid State Drive picture

Crucial MX500 CT250MX500SSD1 250 GB SATA III 2.5 in Solid State Drive

$14.99



WD BLUE 3D NAND 250GB 2.5

WD BLUE 3D NAND 250GB 2.5" SATA Laptop SSD Solid State Tested,Wiped -WDS250G2B0A

$16.00



Fanxiang M.2 SATA SSD 2TB 1TB 512GB 256GB SSD Internal M2 Solid State Drive Lot picture

Fanxiang M.2 SATA SSD 2TB 1TB 512GB 256GB SSD Internal M2 Solid State Drive Lot

$109.99



SAMSUNG 2.5 in SSD 870 EVO 2TB 1TB 500 GB 250 GB SATA III Solid State Drive lot picture

SAMSUNG 2.5 in SSD 870 EVO 2TB 1TB 500 GB 250 GB SATA III Solid State Drive lot

$149.13