Link to home
Start Free TrialLog in
Avatar of TonyJix
TonyJix

asked on

Listing all IPs on a server

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!
Avatar of rugdog
rugdog
Flag of Mexico image

what do you mean by "sometimes"? ifconfig always returns the all the IPs configured on the machine.
Avatar of Kerem ERSOY
Kerem ERSOY

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.
ASKER CERTIFIED SOLUTION
Avatar of ezaton
ezaton

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
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.  
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.
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.
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
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'.
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.
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.

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 :-)

Avatar of TonyJix

ASKER

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.