'ifconfig' to skip loopback IPs


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users 'ifconfig' to skip loopback IPs
# 1  
Old 03-15-2010
Bug 'ifconfig' to skip loopback IPs

I generally use
Code:
/usr/sbin/ifconfig -a | grep "inet" |egrep -v "inet6|0.0.0.0|192.168.100.2"|awk '{print $2}'

to capture IPs on a host.

Now here is what i have:

Code:
bash-2.05$  /usr/sbin/ifconfig -a
lo0: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
        inet <IP> netmask ff000000
lo0:1: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
        inet <IP> netmask ff000000
lo0:2: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
        inet <IP> netmask fffffff8
lo0:3: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
        inet <IP> netmask fffffff8
lo0:4: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
        inet <IP> netmask fffffff8
lo0:5: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
        inet <IP> netmask fffffff8
lo0:6: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
        inet <IP> netmask fffffff8
lo0:7: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
        inet <IP> netmask fffffff8
lo0:8: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
        inet <IP> netmask fffffff8
ce0: flags=9040843<UP,BROADCAST,RUNNING,MULTICAST,DEPRECATED,IPv4,NOFAILOVER> mtu 1500 index 2
        inet <IP> netmask ffffff80 broadcast <BROADCAST>
        groupname ipmp
ce0:1: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 2
        inet <IP> netmask ffffff80 broadcast <BROADCAST>
ce1: flags=9040843<UP,BROADCAST,RUNNING,MULTICAST,DEPRECATED,IPv4,NOFAILOVER> mtu 1500 index 3
        inet <IP> netmask ffffff80 broadcast <BROADCAST>
        groupname ipmp
ce1:1: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 3
        inet <IP> netmask ffffff80 broadcast <BROADCAST>
ce5: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 4
        inet <IP> netmask fffffc00 broadcast <BROADCAST>

As you can see,i have multiple loopbacks configured.I wish not to capture these IP addresses.I just want it to capture IP address which are not loopback i.e in above example..IPs for 'ceo'...etc...

Kindly advice

Abhi

Last edited by ak835; 03-19-2010 at 10:24 AM.. Reason: code tags, please...
# 2  
Old 03-15-2010
What kind of system is this? On linux, you may be able to avoid it outputting the unwanted network devices entirely:
Code:
ls /sys/class/net | egrep -v "^(lo[0-9]?|sit[0-9]|ce[0-9]?)$" | xargs --max-args=1 /sbin/ifconfig

# 3  
Old 03-16-2010
Bug

I need a command or a small script for all three platforms : AIX,Solaris and Linux.

Abhi
# 4  
Old 03-18-2010
just add
Code:
grep -v '^lo'

# 5  
Old 03-19-2010
Bug

Code:
grep -v '^lo'

this will just chop off first line....

it will still display second line where IP is present.

Look at this:

Code:
bash-3.00$  /usr/sbin/ifconfig -a
lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
        inet 127.0.0.1 netmask ff000000

Line in BOLD will still remain

Regards
Abhi
# 6  
Old 03-19-2010
AK835, I realized that later on.. thanks.
# 7  
Old 03-19-2010
Here is what I use under Solaris, it skips interfaces used by zones too:
Code:
ifconfig -a4 | nawk '
  BEGIN { ignore=0 }
  /^lo/ { ignore=1 }
  /zone/ { ignore=1 }
  /inet/ { if((ignore==0) && ($2!="0.0.0.0")) print $2 ; ignore=0}
  '

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Red Hat

NAT Loopback and iptables

Hello, please can you help and explain me. I have two servers. Both are RHEL6. I use the first one like router and the second one for apache. Router forwards 80 port on the second server and I can open that from the internet (mysite.com, for example). But I can not open mysite.com if i try to... (0 Replies)
Discussion started by: 6765656755
0 Replies

2. UNIX Desktop Questions & Answers

Loopback

clear echo "vans, Rolland" echo "Press in Your Keyboard to Quit" echo -e "Please Enter Your Choice : \c" read option case $option in I have created the corresponding information for each input on the display so... My question is... How do I display the corresponding information... (6 Replies)
Discussion started by: thriveforana
6 Replies

3. UNIX for Dummies Questions & Answers

How to Loopback?

This is in the beginning of the program: clear tput cup 1 20 echo "Welcome to UNIX I Final Assignment" tput cup 4 3 echo -e "Who would you like to look up? \c" tput cup 6 5 echo "vans, Rolland" tput cup 8 5 echo "ones, Mildred" tput cup 10 5 echo "mith, Julie" tput cup 12 5 echo... (0 Replies)
Discussion started by: thriveforana
0 Replies

4. Linux

Loopback interface doen't appear

Hi all, i have a problem with (Network in Linux) .. my issue with a HW appliance has openfiler 2.3 and is used for File Sharing using samba .. the problem is when i try to list all configured network interfaces using ifconfig -a .. i can't see the loopback interface, Although the file... (3 Replies)
Discussion started by: mabdelmageid
3 Replies

5. Solaris

Adding Loopback Interface

Hello, I have a SunOS (5.5.1) system that I need to migrate to a new IP address. I would like to have any requests destined for the old IP to be forwarded to this server. One suggestion I had was to add a route on my router that would point the old IP to the new IP. How do I add another... (2 Replies)
Discussion started by: reiklen
2 Replies

6. Filesystems, Disks and Memory

Can a Loopback Filesystem be Partitioned?

I have a disk image file created for use with the Linux version of the QEMU emulator. It's partitioned. I opened it with fdisk and the partitions show up with some extra messages about physical/logical endings: Disk knoppix.img: 0 MB, 0 bytes 16 heads, 63 sectors/track, 0 cylinders Units =... (3 Replies)
Discussion started by: deckard
3 Replies

7. AIX

loopback in 4.1.4.0 AIX server

Hi: I´ve a problem in a 4.1.4.0 AIX server because is generating a loopback in its own ip address and this are consuming all the bandwidth. I did many things trying to solve the problem but it doesn´t help. 1. Flush Routing tables 2. Get Up/Down Network interface 3. Add/remove Network... (0 Replies)
Discussion started by: terron79
0 Replies

8. Filesystems, Disks and Memory

Can I Use Loopback Devices with LVM?

I've got a RedHat 9 box with LVM support in a 2.4.22 kernel. What I would like to do is take a set of empty files created with 'dd' and concatenate them into a volume group. I've done a good deal of googling, and it seems that this is something that can be done. But when I try to use 'pvcreate'... (3 Replies)
Discussion started by: deckard
3 Replies

9. Filesystems, Disks and Memory

Using loopback devices in RAID?

Hopefully I am posting this silly question in the right place... I was wondering about the possibility of using loopback files on a physical disk to create virtual disks that could shrink or grow as needed. Something like RAID 0, but instead of using block devices, just using files. If I need... (0 Replies)
Discussion started by: deckard
0 Replies

10. UNIX for Advanced & Expert Users

Loopback Interface...Vanished???

Recently I noticed that my internet connection would not work correctly-although connected domain names could not be resolved. My resolv.conf file was fine since it is configured every time I dial up. a closer inspection showed that my loopback interface had disappearerd! Any ideas why would this... (1 Reply)
Discussion started by: silvaman
1 Replies
Login or Register to Ask a Question