ifconfig and ip command Tips and Tricks

ifconfig and ip command

ifconfig and ip are command line tools used to configure,manage and query network interface  parameters via command line interface in Linux.

In this articles covers useful  “ifconfig” and “ip” commands which are helpful to you in managing and configuring network interfaces in Linux systems.

1) Shows all network interfaces.

Using  “”ifconfig”” command without options will display all the active interfaces details.

#ifconfig

[root@server1 ~]# ifconfig
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.10  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::a00:27ff:fed5:b2a2  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:d5:b2:a2  txqueuelen 1000  (Ethernet)
        RX packets 60  bytes 8139 (7.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 94  bytes 14301 (13.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

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 0  (Local Loopback)
        RX packets 28  bytes 2696 (2.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 28  bytes 2696 (2.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Take a closer look at the output fields of the ifconfig command.

ifconfig_ittroubleshooter_new

Using “-a” option, It will display information of all active or inactive network interfaces on system.
#ifconfig -a

[root@server1 ~]# ifconfig -a
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.10  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::a00:27ff:fed5:b2a2  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:d5:b2:a2  txqueuelen 1000  (Ethernet)
        RX packets 67  bytes 8725 (8.5 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 110  bytes 16373 (15.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp0s8: flags=4098<BROADCAST,MULTICAST>  mtu 1500
        ether 08:00:27:20:02:39  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

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 0  (Local Loopback)
        RX packets 36  bytes 3464 (3.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 36  bytes 3464 (3.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Note: If you got the error “ifconfig command not found”, then install the package called “net-tools” using yum command.

Remember: “ifconfig” command is equivalent to “ip” command. The output format for both commands is different; as shown below
#ip address or #ip a

[root@server1 ~]# ip address
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:d5:b2:a2 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.10/24 brd 192.168.1.255 scope global enp0s3
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fed5:b2a2/64 scope link 
       valid_lft forever preferred_lft forever
3: enp0s8: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
    link/ether 08:00:27:20:02:39 brd ff:ff:ff:ff:ff:ff
[root@server1 ~]#

As shown above, “ip” command does not show counts of packets handled in normal ways. For that use “-s” option.
#ip -s addr

[root@server1 ~]# ip -s addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
    RX: bytes  packets  errors  dropped overrun mcast   
    3464       36       0       0       0       0       
    TX: bytes  packets  errors  dropped carrier collsns 
    3464       36       0       0       0       0       
2: enp0s3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:d5:b2:a2 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.10/24 brd 192.168.1.255 scope global enp0s3
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fed5:b2a2/64 scope link 
       valid_lft forever preferred_lft forever
    RX: bytes  packets  errors  dropped overrun mcast   
    14513      137      0       0       0       0       
    TX: bytes  packets  errors  dropped carrier collsns 
    27027      149      0       0       0       0       
3: enp0s8: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN qlen 1000
    link/ether 08:00:27:20:02:39 brd ff:ff:ff:ff:ff:ff
    RX: bytes  packets  errors  dropped overrun mcast   
    0          0        0       0       0       0       
    TX: bytes  packets  errors  dropped carrier collsns 
    0          0        0       0       0       0       

2) Display Specific Interface.

#ifconfig <Network Interface>

[root@server1 ~]# ifconfig enp0s3
enp0s3: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.10  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::a00:27ff:fed5:b2a2  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:d5:b2:a2  txqueuelen 1000  (Ethernet)
        RX packets 175  bytes 17677 (17.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 178  bytes 33525 (32.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@server1 ~]#

Similarly you can use “ip” command;

[root@server1 ~]# ip addr show dev enp0s3

3)  Enable and disable a network interface.

#ifconfig enp0s3 up or #ip link set enp0s3 up or #ifup enp0s3

[root@server1 ~]# ifconfig enp0s3 up

A network interface is disabled in a similar way:
#ifconfig enp0s3 down or #ip link set enp0s3 down or #ifdown enp0s3

[root@server1 ~]# ifconfig enp0s3 down

4) Set IP address using ifconfig and ip addr commands.

#ifconfig enp0s8 192.168.1.50

[root@server1 ~]# ifconfig enp0s8 
enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.11  netmask 255.255.255.255  broadcast 192.168.1.11
        inet6 fe80::a00:27ff:fe20:239  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:20:02:39  txqueuelen 1000  (Ethernet)
        RX packets 300  bytes 18114 (17.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 94  bytes 10548 (10.3 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@server1 ~]# ifconfig enp0s8 192.168.1.50
[root@server1 ~]# ifconfig enp0s8 
enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.50  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::a00:27ff:fe20:239  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:20:02:39  txqueuelen 1000  (Ethernet)
        RX packets 308  bytes 18760 (18.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 101  bytes 11224 (10.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

You can use “ip” command in a similar way:
#ip address add 192.168.1.50 dev enp0s8

[root@server1 ~]# ip address add 192.168.1.50 dev enp0s8

To verify the status of ip address use below command.

[root@server1 ~]# ip addr show dev enp0s8

As above examples showing the simple version of the command. Often We need to specified the network mask or the broadcast address.  The following examples show the ifconfig and ip variants.
#ifconfig enp0s8 192.168.1.50 netmask 255.255.255.0 broadcast 192.168.1.255

[root@server1 ~]# ifconfig enp0s8 192.168.1.50 netmask 255.255.255.0 broadcast 192.168.1.255
[root@server1 ~]# ifconfig enp0s8
enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.50  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::a00:27ff:fe20:239  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:20:02:39  txqueuelen 1000  (Ethernet)
        RX packets 472  bytes 30836 (30.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 289  bytes 32682 (31.9 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Similarly you can use “ip” command;

#ip addr add 192.168.1.50/24 broadcast 192.168.1.255 dev enp0s8

[root@server1 ~]# ip addr add 192.168.1.50/24 broadcast 192.168.1.255 dev enp0s8

5) Delete an IP address to Network Interface.

Using “ip addr” command, It is also possible to delete an address.
#ip addr del 192.168.1.50/24 dev enp0s8

[root@server1 ~]# ip addr del 192.168.1.50/24 dev enp0s8

6) Add New Alias to Network Interface.

Using “ifconfig” and “ip” utility  you can add alias of network interfaces. Let take the example, if your enp0s8 network ip address is 192.168.1.50, then alias ip address must be 192.168.1.55 that means alias network address in same sub-net mask.
#ifconfig enp0s8:1 192.168.1.55/24

[root@server1 ~]# ifconfig enp0s8
enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.50  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::a00:27ff:fe20:239  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:20:02:39  txqueuelen 1000  (Ethernet)
        RX packets 971  bytes 70968 (69.3 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1150  bytes 142190 (138.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@server1 ~]# ifconfig enp0s8:1 192.168.1.55/24
[root@server1 ~]# ifconfig -a
enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.50  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::a00:27ff:fe20:239  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:20:02:39  txqueuelen 1000  (Ethernet)
        RX packets 1114  bytes 82110 (80.1 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 1441  bytes 175820 (171.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

enp0s8:1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.55  netmask 255.255.255.0  broadcast 192.168.1.255
        ether 08:00:27:20:02:39  txqueuelen 1000  (Ethernet)
 [. . . . .]

You can use “ip address” command in a similar way:
#ip addr add 192.168.1.55/24 dev enp0s8 label enp0s8:1

[root@server1 ~]# ip addr add 192.168.1.55/24 dev enp0s8 label enp0s8:1
[root@server1 ~]# ip addr show dev enp0s8
3: enp0s8: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 08:00:27:20:02:39 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.50/24 brd 192.168.1.255 scope global enp0s8
       valid_lft forever preferred_lft forever
    inet 192.168.1.55/24 brd 192.168.1.255 scope global secondary enp0s8:1
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fe20:239/64 scope link 
       valid_lft forever preferred_lft forever
[root@server1 ~]#

You can also use the same option for Enable and disable a network interface.

# ifconfig enp0s8:1 192.168.1.55 netmask 255.255.255.0 up

[root@server1 ~]# ifconfig enp0s8:1 192.168.1.55 netmask 255.255.255.0 up

# ifconfig enp0s8:1 192.168.1.55 netmask 255.255.255.0 down

[root@server1 ~]# ifconfig enp0s8:1 192.168.1.55 netmask 255.255.255.0 down

To Remove Alias to Network Interface use following command.

[root@server1 ~]# ifconfig enp0s8:1 down

7) Change the MAC (Media Access Control) address.

Use the below command, You can change the MAC  address of an enp0s8 network interface.
#ifconfig <Network Interface> hw ether <Ether Card Address>

[root@server1 ~]# ifconfig enp0s8
enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
 inet 192.168.1.11 netmask 255.255.255.255 broadcast 192.168.1.11
 inet6 fe80::a00:27ff:fe20:239 prefixlen 64 scopeid 0x20<link>
 ether 08:00:27:20:02:39 txqueuelen 1000 (Ethernet)
 RX packets 120 bytes 7200 (7.0 KiB)
 RX errors 0 dropped 0 overruns 0 frame 0
 TX packets 12 bytes 924 (924.0 B)
 TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

[root@server1 ~]# ifconfig enp0s8 hw ether 0A:CC:72:03:05:40
[root@server1 ~]# ifconfig enp0s8
enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
 inet 192.168.1.11 netmask 255.255.255.255 broadcast 192.168.1.11
 inet6 fe80::a00:27ff:fe20:239 prefixlen 64 scopeid 0x20<link>
 ether 0a:cc:72:03:05:40 txqueuelen 1000 (Ethernet)
 RX packets 147 bytes 8820 (8.6 KiB)
 RX errors 0 dropped 0 overruns 0 frame 0
 TX packets 12 bytes 924 (924.0 B)
 TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

You can use “ip” command in a similar way:
#ip link set dev <interface> address <mac_addr>

[root@server1 ~]# ip link set dev enp0s8 address 0a:cc:72:03:05:40

8) Set the MTU for an Network Interface.

MTU stand for Maximum Transmission Unit. It is the size of each packet received by the Ethernet card. By default the value of MTU for all Ethernet devices is 1500. In our case, we will set the maximum transmission unit is 1000.
#ifconfig enp0s8 mtu 1000

[root@server1 ~]# ifconfig enp0s8
enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.11  netmask 255.255.255.255  broadcast 192.168.1.11
        inet6 fe80::a00:27ff:fe20:239  prefixlen 64  scopeid 0x20<link>
        ether 08:00:27:20:02:39  txqueuelen 1000  (Ethernet)
        RX packets 153  bytes 9180 (8.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 12  bytes 924 (924.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[root@server1 ~]# ifconfig enp0s8 mtu 1000
[root@server1 ~]# ifconfig enp0s8
enp0s8: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1000
        inet 192.168.1.11  netmask 255.255.255.255  broadcast 192.168.1.11
        ether 0a:cc:72:03:05:40  txqueuelen 1000  (Ethernet)
        RX packets 153  bytes 9180 (8.9 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 12  bytes 924 (924.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

You can use “ip” command in a similar way:
#ip link set dev <interface> mtu <n>

[root@server1 ~]# ip link set dev enp0s8 mtu 1000

9) Enable or disable the promiscuous mode.

If promiscuous mode is enabled (Shown below example), it verifies all the packets that flows through the network card.

[root@server1 ~]# ifconfig enp0s8 promisc
[root@server1 ~]# dmesg | tail -1
[ 1562.512409] device enp0s8 entered promiscuous mode
[root@server1 ~]#

Similarly, If promiscuous mode is disabled, It will not analyze the drop packets hat flows through the network interface, as shown below example.

[root@server1 ~]# ifconfig enp0s8 -promisc
[root@server1 ~]# dmesg | tail -1
[ 1641.428471] device enp0s8 left promiscuous mode
[root@server1 ~]#

You can use “ip” command in a similar way:
#ip link set dev <interface> promisc on or off

[root@server1 ~]# ip link set dev enp0s8 promisc on

10) Sets the multicast flag.

Sets the multicast flag on the interface using “ifconfig” and “ip” address.
#ifconfig <interface> multicast

[root@server1 ~]# ifconfig enp0s8 multicast

You can use “ip” command in a similar way:
#ip link set dev <interface> multicast on or off

[root@server1 ~]# ip link set dev enp0s8 multicast on

Note: It should not be needed as the drivers set the flag correctly themselves.

11) Sets the transmit queue length.

Sets the transmit queue length on the network interface, as shown below.
#ifconfig <interface> txquelen <n>

[root@server1 ~]# ifconfig enp0s8 txquelen 1000

Similar for “ip” address;
#ip link set dev <interface> txqueuelen <n> or #txqlen <n>

[root@server1 ~]# ip link set dev enp0s8  txqueuelen 1000

Hope this post will help Linux/Unix beginners. Please share you feedback and Comments.!!!

Leave a Reply

Be the First to Comment!

Notify of
avatar
wpDiscuz