LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-28-2005, 01:48 PM   #1
onmountain
LQ Newbie
 
Registered: Oct 2005
Distribution: Debian
Posts: 16

Rep: Reputation: 0
How to get just my ip address?


Hi. I want to be able to just get the ip address of my machine, so that I can use this in a script to update some conf files. I currently know enough to use the following:
/sbin/ifconfig -a

This returns tons of info:

eth0 Link encap:Ethernet HWaddr 00:07:95:46:5C:91
inet addr:192.1.2.15 Bcast:192.1.2.255 Mask:255.255.255.0
inet6 addr: fe80::207:95ff:fe46:5c91/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:850388 errors:0 dropped:0 overruns:0 frame:0
TX packets:190366 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:111465391 (106.3 MiB) TX bytes:100919889 (96.2 MiB)
Interrupt:5 Base address:0xd400

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:143896 errors:0 dropped:0 overruns:0 frame:0
TX packets:143896 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:58321203 (55.6 MiB) TX bytes:58321203 (55.6 MiB)

sit0 Link encap:IPv6-in-IPv4
NOARP MTU:1480 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)


I can see my ip address in the line:
inet addr:192.1.2.15 Bcast:192.1.2.255 Mask:255.255.255.0
Is there a command or something that will just spit out something like:
192.1.2.15

Thanks!
 
Old 10-28-2005, 01:56 PM   #2
Moloko
Member
 
Registered: Mar 2004
Location: Netherlands
Distribution: Debian
Posts: 729

Rep: Reputation: 30
/sbin/ifconfig eth0 | awk '/inet/ { print $2 }' | awk -F ":" '{ print $2 }'

(google )
 
Old 10-28-2005, 02:06 PM   #3
Moloko
Member
 
Registered: Mar 2004
Location: Netherlands
Distribution: Debian
Posts: 729

Rep: Reputation: 30
/sbin/ifconfig eth0| grep "inet addr" | tr -s " " | cut -d":" -f2 | cut -d" " -f1

(nicer if you have ipv6 enabled)
 
Old 10-28-2005, 02:31 PM   #4
onmountain
LQ Newbie
 
Registered: Oct 2005
Distribution: Debian
Posts: 16

Original Poster
Rep: Reputation: 0
Thanks - both worked

Thanks. Both methods worked great. I understand the first way better than the second, but it gives me something to learn from. Many thanks!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
dhcp no ip address and netmask dont match route address pengy666 Linux - Wireless Networking 1 05-08-2005 10:33 AM
how to get ip address, broadcast address, mac address of a machine sumeshstar Programming 2 03-12-2005 05:33 AM
DHCP Server MAC Address found, IP address not assigned wmburke Linux - Wireless Networking 17 11-17-2004 11:33 AM
problem to print source address and destination address jooboo Programming 2 11-26-2003 04:24 PM
Should i use the eth0 ip address of my internet ip address when applying iptables ForumKid Linux - Security 2 01-03-2002 09:54 AM


All times are GMT -5. The time now is 08:26 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration