To: "For users of Fedora Core releases" <fedora-list@xxxxxxxxxx>
Sent: Wednesday, February 16, 2005 10:38 AM
Subject: Re: IP address variable
On Wed, 16 Feb 2005 09:36:47 -0600, Thomas Cameron <thomas.cameron@xxxxxxxxxxxxxxx> wrote:----- Original Message ----- From: "Mike Burger" <mburger@xxxxxxxxxxxxxxxxx> To: <fedora-list@xxxxxxxxxx> Sent: Wednesday, February 16, 2005 6:50 AM Subject: re: IP address variable
> On Mon, Feb 14, Dave wrote: > >> > Hello All, >> > >> > I need to create a variable (or read an existing one) that returns >> > the >> >IP >> > address for eth0. >> > I used to do it like this under RH 7.2: >> > >> > IPADDR='ifconfig eth0|grep inet|cut -d ":" -f2|cut -d " " -f1' >> > >> > The result now under FC3 is: >> > >> > # $IPADDR >> > "inet|cut: Unknown host" >> > >> > Can anyone help me out here? I am having a hard time figuring this >> > one >>out. >> >>It's falling over the fact that the grep matches 2 lines (ipv4 and >>ipv6). >>grep for "inet addr" and it works fine. > > Actually, chances are pretty good that it's tripping over the use of > straight quotes (') instead of angled ones (`). > > Paul...replace the ' at the beginning and end of your variable > declaration with `, and it should work properly.
Why not just use hostname -i?
This would help me out too, so I tried this. I get 127.0.0.1 :-). How can I fix that so that command gives me the address I actually want? man hostname doesn't help me. Thanks.
Hrm. OK, here's what I would do if I were you.
1) Turn off ipv6 unless you are using it. Add the following two lines to /etc/modprobe.conf:
alias net-pf-10 off alias ipv6 off
2) Make sure that your hostname is set correctly in /etc/sysconfig/network. It should look something like this:
NETWORKING=yes HOSTNAME=myhost.camerontech.com
Change "myhost.camerontech.com" to your machine's name
3) Make sure that your /etc/hosts file is set up like this:
# Do not remove the following line, or various programs # that require network functionality will fail. 127.0.0.1 localhost.localdomain localhost 300.300.300.300 myhost.camerontech.com myhost
Obviously, change the ip address and hostname to match your machine.
4) Reboot so that ipv6 is not loaded and your hostname is set correctly.
5) Run hostname -i and see if it works.
Please report back your results?
An alternative version of your script could look like this:
/sbin/ifconfig | grep inet | grep -v 127.0.0.1 | awk '{ print $2 }' | awk -F: '{ print $2 }'
Thomas