[Tip] How to find the IP address and hostname of your computer

I) Here are ways summarized to find out or get the IP address of your computer via console.

a) most complicated but most to the point command is

ip route get | grep -oP '(?<=src )\S+'

b) a little confusing result is shown with

 ip address


ip addr


ip a

c) shows the default IP address of your WLAN router but also your PC IP address is included.

ip route show

d) should show the ip address under IP4.ADDRESS

nmcli -p device show

e) Install “net-tools” than use the command

ifconfig -a

f) simply look into your router and you can find the ip address to your device.

II) a) hostname of your PC


b) Here you can also find out the hostname of your PC. The IP address of the router but not of your PC is also shown.

getent hosts
1 Like

ip command also has a brief mode for address:

$ ip -br a

This potentially gets alot of results, depending on hosts configuration in /etc/nsswitch.conf.
The IP address of the router is not necessarily among those entries.