determining the machines local ip address

Rick Stevens rstevens at vitalstream.com
Mon Mar 8 18:58:09 UTC 2004


M.Hockings wrote:
> Rick Stevens wrote:
> 
>> M.Hockings wrote:
>>
>>> Dear Red Hat Linux Guru's at large...
>>>
>>> This is probably more of a Linux question than strictly a RH9 
>>> question but I wasn't able to find a solution by Googlin'...
>>>
>>> What is an easy way to display the local machine's ip address?  Not 
>>> the loopback address (127.0.0.1) and not the external address (I can 
>>> get that with a Web page) but eth0's address on the current LAN.  For 
>>> example at home I'd expect to see something like 192.168.1.x.
>>
>>
>>
>> The easist way is to use "ifconfig eth0" (or, as a regular user,
>> "/sbin/ifconfig eth0") and assuming you're using ethernet rather than
>> a dialup or DSL-over-USB.  In the latter case, you can use "ppp0"
>> rather than "eth0" or simply "ifconfig -a" or "/sbin/ifconfig -a" to
>> list ALL interfaces.
>>
>> If you want to know what your IP is as seen by the rest of the world,
>> try "http://www.rhil.net/whatip.php".  It'll tell you.
>> ----------------------------------------------------------------------
>> - Rick Stevens, Senior Systems Engineer     rstevens at vitalstream.com -
>> - VitalStream, Inc.                       http://www.vitalstream.com -
>> -                                                                    -
>> -                   To err is human, to moo bovine.                  -
>> ----------------------------------------------------------------------
> 
> 
> 
> Thanks Rick, et. al.
> 
> The /sbin/ifconfig eth0 works great!  Now I need to learn a little 
> scripting on Linux to pull out the ip address (or install REXX :-).
> 
> I have a site that could get the external address but in this case that 
> would not help.  We're just tinkering with a way to "find" a  our RH box 
> in a morass of Windows  machines.  All the machines in the site go 
> through some sort of NAT to get to the real world and thus all share the 
> same apparent ip from that point of view.

Try:

     ifconfig eth0 | grep "addr:" | gawk 'BEGIN{FS="[:| ]*"}{print $4;}'

Be careful about the punctuation (don't swap the " and ' marks around).

If you're using DHCP, the data is also contained in the file
"/var/lib/dhcp/dhclient.leases", but it's harder to parse.
----------------------------------------------------------------------
- Rick Stevens, Senior Systems Engineer     rstevens at vitalstream.com -
- VitalStream, Inc.                       http://www.vitalstream.com -
-                                                                    -
-          When all else fails, try reading the instructions.        -
----------------------------------------------------------------------





More information about the Redhat-install-list mailing list