Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am trying to get my locally assigned IP address from Ubuntu 10.04 LTS with ifconfig and what I'm getting is my external IP address (in other words, it's the same IP I see on whatismyip.com)

When running ifconfig eth0, inet addr shows my external IP address instead of the local address.

How do I get my local IP address ?

share|improve this question

4 Answers 4

up vote 6 down vote accepted

If ifconfig eth0 returns an externally routeable IP address, you're almost certainly not behind any NAT. ifconfig has no way to know what any non-NATed IP address would be, it can only report the IP address actually associated with the interface.

Why do you think that the IP address shown is incorrect?

share|improve this answer

ip addr shows you every address your machine has. That includes ipv4, ipv6, mac, link-local and global, avahi…

If you don't see an rfc1918 private address, it means you aren't behind a NAT. Your router is acting like a modem and doesn't have an ip address of its own.

share|improve this answer

You'll have to use a router for it: so the router will have the public ip and your box will have its local ip delivered by DHCP.

Just out of curiosity: why aren't you ok with external ip? Security issues?

share|improve this answer

Try ip route The first or second match with this regex is your local IP:

(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)

If this returns also your external IP, then I think you don't have a router....

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.