15 Useful “ifconfig” Commands to Configure Network Interface in Linux

ens3 Link encap:Ethernet HWaddr 00:0B:CD:1C:18:5A
inet addr:172.16.25.126 Bcast:172.16.25.63 Mask:255.255.255.224
inet6 addr: fe80::20b:cdff:fe1c:185a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2345583 errors:0 dropped:0 overruns:0 frame:0
TX packets:2221421 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:293912265 (280.2 MiB) TX bytes:1044100408 (995.7 MiB)

4. How to Enable a Network Interface

ifconfig ens3 down

ifconfig ens3 down
ifconfig ens3 hw ether AA:BB:CC:DD:EE:FF
ifconfig ens3 up

ifconfig ens3 netmask 255.255.255.224

8. How to Assign a Broadcast Address to a Network Interface

ifconfig (Interface Configuration is a utility for system/network administration in Unix/Linux operating systems used to configure, manage, and query network interface parameters via the command-line interface or in system configuration scripts.
To get more information and options for any of the above tools, see the man pages by entering “man toolname” at the command prompt. For example, to get the information for the “netstat” tool, use the command “man netstat“.
ifconfig ens3 mtu 1000

sudo apt install net-tools #Debian/Ubuntu
sudo dnf install net-tools #RHEL/Fedora

1. How to List All Active Network Interfaces in Linux

To install it, run:
ifconfig ens3 172.16.25.125 netmask 255.255.255.224 broadcast 172.16.25.63

10. How to Change the MTU for a Network Interface

The ifconfig command is used for displaying current network configuration information, setting up an IP address, netmask, or broadcast address to a network interface, creating an alias for a network interface, setting the hardware address, and enabling or disabling network interfaces.
For example, the following command sets the IP address on the ens3 interface.
ifconfig ens3

In normal mode, when a network card receives a packet, it checks whether the packet is addressed to itself. If not, it drops the packet. In promiscuous mode, the network interface accepts all packets flowing through the network, regardless of their destination address.
If you no longer require an alias network interface or configured it incorrectly, you can remove it using the following command.

5. How to Disable a Network Interface

The following ifconfig command with the -a argument will display information on all active or inactive network interfaces on the server. It displays the results for eth0, lo, sit0, and tun0.
Adjusting the MTU is useful in specific network environments, such as when using VPNs or jumbo frames.

6. How to Assign an IP Address to a Network Interface

The down flag with an interface name deactivates the specified network interface,f or example, the ifconfig ens3 down command deactivates the ens3 interface.
For example, the following command sets the netmask on the ens3 interface.
ifconfig ens3:0 172.16.25.127

ifconfig -a

These are the most useful ifconfig commands for configuring network interfaces in Linux. For more information and usage options, refer to the man page by running man ifconfig at the terminal.
To add an alias for the ens3 interface, use the following command, but do note that the alias IP address must be within the same subnet as the primary IP address.
ifconfig ens3 up

For example, if your primary IP is 172.16.25.125, a valid alias would be 172.16.25.127.
You might also like:
ifconfig ens3 broadcast 172.16.25.63

9. How to Assign an IP Address, Netmask, and Broadcast Address Together

ens3:0 Link encap:Ethernet HWaddr 00:01:6C:99:14:68
inet addr:172.16.25.127 Bcast:172.16.25.63 Mask:255.255.255.224
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1

ifconfig ens3 -promisc

13. How to Add an Alias to a Network Interface

Using the ifconfig command with the netmask argument and an interface name allows you to define a subnet mask for the given interface.
For example, ifconfig ens3 up will activate the ens3 interface.
Since ifconfig is deprecated on most modern Linux distributions, it is worth familiarizing yourself with the ip command as the recommended replacement for managing network interfaces going forward.
ifconfig

eth0 Link encap:Ethernet HWaddr 00:0B:CD:1C:18:5A
inet addr:172.16.25.126 Bcast:172.16.25.63 Mask:255.255.255.224
inet6 addr: fe80::20b:cdff:fe1c:185a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2344927 errors:0 dropped:0 overruns:0 frame:0
TX packets:2220777 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:293839516 (280.2 MiB) TX bytes:1043722206 (995.3 MiB)
Interrupt:185 Memory:f7fe0000-f7ff0000

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:16436 Metric:1
RX packets:5022927 errors:0 dropped:0 overruns:0 frame:0
TX packets:5022927 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2175739488 (2.0 GiB) TX bytes:2175739488 (2.0 GiB)

sit0 Link encap:IPv6-in-IPv4
NOARP MTU:1480 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)

tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:10.1.1.1 P-t-P:10.1.1.2 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP 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:100
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)

3. How to View Network Settings of a Specific Interface

To enable promiscuous mode on an interface, use the following command.
In this article, you will learn how to list, configure, enable, disable, and troubleshoot network interfaces in Linux using 15 useful ifconfig commands with practical examples.
ifconfig ens3:0

Network monitoring and packet analysis tools such as tcpdump and Wireshark rely on promiscuous mode to capture traffic.

14. How to Remove an Alias from a Network Interface

For example, the following command sets the MTU to 1000 on the ens3 interface.
ens3 Link encap:Ethernet HWaddr 00:0B:CD:1C:18:5A
inet addr:172.16.25.126 Bcast:172.16.25.63 Mask:255.255.255.224
inet6 addr: fe80::20b:cdff:fe1c:185a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2341604 errors:0 dropped:0 overruns:0 frame:0
TX packets:2217673 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:293460932 (279.8 MiB) TX bytes:1042006549 (993.7 MiB)

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:5019066 errors:0 dropped:0 overruns:0 frame:0
TX packets:5019066 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2174522634 (2.0 GiB) TX bytes:2174522634 (2.0 GiB)

tun0 Link encap:UNSPEC HWaddr 00-00-00-00-00-00-00-00-00-00-00-00-00-00-00-00
inet addr:10.1.1.1 P-t-P:10.1.1.2 Mask:255.255.255.255
UP POINTOPOINT RUNNING NOARP 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:100
RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)

ifconfig ens3 promisc

12. How to Disable Promiscuous Mode on a Network Interface

ifconfig ens3:0 down

15. How to Change the MAC Address of a Network Interface

ifconfig ens3 172.16.25.125

To assign an IP address to a specific interface, use the ifconfig command with the interface name and the IP address you want to set.

Similar Posts