10

How can I see my IP address on Ubuntu? I used

ifconfig eth0

but it only displays HWaddr and I don't see where the IP address is.

A.B.
  • 90,397
  • 3
    If there is no IP address in ifconfig, then you do not get one. Please [edit] your question and add output of ifconfig command. – Pilot6 Jul 07 '15 at 18:16
  • 1
    And why eth0? Post just ifconfig. – Pilot6 Jul 07 '15 at 18:22
  • Relevant https://askubuntu.com/questions/430853/how-do-i-find-my-internal-ip-address http://askubuntu.com/q/95910/178596 – Wilf Jul 07 '15 at 19:10

8 Answers8

9

The following command will output all of your current IP addresses, separated by spaces:

hostname -I
Kaz Wolfe
  • 34,122
  • 21
  • 114
  • 172
tomd
  • 191
6

Your best to use ifconfig without the interface as it may not be eth0.

ifconfig | less

will allow you to page down to see what interface is assigned an IP.

You can also cheat by using route to see what interfaces are being used.

$ route
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         192.168.138.1   0.0.0.0         UG    0      0        0 eth2

and then use ifconfig on the interfaces listed, eg.

ifconfig eth2
3

Use command: ip addr show and look for your interface, for example wlan0 for WiFi and eth0 for network card.

Mike
  • 5,691
1

If ifconfig doesn't show an IP the interface doesn't have one assigned. Assign one with sudo ifconfig 1.2.3.4 netmask 255.255.255.0 or use dhclient -d [iface] if you have a DHCP server in your network (if your uncertain try it, it doesn't hurt and is easier if it works).

Kalle Richter
  • 6,180
  • 21
  • 70
  • 103
  • You can additionally use ip addr to see all address (hardware, IPv4, and IPv6) assigned to an interface. (ifconfig is deprecated.) – saiarcot895 Jul 07 '15 at 16:48
1

If you're connected to the network through a wireless NIC, ifconfig eth0 is useless, because it will show the output of ifconfig for the first ethernet NIC (if any):

ifconfig wlan0

Or wlan1, wlan2, wlan3, [...] depending on how the NIC in use has been mapped (in case you have multiple wireless NICs).

To display only the IP address:

ifconfig wlan0 | sed -n '2s/[^:]*:\([^ ]*\).*/\1/p'
kos
  • 35,891
1

Personally I use nmcli dev show (15.04) or nmcli dev list (14.04 and earlier). It lists full information about your interfaces, dns, nearest access points, and of course your IPv4 address. You can use awk to trim the info as desired.

A.B.
  • 90,397
Sergiy Kolodyazhnyy
  • 105,154
  • 20
  • 279
  • 497
0

After typing

ifconfig eth0

your IP should be listed under

inet addr

Something like:

inet addr:10.0.2.15 Bcast: 10.0.2.255 Mask:255.255.255.0

In this example, 10.0.2.15 would be your IP address.

A.B.
  • 90,397
rye
  • 109
0

Show all your IPv4 addresses:

LANG=C ifconfig | awk -F: '/inet addr/ {gsub(/ .*/,"",$2); print $2}'

Or for IPv6:

LANG=C ifconfig | awk '/inet6 addr/ {print $3}'

Or an other version:

ip addr show | awk '/inet/ {print $2}' 

If you only see something like this:

127.0.0.1/8
::1/128

than you have no IP address. (127.0.0.1 doesn't count as this is your system aka localhost.)


Sample output

% LANG=C ifconfig | awk -F: '/inet addr/ {gsub(/ .*/,"",$2); print $2}'
192.168.2.131
127.0.0.1

% LANG=C ifconfig | awk '/inet6 addr/ {print $3}'   
fe80::92e2:baff:fe21:c902/64
::1/128

% ip addr show | awk '/inet/ {print $2}' 
127.0.0.1/8
::1/128
192.168.2.131/24
fe80::92e2:baff:fe21:c902/64
Fabby
  • 34,259
A.B.
  • 90,397