localhost variables - Mandriva

This is a discussion on localhost variables - Mandriva ; is there a way to set the machine name to a variable?? my dilemma...I use mandriva spring 2007.1 to make a live cd that houses some in house tools, so when the user boot their live cd's I get 30+ ...

+ Reply to Thread
Results 1 to 6 of 6

Thread: localhost variables

  1. localhost variables

    is there a way to set the machine name to a variable??
    my dilemma...I use mandriva spring 2007.1 to make a live cd that houses some
    in house tools, so when the user boot their live cd's I get 30+ machines on
    the network all named "Localhost" and thus none is accessible.

    Any Help is much appreciated,
    --
    scales.removed

  2. Re: localhost variables

    On Wed, 04 Jul 2007 15:05:58 -0600, scales.removed@mandriva.com wrote:
    > is there a way to set the machine name to a variable??


    Sure. try this

    node=$(hostname)
    echo $node

    Now setting hostname from a variable is about as easy,
    hostname $node
    except is not /etc/ write protected on a live cd?

    You also would have to hook your code in during boot, and anytime
    network is restarted.

    Since /etc/sysconfig/network is sourced during boot and network
    restart, I wonder if you could put something like
    source /somewhere/set_hostname
    in /etc/sysconfig/network,
    and /somewhere/set_hostname sets HOSTNAME=what.u.want

    See example:
    $ cat /etc/sysconfig/network
    NETWORKING_IPV6=no
    NOZEROCONF=yes
    GATEWAYDEV=eth0
    GATEWAY=192.168.2.1
    # HOSTNAME=wb.home.invalid
    source /somewhere/set_hostname
    NEEDHOSTNAME=no
    NETWORKING=yes


    > my dilemma...I use mandriva spring 2007.1 to make a live cd that houses some
    > in house tools, so when the user boot their live cd's I get 30+ machines on
    > the network all named "Localhost" and thus none is accessible.
    >
    > Any Help is much appreciated,


    Another possibility is have your DHCP server send out hostname with the lease.
    I have not played with a DHCP server setup.

  3. Re: localhost variables

    scales.removed@mandriva.com wrote:

    > is there a way to set the machine name to a variable??
    > my dilemma...I use mandriva spring 2007.1 to make a live cd that houses
    > some in house tools, so when the user boot their live cd's I get 30+
    > machines on the network all named "Localhost" and thus none is accessible.
    >

    I assume you have a dhcp server handing out IPs. Bind them to the MAC
    addresses of the network cards of your clients, and hand out your dns
    server address via dhcp as well. Since Mandriva fully supports dhcp, your
    liveCDs will be known under the predefined names.
    --
    vista policy violation: Microsoft optical mouse found penguin patterns
    on mousepad. Partition scan in progress to remove offending
    incompatible products. Reactivate MS software.
    Linux 2.6.17mm,Xorg7.2/nvidia [LinuxCounter#295241,ICQ#4918962]

  4. Re: localhost variables


    > scales.removed@mandriva.com wrote:
    >
    >> is there a way to set the machine name to a variable??
    >> my dilemma...I use mandriva spring 2007.1 to make a live cd that houses
    >> some in house tools, so when the user boot their live cd's I get 30+
    >> machines on the network all named "Localhost" and thus none is
    >> accessible.
    >>

    > I assume you have a dhcp server handing out IPs. Bind them to the MAC
    > addresses of the network cards of your clients, and hand out your dns
    > server address via dhcp as well. Since Mandriva fully supports dhcp, your
    > liveCDs will be known under the predefined names.




    I don't have access nor control over the DHCP servers on the network

    I was hoping to find a way that the machine would append the hostname,
    something like part of the mac address or ip address. so I could name the
    original image something like foo%s and it would use the %s to append the
    host name. But when I tried that they all were foo%s no parsing of the
    variable. Or is it possible to have the host name be the ip address?

    Thanks very much for your help!
    --
    scales.removed

  5. Re: localhost variables

    scales.removed@mandriva.com wrote:

    ......
    > I don't have access nor control over the DHCP servers on the network
    >

    Nevertheless, you should receive IP addresses from there, and - if in the
    dynamic range - usually names reflecting the IP, like
    dhcp-172_20_18_15.yourcorporate.domain. The domain part won't make it to
    your livecd bootups, but the names should show different.
    DHCP configures your netmask(s) and the ip of your default gateway and dns
    servers as well. "localhost" exists on every ip networked host, and
    describes just the loopback interface.
    Some dhcp server setups interact with dns servers as well, so these names
    may well be published on the lan, and accessible (ping ....).
    Any time you can reach your hosts by IP address.

    > I was hoping to find a way that the machine would append the hostname,
    > something like part of the mac address or ip address. so I could name the
    > original image something like foo%s and it would use the %s to append the
    > host name. But when I tried that they all were foo%s no parsing of the
    > variable. Or is it possible to have the host name be the ip address?


    Usually dhcp does that, and default live cd bootups should take these names.

    --
    vista policy violation: Microsoft optical mouse found penguin patterns
    on mousepad. Partition scan in progress to remove offending
    incompatible products. Reactivate MS software.
    Linux 2.6.17mm,Xorg7.2/nvidia [LinuxCounter#295241,ICQ#4918962]

  6. Re: localhost variables

    On Thu, 05 Jul 2007 09:34:06 -0600, scales.removed@mandriva.com wrote:
    >
    > I don't have access nor control over the DHCP servers on the network
    >
    > I was hoping to find a way that the machine would append the hostname,
    > something like part of the mac address or ip address. so I could name the
    > original image something like foo%s and it would use the %s to append the
    > host name. But when I tried that they all were foo%s no parsing of the
    > variable. Or is it possible to have the host name be the ip address?
    >
    > Thanks very much for your help!


    Variables in bash are $s not %s unless you are using printf.

    Some light reading found here http://tldp.org/LDP/abs/html/index.html

    Here is a quick kludge, per my earlier suggestion:
    ------------8<-------cut set_hostname below this line -----8<------------8<
    #!/bin/bash
    #**********************************************
    #*
    #* set_hostname - set hostname based on mac
    #*
    #* Called from inside /etc/sysconfig/network
    #*
    #* Example: source /wherever/set_hostname
    #*
    #* HOSTNAME will contain the FQDN upon exit and
    #* /etc/hosts will have 127.0.0.1 FQDN localhost
    #*
    #**********************************************

    _domain="kosh.invalid"

    #************************************
    #* fetch mac addy from dmesg for eth0
    #************************************

    set $(dmesg | grep eth0: | grep IRQ )
    _loc=$(($#-2)) # set mac argument location 3'rd from end
    _mac=${!_loc} # get mac value

    #************************************
    #* pick host based on mac addy
    #************************************
    case $_mac in
    "00:A0:CC:21:B8:91,") _node=doopy ;;
    "00:16:17:57:6a:54,") _node=sleezy ;;
    *) _node=unknown ;;
    esac

    #****************************
    #* set FQDN in /etc/hosts
    #****************************

    grep -v localhost /etc/hosts > /tmp/hosts
    echo -e "127.0.0.1\t$_node.${_domain} $_node localhost" > /etc/hosts
    cat /tmp/hosts >> /etc/hosts
    /bin/rm -f /tmp/hosts

    HOSTNAME=$_node.${_domain}

    #************** end set_hostname *******************

+ Reply to Thread