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.
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.
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
Use command: ip addr show
and look for your interface, for example wlan0 for WiFi and eth0 for network card.
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).
ip addr
to see all address (hardware, IPv4, and IPv6) assigned to an interface. (ifconfig
is deprecated.)
– saiarcot895
Jul 07 '15 at 16:48
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'
sed
. That should match any possible language
– kos
Jul 07 '15 at 18:33
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.
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.
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
ifconfig
-something somewhere on the left! My bad
– kos
Jul 07 '15 at 18:53
ifconfig
command. – Pilot6 Jul 07 '15 at 18:16ifconfig
. – Pilot6 Jul 07 '15 at 18:22