ifconfig command in Linux with Examples



Name

ifconfig - configure a network interface

Synopsis

ifconfig [-v] [-a] [-s] [interface]
ifconfig [-v] interface [aftype] options | address ...

Description

ifconfig command is used to configure the kernel-resident network interfaces. It is used at boot time to set up interfaces as necessary. After that, it is usually needed to query and manage network parameters. It is also required during debugging or when system tuning is needed.

If no arguments are given, ifconfig command displays the status of the currently active interfaces. If a single interface argument is given, it displays the status of the given interface only; in case of -a option, it displays the status of all interfaces, even those that are down. Otherwise, it configures an interface.

Options

ifconfig commands accepts following options and arguments:

-a    display all interfaces which are currently available, even if down

-s    display a short list (like netstat -i)

-v    be more verbose for some error conditions

interface
   The name of the interface. This is usually a driver name followed by a unit number, for example eth0 for the first Ethernet interface. If your kernel supports alias interfaces, you can specify them with eth0:0 for the first alias of eth0. You can use them to assign a second address. To delete an alias interface use ifconfig eth0:0 down. Note: for every scope (i.e. same net with address/netmask combination) all aliases are deleted, if you delete the first (primary).

up     This flag causes the interface to be activated. It is implicitly specified if an address is assigned to the interface.

down   This flag causes the driver for this interface to be shut down.

[-]arp Enable or disable the use of the ARP protocol on this interface.

[-]promisc
   Enable or disable the promiscuous mode of the interface. If selected, all packets on the network will be received by the interface.

[-]allmulti
   Enable or disable all-multicast mode. If selected, all multicast packets on the network will be received by the interface.

metric N
   This parameter sets the interface metric.

mtu N  This parameter sets the Maximum Transfer Unit (MTU) of an interface.

dstaddr addr
   Set the remote IP address for a point-to-point link (such as PPP). This keyword is now obsolete; use the pointopoint keyword instead.
   netmask addr
   Set the IP network mask for this interface. This value defaults to the usual
   class A, B or C network mask (as derived from the interface IP  address),  but  it
   can be set to any value.

add addr/prefixlen
   Add an IPv6 address to an interface.

del addr/prefixlen
   Remove an IPv6 address from an interface.

tunnel aa.bb.cc.dd
   Create a new SIT (IPv6-in-IPv4) device, tunnelling to the given destination.

irq addr
   Set the interrupt line used by this device. Not all devices can dynamically change their IRQ setting.

io_addr addr
   Set the start address in I/O space for this device.

mem_start addr
   Set the start address for shared memory used by this device.  Only a few devices need this.
address
   The IP address to be assigned to this interface.

Examples

1. ifconfig command without any argument displays the details of all the active interfaces. This command also displays the assigned ip address of active interfaces. There could be interfaces that are active but they may not have been assigend an IP address.

$ ifconfig
eth0: flags=4099<UP,BROADCAST,MULTICAST> mtu 1500
      ether 20:25:64:08:6a:a4  txqueuelen 1000  (Ethernet)
      RX packets 0  bytes 0 (0.0 B)
      RX errors 0  dropped 0  overruns 0  frame 0
      TX packets 0  bytes 0 (0.0 B)
      TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
      device interrupt 20  memory 0xf7c00000-f7c20000  

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
      inet 127.0.0.1  netmask 255.0.0.0
      inet6 ::1  prefixlen 128  scopeid 0x10<host>
      loop  txqueuelen 1000  (Local Loopback)
      RX packets 5426  bytes 509075 (509.0 KB)
      RX errors 0  dropped 0  overruns 0  frame 0
      TX packets 5426  bytes 509075 (509.0 KB)
      TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
      inet 192.168.72.222  netmask 255.255.255.0  broadcast 192.168.72.255
      inet6 2409:4053:2105:527d:db24:166e:345d:d48a prefixlen 64  scopeid 0x0<global>
      inet6 fe80::fa1c:1e5f:feac:5280  prefixlen 64  scopeid 0x20<link>
      inet6 2409:4053:2105:527d:c113:9da0:ddcc:2235  prefixlen 64  scopeid 0x0<global>
      ether a4:2b:8c:5f:19:0b  txqueuelen 1000  (Ethernet)
      RX packets 15381  bytes 7488890 (7.4 MB)
      RX errors 0  dropped 0  overruns 0  frame 0
      TX packets 16671  bytes 2821518 (2.8 MB)
      TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

2. Use -a option to display all network interfaces on the server even if the network interface is down.

