I have to set up a network connection on a Arch Linux install (in Virtualbox) and I need to know what network interfaces I’m using. How can I do this without using ifconfig
?
4 Answers
The ifconfig
tool (from net-tools
) is being deprecated in favour of the ip
tool, which is part of the iproute2
suite.
This will list interfaces, and their ip addresses if they have one:
ip addr
-
1Note that the answer from Palaeologus shows the
ip a
command - this is a valid abbreviation ofip addr
which is the form you'll see in the help forip
. In fact, any abbreviation ofaddress
will give the same result.– PaulCommented Jul 13, 2017 at 4:39
The Linux.com website has the following article on replacing the ifconfig command with ip:
The first thing most people learn with the ifconfig command is how to find out what IP address has been assigned to an interface. This is usually done with the command ifconfig and no flags or arguments. To do the same with the ip command, it is run as such:
ip a
This command will list all interfaces with their associated information (Figure 1 above).
Let’s say you only want to see IPv4 information (for clarity). To do this, issue the command:
ip -4 a
Or, if you only want to see IPv6 information:
ip -6 a
What if you only want to see information regarding a specific interface? You can list information for a wireless connection with the command:
ip a show wlan0
You can even get more specific with this command. If > you only want to view IPv4 on the wlan0 interface, issue the command:
ip -4 a show wlan0
You can even list only the running interface using:
ip link ls up
There's another option: use the kernel-provided directories (sysfs).
ls /sys/class/net/
That way it is easy to write:
for interface in $(ls /sys/class/net/) ; do
echo $interface
# ...
done
Note that the subdirectories can offer some info about the link level aspects (like the Ethernet MAC address), but not things like IP address.
In case someone wants to know what can be found there, here is the documentation: https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-net
You can also the cli for Network Manager GUI, with the command to list the interfaces available, their type, connection state, and general connection "name"
nmcli dev status
Or you can go further with
nmcli dev show
Which will produce a result similar to Window's ipconfig /all
command:
acejavelin@BlazingIcicle ~ $ nmcli dev show
GENERAL.DEVICE: enp2s0
GENERAL.TYPE: ethernet
GENERAL.HWADDR: F8:32:E4:BD:00:00
GENERAL.MTU: 1500
GENERAL.STATE: 100 (connected)
GENERAL.CONNECTION: Wired connection 1
GENERAL.CON-PATH: /org/freedesktop/NetworkManager/ActiveConnection/0
WIRED-PROPERTIES.CARRIER: on
IP4.ADDRESS[1]: 192.168.1.188/24
IP4.GATEWAY: 192.168.1.1
IP4.ROUTE[1]: dst = 169.254.0.0/16, nh = 0.0.0.0, mt = 1000
IP4.DNS[1]: 208.67.220.220
IP4.DNS[2]: 208.67.222.222
IP4.DNS[3]: 192.168.1.1
IP6.ADDRESS[1]: fe80::36f1:930b:48a:ab0e/64
IP6.GATEWAY:GENERAL.DEVICE: lo
GENERAL.TYPE: loopback
GENERAL.HWADDR: 00:00:00:00:00:00
GENERAL.MTU: 65536
GENERAL.STATE: 10 (unmanaged)
GENERAL.CONNECTION: --
GENERAL.CON-PATH: --
IP4.ADDRESS[1]: 127.0.0.1/8
IP4.GATEWAY:
IP6.ADDRESS[1]: ::1/128
IP6.GATEWAY:
acejavelin@BlazingIcicle ~ $
This could also be further refined for the specific interface
nmcli dev show eth0
or nmcli dev show wl0
I have also found it useful to use an alias of ipconfig
to actually be nmcli dev show
on several computers I use.