?
Solved

Listing all IPs on a server

Posted on 2007-07-19
14
Medium Priority
?
823 Views
Last Modified: 2013-12-23
Hi,

My application is able to bind to IP addresses. How do I find out all IP addresses on the server (to possibly bind on) ?

Sometimes the command "/sbin/ifconfig -a" will do, but sometimes that won't even return the main IP address. Anyone any ideas ? Thanx!
0
Comment
Question by:TonyJix
14 Comments
 
LVL 7

Expert Comment

by:rugdog
ID: 19526472
what do you mean by "sometimes"? ifconfig always returns the all the IPs configured on the machine.
0
 
LVL 30

Expert Comment

by:Kerem ERSOY
ID: 19526479
In fact the primary command to use is "ifconfig" on linux systems it does the same thing with ifconfig -a.
If it is not returning any ip then probably you are having a physical disconnection and your IP address is dynamic.
0
 
LVL 7

Accepted Solution

by:
ezaton earned 1000 total points
ID: 19526590
Actually, in Linux nowadays, ifconfig is on its way to become deprecated. You can see how it cannot be used to determine the shared IP address of RedHat cluster, for example.

The safest command to run is 'ip addr'. This will allow you to see all IPs defined for the computer, including ones hidden to ifconfig.

Using 'ip route' you can view the default (primary) interface, and derive the IP assigned to it, by combining the class in which it exists, and the network interface device.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 30

Assisted Solution

by:Kerem ERSOY
Kerem ERSOY earned 1000 total points
ID: 19526633
ezaton:
> Actually, in Linux nowadays, ifconfig is on its way to become deprecated

Though it is not a new command it is not normal that it does not show anything and it indicates there's some problem..
0
 
LVL 7

Expert Comment

by:ezaton
ID: 19526696
It is not a new command. This is perfectly normal for it to happen, as the IPs are being assigned using the 'ip' command, and not using ifconfig's virtual interface (ethX:#).
Check this link:
http://kbase.redhat.com/faq/FAQ_51_7212.shtm
0
 
LVL 30

Expert Comment

by:Kerem ERSOY
ID: 19526735
ok this is from the text you've sent the link:

> IP aliases cannot be viewed using the ifconfig command. The ip command can show all the addresses > an interface has, so run the command on the cluster node that is delivering the service.

It is telling about "IPALIASES" which are common in a clusted environment while it has no use in a standard desktop PC. Please try to focus on the question.  
0
 
LVL 7

Expert Comment

by:ezaton
ID: 19527014
I have focused on the question, of course: "How do I find out all IP addresses on the server?"
This is not (and should not be considered) a "standard desktop PC".

Aliased IPs are part of the IPs a server might have, and, actually, might use. Aliased IPs are quite similar to the virtual device, but I wonder if they have the same limitations regarding the max number of virtual IPs.

Also, since 'ip addr' does show all IPs the server has, including the old-style virtual interfaces, I don't see why my answer is not focused or less accurate, comparing to your answer.

Using 'ip addr' you can view ALL the IPs assigned to a server (or workstation, or desktop, or mobile device, or whatever), and iputils are the future.
0
 
LVL 30

Expert Comment

by:Kerem ERSOY
ID: 19527315
Ok lets put it this way:
ip is an optional command that comes from an optional package called iproute. User has an option *not* to install ip at all. So we can not say that every linux comes with ip by default whereas ipconfig comes with every standart Unix and universal.

The original question specifies that ipconfig -a "returns nothing" and it has nothing to do with "ipconfig being obsolete" or not. so if the user has ip on his / her system he can check with ip command too. But if a system does not show anything with ipconfig the problem goes beyond how to display an interface. So please be more specific when you are suggesting something. The IP command is not areplaceement of iproute anyway furthermore the question is probly a failing hardware / dreiver etc. Please leave this discussion alone and concentrate on the user's question. Your suggestion does not help him at all.
I prefer to concentrate on the porblem isntead of looking alternative ways of displaying an IP address. Please stop trying to convince me into ip is the only solution which will display the IP address ofa system.
0
 
LVL 30

Expert Comment