$ ifconfig -a
eth0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
      ether 20:25:64:08:6a:a4  txqueuelen 1000  (Ethernet)
      RX packets 0  bytes 0 (0.0 B)
      RX errors 0  dropped 0  overruns 0  frame 0
      TX packets 0  bytes 0 (0.0 B)
      TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
      device interrupt 20  memory 0xf7c00000-f7c20000  

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
      inet 127.0.0.1  netmask 255.0.0.0
      inet6 ::1  prefixlen 128  scopeid 0x10<host>
      loop  txqueuelen 1000  (Local Loopback)
      RX packets 5426  bytes 509075 (509.0 KB)
      RX errors 0  dropped 0  overruns 0  frame 0
      TX packets 5426  bytes 509075 (509.0 KB)
      TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        
sit0     Link encap:IPv6-in-IPv4
         NOARP  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:0
         RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

wlan0:   flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
         inet 192.168.72.222  netmask 255.255.255.0  broadcast 192.168.72.255
         inet6 2409:4053:2105:527d:db24:166e:345d:d48a  prefixlen 64  scopeid 0x0<global>
         inet6 fe80::fa1c:1e5f:feac:5280  prefixlen 64  scopeid 0x20<link>
         inet6 2409:4053:2105:527d:c113:9da0:ddcc:2235  prefixlen 64  scopeid 0x0<global>
         ether a4:2b:8c:5f:19:0b  txqueuelen 1000  (Ethernet)
         RX packets 15381  bytes 7488890 (7.4 MB)
         RX errors 0  dropped 0  overruns 0  frame 0
         TX packets 16671  bytes 2821518 (2.8 MB)
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

We can see that sit0 interface is down, even then it is listed in the display.

3. Use -s option to display a short list, instead of all the details.

$ ifconfig -s
Iface      MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0      1500        0      0      0 0             0      0      0      0 BMU
lo       65536     9696      0      0 0          9696      0      0      0 LRU
wlan0     1500    32426      0      0 0         35073      0      0      0 BMRU

4. ifconfig command with interface name (wlan0) as an argument displays details of interface configuration.

$ ifconfig wlan0
      wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
      inet 192.168.72.222  netmask 255.255.255.0  broadcast 192.168.72.255
      inet6 2409:4053:2105:527d:db24:166e:345d:d48a  prefixlen 64  scopeid 0x0<global>
      inet6 fe80::fa1c:1e5f:feac:5280  prefixlen 64  scopeid 0x20<link>
      inet6 2409:4053:2105:527d:c113:9da0:ddcc:2235  prefixlen 64  scopeid 0x0<global>
      ether a4:2b:8c:5f:19:0b  txqueuelen 1000  (Ethernet)
      RX packets 39246  bytes 16139815 (16.1 MB)
      RX errors 0  dropped 0  overruns 0  frame 0
      TX packets 42288  bytes 8517460 (8.5 MB)
      TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

4. ifconfig command along with down option can be used to deactivate a network interface. Use this command with root permissions.

$ sudo ifconfig  enp0s25 down
$ ifconfig
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:187930 errors:0 dropped:0 overruns:0 frame:0
         TX packets:187930 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:1000 
         RX bytes:68712556 (68.7 MB)  TX bytes:68712556 (68.7 MB)

wlx503eaa7c4c9b Link encap:Ethernet  HWaddr 50:3e:aa:7c:4c:9b  
         inet addr:192.168.0.4  Bcast:192.168.0.255  Mask:255.255.255.0
         inet6 addr: fe80::15de:9204:3015:b802/64 Scope:Link
         UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
         RX packets:409882 errors:0 dropped:1902 overruns:0 frame:0
         TX packets:308849 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:1000 
         RX bytes:464826692 (464.8 MB)  TX bytes:51670694 (51.6 MB)

We can see the network interface enp0s25 is not displayed in the list of active interfaces, after it was deactivated.

5. ifconfig command along with up option can be used to activate a network interface if it is not in active state. Use this command with root permissions. It is important to note that name of network interface must precede the command options.

