Tuesday, March 7, 2017

How do I display all available network interfaces on linux?

How do I display all available network interfaces names under Linux operating systems using bash shell prompt?

You can use the following commands to see all network interfaces under Linux operating systems:

Method 1:

Using ip command

Syntax: ip link show

Example:

root@linuxforfreshers.com:~$ ip link show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether 00:1b:78:8b:33:c4 brd ff:ff:ff:ff:ff:ff
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN mode DEFAULT group default qlen 1000
    link/ether 46:41:6e:87:64:74 brd ff:ff:ff:ff:ff:ff

Where
1.    lo – Loopback interface.
2.    eth0 – First Ethernet network interface.
3.     vboxnet0, vmnet1, vmnet8 – Virtual machine interface working in bridge mode or NAT mode. 
Method 2:
Using ifconfig
Syntax: ifconfig
Example:
root@linuxforfreshers.com:~$ ifconfig
eth0      Link encap:Ethernet  HWaddr 00:1b:78:8b:39:d5 
          inet addr:192.168.101.26Bcast:192.1.16.255  Mask:255.255.255.0
          inet6 addr: fe80::21b:78ff:fe8b:33c4/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1881405 errors:0 dropped:0 overruns:0 frame:0
          TX packets:841660 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1234319479 (1.2 GB)  TX bytes:157758923 (157.7 MB)
          Interrupt:19 Memory:f2400000-f2420000

lo        Link encap:Local Loopback 
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:148 errors:0 dropped:0 overruns:0 frame:0
          TX packets:148 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1
          RX bytes:21549 (21.5 KB)  TX bytes:21549 (21.5 KB)

virbr0    Link encap:Ethernet  HWaddr 46:41:6e:87:64:74 
          inet addr:192.168.122.1  Bcast:192.168.122.255  Mask:255.255.255.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

Example 2:
root@linuxforfreshers.com:~$ ifconfig -a | sed 's/[ \t].*//;/^$/d'
eth0
lo
virbr0

Method 3:
Usinf sys.
Example:
root@linuxforfreshers.com:~$ ls /sys/class/net/
eth0  lo  virbr0
 Method 4:
Using basename
Example :
root@linuxforfreshers.com:~$ basename -a /sys/class/net/*
eth0
lo
virbr0

No comments:

Post a Comment