[olug] Unix Tip: GET YOUR IP-ADDRESS

David Walker linux_user at grax.com
Sun Mar 23 00:04:02 UTC 2003


I wouldn't mind seeing shorter versions of these commands but I had fun 
looking into these.
I find the "ip" command to be a rather cool and powerful command.

All IP addresses
Human
ip -f inet -o addr show 
Machine
ip -f inet -o addr show |awk {'print $4'}| awk -F '/' {'print $1'}

All IP addresses for eth0
Human
ip -f inet -o addr show dev eth0
Machine
ip -f inet -o addr show dev eth0 | awk {'print $4'}| awk -F '/' {'print $1'}

What will my IP address be if I try to send packets to IP address 
xxx.xxx.xxx.xxx?
ip -o route get xxx.xxx.xxx.xxx

ip -o route get xxx.xxx.xxx.xxx | awk -F "src " {'print $2'} | \
awk {'print $1'}

What is my default IP address?  (The one used if using the default route)

ip -o route get `ip -o route get \`ip route show | grep "default via" | \
head -1 | awk {'print $3'}\` | awk {'print $5'}` |  \
awk -F "src " {'print $2'} | awk {'print $1'}


On Saturday 22 March 2003 03:52 pm, Eric Penne wrote:
> What is the new way of doing things?
>
> I haven't heard about this netlink thing.
>
> Eric
>
> > On Thu, 20 Mar 2003, David Walker wrote:
> >> The beauty of it is that it is possible.
> >>
> >> Every decent operating system has guru support.
> >>
> >> If a user wished to know their IP address they can simply type
> >> ifconfig
> >
> > SIGH... And here I thought this was a Linux list... ;-}
> >
> > BTW - ifconfig has been deprecated as a kernal IPvx interface since
> > kernel 2.3.7 back in 1998 or so.
> >
> > Even Redhat is now using the netlink interfaces (ip and cousins)
> >
> > Oh - and one other bit of trivia - CIDR is standard with dotted
> > decimal netmasks deprecated since 2.3.7 along with those stupid
> > colonic virtual interfaces (ie: eth0:0 etc)
> >
> > Funny thing since RH has both DM and AC on staff that it took them so
> > long to switch. Eh - I'll go back into lurk mode now...
> >
> >> On Thursday 20 March 2003 01:43 pm, William E. Kempf wrote:
> >> > Unix Guru Universe said:
> >> > > Type this simple command at the unix-prompt
> >> > >
> >> > > ifconfig | grep "inet addr" |  grep -v "127.0.0.1" | awk '{print
> >>
> >> $2;}' |
> >>
> >> > >  awk -F':' '{print $2;}'
> >> >
> >> > *chuckles*
> >> >
> >> > While as a developer I love the power behind these "little tools
> >>
> >> piped together", it's exactly this sort of attitude ("Type this
> >> _simple_ command", emphasis mine) which continues to lead me to think
> >> Linux is for the Gurus, and not Mom and Pop.
> >>
> >> _______________________________________________
> >> OLUG mailing list
> >> OLUG at olug.org
> >> http://lists.olug.org/mailman/listinfo/olug
> >
> > --------------------------------------------------
> > Matthew G. Marsh,  President
> > Paktronix Systems LLC
> > 1506 North 59th Street
> > Omaha  NE  68104
> > Phone: (402) 553-2288
> > Email: mgm at midwestlinux.com
> > WWW:  http://www.midwestlinux.com
> > --------------------------------------------------
> > _______________________________________________
> > OLUG mailing list
> > OLUG at olug.org
> > http://lists.olug.org/mailman/listinfo/olug
>
> _______________________________________________
> OLUG mailing list
> OLUG at olug.org
> http://lists.olug.org/mailman/listinfo/olug



More information about the OLUG mailing list