$ sudo ifconfig enp0s25 up
$ ifconfig
enp0s25     Link encap:Ethernet  HWaddr 7c:05:07:10:08:8d  
            inet6 addr: fe80::5ba9:5ddd:a609:e410/64 Scope:Link
            UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
            RX packets:0 errors:0 dropped:0 overruns:0 frame:0
            TX packets:4719 errors:0 dropped:0 overruns:0 carrier:0
            collisions:0 txqueuelen:1000 
            RX bytes:0 (0.0 B)  TX bytes:963440 (963.4 KB)
            Interrupt:20 Memory:f7c00000-f7c20000 

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:190712 errors:0 dropped:0 overruns:0 frame:0
            TX packets:190712 errors:0 dropped:0 overruns:0 carrier:0
            collisions:0 txqueuelen:1000 
            RX bytes:69933565 (69.9 MB)  TX bytes:69933565 (69.9 MB)

wlx503eaa7c4c9b   Link encap:Ethernet  HWaddr 50:3e:aa:7c:4c:9b  
                  inet addr:192.168.0.4  Bcast:192.168.0.255  Mask:255.255.255.0
                  inet6 addr: fe80::15de:9204:3015:b802/64 Scope:Link
                  UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
                  RX packets:410653 errors:0 dropped:1929 overruns:0 frame:0
                  TX packets:309651 errors:0 dropped:0 overruns:0 carrier:0
                  collisions:0 txqueuelen:1000 
                  RX bytes:465020094 (465.0 MB)  TX bytes:51915953 (51.9 MB) 

6. ifconfig command can be used with an interface name (eth0) and ip address to assign an IP address to the specific interface. Use this command with root permissions.

$ sudo ifconfig eth0 192.168.72.228
$ ifconfig
eth0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
      inet 192.168.72.228  netmask 255.255.255.0  broadcast 192.168.72.255
      ether 20:25:64:08:6a:a4  txqueuelen 1000  (Ethernet)
      RX packets 0  bytes 0 (0.0 B)
      RX errors 0  dropped 0  overruns 0  frame 0
      TX packets 0  bytes 0 (0.0 B)
      TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
      device interrupt 20  memory 0xf7c00000-f7c20000  

lo:   flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
      inet 127.0.0.1  netmask 255.0.0.0
      inet6 ::1  prefixlen 128  scopeid 0x10<host>
      loop  txqueuelen 1000  (Local Loopback)
      RX packets 16589  bytes 1698274 (1.6 MB)
      RX errors 0  dropped 0  overruns 0  frame 0
      TX packets 16589  bytes 1698274 (1.6 MB)
      TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0:   flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
         inet 192.168.72.222  netmask 255.255.255.0  broadcast 192.168.72.255
         inet6 fe80::fa1c:1e5f:feac:5280  prefixlen 64  scopeid 0x20<link>
         inet6 2409:4053:2105:527d:db24:166e:345d:d48a  prefixlen 64  scopeid 0x0<global>
         inet6 2409:4053:2105:527d:653c:9f2d:750d:4528  prefixlen 64  scopeid 0x0<global>
         ether a4:2b:8c:5f:19:0b  txqueuelen 1000  (Ethernet)
         RX packets 53256  bytes 15930912 (15.9 MB)
         RX errors 0  dropped 0  overruns 0  frame 0
         TX packets 58487  bytes 12868848 (12.8 MB)
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

7. To assign an IP address, Netmask address and Broadcast address all at once, we can use the following command. Use this command with root permissions.

$ ifconfig eth0 192.168.72.144 netmask 255.255.255.0 broadcast 192.168.72.255
$ ifconfig
eth0: flags=4099<UP,BROADCAST,MULTICAST>  mtu 1500
      inet 192.168.72.144  netmask 255.255.255.0  broadcast 192.168.72.255
      ether 20:25:64:08:6a:a4  txqueuelen 1000  (Ethernet)
      RX packets 0  bytes 0 (0.0 B)
      RX errors 0  dropped 0  overruns 0  frame 0
      TX packets 0  bytes 0 (0.0 B)
      TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
      device interrupt 20  memory 0xf7c00000-f7c20000  

lo:   flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
      inet 127.0.0.1  netmask 255.0.0.0
      inet6 ::1  prefixlen 128  scopeid 0x10<host>
      loop  txqueuelen 1000  (Local Loopback)
      RX packets 19543  bytes 2004727 (2.0 MB)
      RX errors 0  dropped 0  overruns 0  frame 0
      TX packets 19543  bytes 2004727 (2.0 MB)
      TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0:   flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
         inet 192.168.72.222  netmask 255.255.255.0  broadcast 192.168.72.255
         inet6 fe80::fa1c:1e5f:feac:5280  prefixlen 64  scopeid 0x20<link>
         inet6 2409:4053:2105:527d:db24:166e:345d:d48a  prefixlen 64  scopeid 0x0<global>
         inet6 2409:4053:2105:527d:653c:9f2d:750d:4528  prefixlen 64  scopeid 0x0<global>
         ether a4:2b:8c:5f:19:0b  txqueuelen 1000  (Ethernet)
         RX packets 62912  bytes 19006480 (19.0 MB)
         RX errors 0  dropped 0  overruns 0  frame 0
         TX packets 69417  bytes 15159473 (15.1 MB)
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