by:Kerem ERSOY
ID: 19527354
Furthermore what you say is wrong! iproute does show any alias ip that an interface has. What it does not show is any IP alias defined via ip. Since in the original problem as the asker specifies does not involve "Clustering" and any "aliases" defined over IP.
- ip is an optianal command.
- iproute is not obsolete and universal
- iproute does show ip aliases (unles they are defined by ip in a clustering environment)
- There's no any evidence in the original question that the user uses a clustered environment created on iproute package.
What you write here is just an optional method to display IP but nothing else. All your allegations are inacurate. Please be careful what you wirte here pepole might take them serious
0
 
LVL 7

Expert Comment

by:ezaton
ID: 19527359
It's ifconfig and not ipconfig. I agree that when your /sbin/ifconfig -a will show nothing, it has a simple meaning that none of your physical network interfaces are available. It usually means that either no module was loaded, or that (more likely) the network service was not turned on.

Also, I would claim that 'ip addr' as said before, would show nothing as well. I have not seen any recent linux without the command 'ip' lately, and if it will make you happy, I will check it every time I have the pleasure of dealing with any distro of Linux.

About ifconfig for other *nix systems - /sbin/ifconfig, or /usr/sbin/ifconfig -a, if we're more into it, will work only on some flavors of *nix, such as Solaris and *bsd. It will not work on HP-UX, where you need to state the name of the network device (ifconfig lan0, for example), or for AIX, where you need to view it using 'netstat -i'.

That said, two corrections:
1. Not all *nix use ifconfig as you suggested it, and Solaris is far from being all *nix.
2. ifconfig -a has a different output comparing to without the '-a' flag - the -a will show all interfaces, including interfaces in 'down' state, while ifconfig without the flag will show all interfaces which are 'up'.
0
 
LVL 7

Expert Comment

by:ezaton
ID: 19527425
All my claims are accurate. I'm sorry you don't see it that way, but we might disagree. It's part of life. I can prove it, of course, however, you can go through these same examples I can.

iproute tools (aka, 'ip') will show:
- Real IP addresses, attached to the physical interfaces
- Virtual interfaces with IPs, such as eth0:0, with their IPs, shown as aliases.
- Aliased IPs, which are used for RHCS, but not only (you took my RHCS example literally. This is not the only case)

iproute is not obsolete, as I have mentioned, while net-tools, of which you can find the command 'ifconfig' are about to become obsolete. Not today, not tomorrow, but they will become such.

You attempt to discredit this answer, while it is perfectly accurate.
I can assume this is part of the game, but the facts talk for themselves. The command 'ip' will be part of every and any modern Linux distro.

And, unlike you, I have also answered the original question - when network interfaces do not appear with using '/sbin/ifconfig -a' it means, nine out of ten times, that the network service is off. Else you would at least se the interface 'lo' with the IP 127.0.0.1.
If you see 'lo' but nothing else, it can mean that your network cards are not configured, or not working.

And back to the original question - to view all the interfaces on a system, use /sbin/ifconfig -a. To view all the active interfaces, use /sbin/ifconfig. To view all IPs attached to all interfaces, with all the possible aliasing methods, use the command 'ip addr'.

Good luck. I have nothing further to add.
0
 
LVL 30

Expert Comment

by:Kerem ERSOY
ID: 19527464
Thank you for correcting my typo about ipconfig they should read ifconfig. But as I am a certified AIX system admin I am happily using ifconfig to display interface info and HP-UX too.

I am happy to hear that we're on the same page again after all these red herrings.  I think we can both focus on the user's problem.

0
 
LVL 7

Expert Comment

by:ezaton
ID: 19527493
I don't like fish :-)
I respect your AIX certification. I am a certified RHCE, so it makes us sort of even on this certification subject :-)

0
 

Author Comment

by:TonyJix
ID: 19569316
Thank you all for the commands... What I have seen is that on some server ifconfig doesn't show all IPs...
Maybe it's a securiy thing or whatever.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is in regards to the Cisco QSFP-4SFP10G-CU1M cables, which are designed to uplink/downlink 40GB ports to 10GB SFP ports. I recently experienced this and found very little configuration documentation on how these are supposed to be confi…
How to fix a SonicWall Gateway Anti-Virus firewall blocking automatic updates to apps like Windows, Adobe, Symantec, etc.
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses
Course of the Month14 days, 17 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question