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
  •  


Dell PowerEdge R630 Server 2x E5-2680 V4 = 28 Cores S130 32GB RAM NEW 480GB SSD picture

Dell PowerEdge R630 Server 2x E5-2680 V4 = 28 Cores S130 32GB RAM NEW 480GB SSD

$197.99



Dell PowerEdge R730 2x E5-2699V3 2.3Ghz 36 Core 128GB RAM H730 X520-I350 2x750W picture

Dell PowerEdge R730 2x E5-2699V3 2.3Ghz 36 Core 128GB RAM H730 X520-I350 2x750W

$329.99



Dell PowerEdge R630 Server 2x E5-2640v3 2.60Ghz 16-Core 64GB H330 picture

Dell PowerEdge R630 Server 2x E5-2640v3 2.60Ghz 16-Core 64GB H330

$182.65



Dell Poweredge R630 Server 2x E5-2620 V4 =16 Cores | S130 | 32GB RAM | 2x trays picture

Dell Poweredge R630 Server 2x E5-2620 V4 =16 Cores | S130 | 32GB RAM | 2x trays

$159.99



Dell PowerEdge R720xd 26HDD 300gb  2.5-inch E5-2697  X 2CPU 384RAM 7.2 Tb HDD  picture

Dell PowerEdge R720xd 26HDD 300gb 2.5-inch E5-2697 X 2CPU 384RAM 7.2 Tb HDD 

$180.00



DELL POWEREDGE R630 8 x 2.5'' 2X E5-2680V4 32GB RAM IDRAC ENT & NDC 2X 495W PSU picture

DELL POWEREDGE R630 8 x 2.5'' 2X E5-2680V4 32GB RAM IDRAC ENT & NDC 2X 495W PSU

$184.95



Dell PowerEdge T620 8-Bay LFF Xeon E5-2660 0 2.20GHz 48GB NO HDD S110 Server picture

Dell PowerEdge T620 8-Bay LFF Xeon E5-2660 0 2.20GHz 48GB NO HDD S110 Server

$174.99



Dell PowerEdge R620 Server - 256GB RAM, 2x8cCPU, 120Gb SSD/3x900Gb SAS, Proxmox picture

Dell PowerEdge R620 Server - 256GB RAM, 2x8cCPU, 120Gb SSD/3x900Gb SAS, Proxmox

$320.00



Dell Poweredge R630 2x Xeon E5-2680 v4 2.4ghz 28-Cores / 128gb / H330 / 2x 1TB picture

Dell Poweredge R630 2x Xeon E5-2680 v4 2.4ghz 28-Cores / 128gb / H330 / 2x 1TB

$334.99



Dell Poweredge R730xd LFF 14-Bay 2U Server | Choose Your CPU & RAM Config picture

Dell Poweredge R730xd LFF 14-Bay 2U Server | Choose Your CPU & RAM Config

$489.99