How do I find my internal ip address?
hostname -I
This will give you just ip address without any extra information.
These commands will tell you all network info
ip add
or
ifconfig -a
If as you say it only gives you 127.0.0.1 then there are two options:
Your network card is not attached or not recognized by the system
Your network DHCP server is not runnning or not connected
This is what I currently recommend:
ip route get 8.8.8.8 | awk '{print $NF; exit}'
The advantage of that command is that you don't have to know which interface you are using (eth0? eth1? or maybe wlan0?), you don't have to filter out localhost addresses, or Docker addresses, or VPN tunnels etc. and you will always get the IP address that is currently used for Internet connections at that very moment (important when e.g. you are connected with both ethernet and wifi or via VPN etc.).
This will test not only that you have a correct IP configured on some interface (like with parsing the output of ifconfig
) but also that you have the routing table configured to use it correctly.
I found that idea in this answer by Collin Anderson.
I use it in the internalip script in my scripts collection on GitHub, which you can install with:
wget https://rawgit.com/rsp/scripts/master/internalip
chmod a+x internalip
and use as:
internalip
or:
internalip TARGET
and you will get your IP address that would be used to connect with the TARGET IP address. The default target is 8.8.8.8
which is the Google's public DNS resolver and a good default for the Internet.
But if you run it with a different IP:
internalip 127.2.3.4
Then you will get:
127.0.0.1
because that is your IP address that would be used to connect with 127.2.3.4 on the loopback interface. It's useful when your target is on a LAN, VPN or other special network, in which case some other IP could be used for connections than the default IP for reaching the Internet.
External IP
To check your external IP address (the one that the servers on the Internet see when you connect to them - which may be different than the internal IP address described here) see this answer.