[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: IP address question
From: |
Systems Administrator |
Subject: |
Re: IP address question |
Date: |
Thu, 2 Oct 2003 09:17:42 +1000 (EST) |
On Wed, 1 Oct 2003, Chip Seraphine wrote:
> The installers in some Unix variants (especially some Linux distros with
> 'friendly' installers) actually put the hostname on the 127.0.0.1 line
> in /etc/hosts. This is totally wrong for a networked machine! If your
> box has so much as a modem, 127.0.0.1 should be "localhost
> localhost.localdomain" and the like (some people also use "loopback" and
> whatever.)
>
> Checking the hosts file in newly built Linux boxen can save you from
> many annoying and subtle errors like the one you describe.
Mark responded similarly, and what I sent him said:
-----
Well, the basic problem is that, while I've defined the IP
address, Redhat has the hostname configured to be localhost.localdomain
(presumably because I didn't install all the packages it likes :) ). So
what I want to do is get that other IP address, use DNS to look up the
hostname, and configure that in. This is for a new machine setup. As
practise, I'm using a special class (invoked with cfengine -Dsetup on new
machines) which sets up new machines the way they need to be. But in the
end, it was complaining about the Perl Regex that I put in the ExecResult,
(see below), so I just put that bit on the end of the Kickstart file.
-----
Richard Dennis wrote:
> #!/bin/sh
> #
> # Module:getLocalIP
>
> IPADDR=`/sbin/ifconfig eth0 | awk '/inet addr/{print $2}' | sed 's/addr://'`
> echo "=MyIP="$IPADDR
Similar to what I did:
REALIP=`ifconfig | grep inet | head -1 | perl -pe
's/^.*?(\d+\.\d+\.\d+\.\d+).*/$1/'`
REALHOST=`host $REALIP | /usr/bin/awk '{print $NF}'`
echo HOSTNAME=$REALHOST >> /etc/sysconfig/network
Thanks :). I like the eth0 thing, and will replace the "head"
statement with that. And I like the search in awk -- I'll use something
similar:
ifconfig eth0 | perl -ne 'if(/inet/){s/^.*?(\d+\.\d+\.\d+\.\d+).*/$1/;print}'
Thanks all :).
--
Tim Nelson
Systems Administrator
Sunet Internet
Tel: +61 3 5241 1155
Fax: +61 3 5241 6187
Web: http://www.sunet.com.au/
Email: sysadmin@sunet.com.au