ifconfig command in Linux with Examples
ifconfig Command
ifconfig stands for Interface configuration. It shows the information about ip address, net mask and broadcast address of current network configuration.
To view all network setting
The below ifconfig command is used to show the information about ip address, broadcast, netmask etc. It is also shows the information about all active interfaces.
Example
[root@localhost ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 4C:72:B9:98:87:0F
inet addr:192.168.7.251 Bcast:192.168.7.255 Mask:255.255.255.0
inet6 addr: fe80::4e72:b9ff:fe98:870f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:31325989 errors:0 dropped:0 overruns:0 frame:0
TX packets:11123954 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:38693395933 (36.0 GiB) TX bytes:1086249568 (1.0 GiB)
Interrupt:20 Memory:fe400000-fe420000
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:76846 errors:0 dropped:0 overruns:0 frame:0
TX packets:76846 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:536955900 (512.0 MiB) TX bytes:536955900 (512.0 MiB)
virbr0 Link encap:Ethernet HWaddr 52:54:00:92:60:28
inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:100480 errors:0 dropped:0 overruns:0 frame:0
TX packets:147360 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:5763019 (5.4 MiB) TX bytes:222134526 (211.8 MiB)
To display information of all network interfaces
It displays all the information of active or inactive network interfaces on server by using the ifconfig command with the -a argument. It shows the interfaces like eth0, lo, virbr0 and virbr0-nic.
Example
[root@localhost ~]# ifconfig -a
eth0 Link encap:Ethernet HWaddr 4C:72:B9:98:87:0F
inet addr:192.168.7.251 Bcast:192.168.7.255 Mask:255.255.255.0
inet6 addr: fe80::4e72:b9ff:fe98:870f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:31364877 errors:0 dropped:0 overruns:0 frame:0
TX packets:11149020 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:38731102002 (36.0 GiB) TX bytes:1091182569 (1.0 GiB)
Interrupt:20 Memory:fe400000-fe420000
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:76896 errors:0 dropped:0 overruns:0 frame:0
TX packets:76896 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:536958400 (512.0 MiB) TX bytes:536958400 (512.0 MiB)
virbr0 Link encap:Ethernet HWaddr 52:54:00:92:60:28
inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:100480 errors:0 dropped:0 overruns:0 frame:0
TX packets:147360 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:5763019 (5.4 MiB) TX bytes:222134526 (211.8 MiB)
virbr0-nic Link encap:Ethernet HWaddr 52:54:00:92:60:28
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:500
To view network settings for specific interface
The below command helps to view the network settings for specific interface by using the ifconfig command with the interface name such as eth0, lo etc.
Example
[root@localhost ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 4C:72:B9:98:87:0F
inet addr:192.168.7.251 Bcast:192.168.7.255 Mask:255.255.255.0
inet6 addr: fe80::4e72:b9ff:fe98:870f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:31451787 errors:0 dropped:0 overruns:0 frame:0
TX packets:11204452 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:38821678185 (36.1 GiB) TX bytes:1097072799 (1.0 GiB)
Interrupt:20 Memory:fe400000-fe420000
To disable the network interface
The below command helps to disable the active interface by using the ifconfig command with the interface name.
Example
[root@localhost ~]# ifconfig eth0 down Now check the status of all network setting, the command is “ ifconfig” [root@localhost ~]# 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:76896 errors:0 dropped:0 overruns:0 frame:0 TX packets:76896 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:536958400 (512.0 MiB) TX bytes:536958400 (512.0 MiB) virbr0 Link encap:Ethernet HWaddr 52:54:00:92:60:28 inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:100480 errors:0 dropped:0 overruns:0 frame:0 TX packets:147360 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:5763019 (5.4 MiB) TX bytes:222134526 (211.8 MiB)
To enable the network interface
It is used to activate the inactive interface by using the ifconfig command with the interface name.
Example
[root@localhost ~]# ifconfig eth0 up
Now check the status of all network setting, the command is “ ifconfig”
[root@localhost ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 4C:72:B9:98:87:0F
inet addr:192.168.7.251 Bcast:192.168.7.255 Mask:255.255.255.0
inet6 addr: fe80::4e72:b9ff:fe98:870f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:31325989 errors:0 dropped:0 overruns:0 frame:0
TX packets:11123954 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:38693395933 (36.0 GiB) TX bytes:1086249568 (1.0 GiB)
Interrupt:20 Memory:fe400000-fe420000
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:76846 errors:0 dropped:0 overruns:0 frame:0
TX packets:76846 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:536955900 (512.0 MiB) TX bytes:536955900 (512.0 MiB)
virbr0 Link encap:Ethernet HWaddr 52:54:00:92:60:28
inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:100480 errors:0 dropped:0 overruns:0 frame:0
TX packets:147360 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:5763019 (5.4 MiB) TX bytes:222134526 (211.8 MiB)
To assign ip address to an interface
The below command helps to assign the ip address for the specific interface.
Example
[root@localhost ~]# ifconfig eth0 192.168.7.252
Now check the status of all network setting, the command is “ ifconfig eth0”
[root@localhost ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 4C:72:B9:98:87:0F
inet addr:192.168.7.252 Bcast:192.168.7.255 Mask:255.255.255.0
inet6 addr: fe80::4e72:b9ff:fe98:870f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:31364877 errors:0 dropped:0 overruns:0 frame:0
TX packets:11149020 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:38731102002 (36.0 GiB) TX bytes:1091182569 (1.0 GiB)
Interrupt:20 Memory:fe400000-fe420000
To assign the Broadcast address of the interface eth0
The below command is used to change or assign the broadcast ip for specific interface.
Example
[root@localhost ~]#ifconfig eth0 broadcast 192.168.7.254
Now check the status of all network setting, the command is “ ifconfig eth0”
[root@localhost ~]#ifconfig eth0
eth0 Link encap:Ethernet HWaddr 4C:72:B9:98:87:0F
inet addr:192.168.7.252 Bcast:192.168.7.254 Mask:255.255.224.0
inet6 addr: fe80::4e72:b9ff:fe98:870f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:654340 errors:0 dropped:0 overruns:0 frame:0
TX packets:364774 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:666933342 (636.0 MiB) TX bytes:60218546 (57.4 MiB)
Interrupt:20 Memory:fe400000-fe420000
To assign subnet mask of the Network interface
The below command is used to change or assign the subnet mask for specified interface in the command.
Example
[root@localhost ~]#ifconfig eth0 netmask 255.255.224.0
Now check the status of all network setting, the command is “ ifconfig eth0”
[root@localhost ~]# ifconfig eth0
eth0 Link encap:Ethernet HWaddr 4C:72:B9:98:87:0F
inet addr:192.168.7.252 Bcast:192.168.31.255 Mask:255.255.224.0
inet6 addr: fe80::4e72:b9ff:fe98:870f/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:654340 errors:0 dropped:0 overruns:0 frame:0
TX packets:364774 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:666933342 (636.0 MiB) TX bytes:60218546 (57.4 MiB)
Interrupt:20 Memory:fe400000-fe420000
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:76846 errors:0 dropped:0 overruns:0 frame:0
TX packets:76846 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:536955900 (512.0 MiB) TX bytes:536955900 (512.0 MiB)
virbr0 Link encap:Ethernet HWaddr 52:54:00:92:60:28
inet addr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:100480 errors:0 dropped:0 overruns:0 frame:0
TX packets:147360 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:5763019 (5.4 MiB) TX bytes:222134526 (211.8 MiB)
To view the ipv4 information
The below command is used to view the ipv4 information by the following command is ip -4 a
Example
[root@linuxhelp ~]# ip -4 a
lo: < LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
inet 127.0.0.1/8 scope host lo
eth0: < BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast
state UP qlen 1000 inet 192.168.7.252/24 brd 192.168.7.254 scope global eth0
virbr0: < BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue
state UNKNOWN inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
To view the ipv6 information
The below command is used to view the information about ipv6. For example, the command is ip -6 a
Example
[root@linuxhelp ~]# ip -6 a
lo: < LOOPBACK,UP,LOWER_UP> mtu 65536
inet6 ::1/128 scope host valid_lft forever preferred_lft forever valid_lft forever preferred_lft forever
eth0: < BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qlen 1000
inet6 fe80::4e72:b9ff:fe98:870f/64 scope link valid_lft forever preferred_lft forever
To view the specific interface with ip a
The below command is used see the information about specific interface
Example
[root@linuxhelp ~]# ip a show eth0
eth0: < BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast
state UP qlen 1000
link/ether 4c:72:b9:98:87:0f brd ff:ff:ff:ff:ff:ff
inet 192.168.7.13/24 brd 192.168.7.255 scope global eth0
inet6 fe80::4e72:b9ff:fe98:870f/64 scope link
valid_lft forever preferred_lft forever
To change the MAC address of specific network interface
The below command is used to change the MAC address of specific network interface.
Example
[root@linuxhelp Desktop]# ifconfig eth0 hw ether AA:BB:CC:11:22:33
[root@linuxhelp Desktop]# ip a
lo: < LOOPBACK,UP,LOWER_UP> mtu 16436 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 inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
eth0: < BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state
UP qlen 1000 link/ether aa:bb:cc:11:22:33 brd ff:ff:ff:ff:ff:ff
inet 192.168.7.250/24 brd 192.168.7.255 scope global eth0
inet6 fe80::20c:29ff:fed3:19cc/64 scope link valid_lft forever preferred_lft forever
To add new alias to an interface
The below command is used to add new alias to network interface.
Example
[root@linuxhelp Desktop]# ifconfig eth0:0 192.168.7.253
[root@linuxhelp Desktop]# ip a
lo: < LOOPBACK,UP,LOWER_UP> mtu 16436 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
inet6 ::1/128 scope host valid_lft forever preferred_lft forever
eth0: < BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state
UP qlen 1000 link/ether 00:0c:29:d3:19:cc brd ff:ff:ff:ff:ff:ff
inet 192.168.7.250/24 brd 192.168.7.255 scope global eth0
inet 192.168.7.253/24 brd 192.168.7.255 scope global secondary eth0:0
inet6 fe80::20c:29ff:fed3:19cc/64 scope link
valid_lft forever preferred_lft forever
To remove alias to an interface
The below command is used to remove the incorrectly configured alias to the network interface.
Example
[root@linuxhelp Desktop]# ifconfig eth0:0 down
[root@linuxhelp Desktop]# ip a
lo: < LOOPBACK,UP,LOWER_UP> mtu 16436 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 inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
eth0: < BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state
UP qlen 1000 link/ether 00:0c:29:d3:19:cc brd ff:ff:ff:ff:ff:ff
inet 192.168.7.250/24 brd 192.168.7.255 scope global eth0
inet6 fe80::20c:29ff:fed3:19cc/64 scope link
valid_lft forever preferred_lft forever
Comments ( 0 )
No comments available