I want to know the easiest way and I would perfer a single line command that works on most or all Linux distros. I want to get the devices IPv4 address.

The reason why I want to know this is because I use XAMPP and to test my websites out on my phone I like to have my computer and phone connected to the same WiFi network and I connect to my website by my computers IP address.

  • use command: ifconfig – Tejas Dec 11 '18 at 1:04

The traditional command, on Unix, is ifconfig.


% ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet  netmask  broadcast

This command has been deprecated and may not always be installed by default. The modern command is ip.

% ip -4 addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    inet scope host lo
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    inet brd scope global noprefixroute dynamic eth0
       valid_lft 18396sec preferred_lft 18396sec

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.