8. Whenever a packet is received by a network card, it verifies if the packet belongs to itself. If not, it drops the packet normally, but in the promiscuous mode, it accept all the packets that flows through the network card. ifconfig command along with an interface name (eth0) and promisc argument enables promiscuous mode. In this mode the interface card will capture all the packets being broadcast. Use this command with root permissions. This is generally used by network sniffer programs like Wireshark to analyze broadcast packets.

$ ifconfig eth0 promisc
$ ifconfig
eth0:    flags=4355<UP,BROADCAST,PROMISC,MULTICAST>  mtu 1000
         inet 192.168.72.144  netmask 255.255.255.0  broadcast 192.168.72.255
         ether aa:bb:cc:dd:ee:ff  txqueuelen 1000  (Ethernet)
         RX packets 0  bytes 0 (0.0 B)
         RX errors 0  dropped 0  overruns 0  frame 0
         TX packets 0  bytes 0 (0.0 B)
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
         device interrupt 20  memory 0xf7c00000-f7c20000  

lo:      flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
         inet 127.0.0.1  netmask 255.0.0.0
         inet6 ::1  prefixlen 128  scopeid 0x10<host>
         loop  txqueuelen 1000  (Local Loopback)
         RX packets 22588  bytes 2330398 (2.3 MB)
         RX errors 0  dropped 0  overruns 0  frame 0
         TX packets 22588  bytes 2330398 (2.3 MB)
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0:   flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
         inet 192.168.72.222  netmask 255.255.255.0  broadcast 192.168.72.255
         inet6 fe80::fa1c:1e5f:feac:5280  prefixlen 64  scopeid 0x20<link>
         inet6 2409:4053:2105:527d:db24:166e:345d:d48a  prefixlen 64  scopeid 0x0<global>
         inet6 2409:4053:2105:527d:653c:9f2d:750d:4528  prefixlen 64  scopeid 0x0<global>
         ether a4:2b:8c:5f:19:0b  txqueuelen 1000  (Ethernet)
         RX packets 73307  bytes 22471053 (22.4 MB)
         RX errors 0  dropped 0  overruns 0  frame 0
         TX packets 80986  bytes 17490208 (17.4 MB)
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

9. Use ifconfig command with an interface name (eth0) and -promisc argument to disable promiscuous mode.

$ ifconfig eth0 -promisc
$ ifconfig
eth0:    flags=4099<UP,BROADCAST,MULTICAST>  mtu 1000
         inet 192.168.72.144  netmask 255.255.255.0  broadcast 192.168.72.255
         ether aa:bb:cc:dd:ee:ff  txqueuelen 1000  (Ethernet)
         RX packets 0  bytes 0 (0.0 B)
         RX errors 0  dropped 0  overruns 0  frame 0
         TX packets 0  bytes 0 (0.0 B)
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
         device interrupt 20  memory 0xf7c00000-f7c20000  

lo:      flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
         inet 127.0.0.1  netmask 255.0.0.0
         inet6 ::1  prefixlen 128  scopeid 0x10<host>
         loop  txqueuelen 1000  (Local Loopback)
         RX packets 22990  bytes 2375724 (2.3 MB)
         RX errors 0  dropped 0  overruns 0  frame 0
         TX packets 22990  bytes 2375724 (2.3 MB)
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

wlan0:   flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
         inet 192.168.72.222  netmask 255.255.255.0  broadcast 192.168.72.255
         inet6 fe80::fa1c:1e5f:feac:5280  prefixlen 64  scopeid 0x20<link>
         inet6 2409:4053:2105:527d:db24:166e:345d:d48a  prefixlen 64  scopeid 0x0<global>
         inet6 2409:4053:2105:527d:653c:9f2d:750d:4528  prefixlen 64  scopeid 0x0<global>
         ether a4:2b:8c:5f:19:0b  txqueuelen 1000  (Ethernet)
         RX packets 74842  bytes 23020724 (23.0 MB)
         RX errors 0  dropped 0  overruns 0  frame 0
         TX packets 82714  bytes 17824215 (17.8 MB)
         TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
Advertisements