7

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 ?

4 Answers 4

7

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?

4

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.

0

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?

0

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....

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .