Learn to Configure a Network Interface in linux by “ifconfig”
In this article we are learning how to configure a Network Interface in linux operating system with the use command call “Interface Configuration” in short “ifconfig” .
The “ifconfig” command is used for displaying current network configuration information, setting up an ip address, netmask or broadcast address to an network interface, creating an alias for network interface, setting up hardware address and enable or disable network interfaces.
1. View All Network Setting
For checking the network setting we are using command called “ifconfig”
The “ifconfig” command with no arguments will display all the active interfaces details. The ifconfig command also used to check the assigned IP address of an server.
2. Display Information of All Network Interfaces
The following ifconfig command with -a argument will display information of all active or inactive network interfaces on server. It displays the results for enp0s3, lo, virbr0 and virbr0-nic.
3. View Network Settings of Specific Interface
Using interface name (enp0s3) as an argument with “ifconfig” command will display details of specific network interface.
4. How to Enable an Network Interface
The “up” or “ifup” flag with interface name (enp0s3) activates an network interface, if it is not in active state and allowing to send and receive information. For example, “ifconfig enp0s3 up” or “ifup enp0s3” will activate the enp0s3 interface.
#ifconfig enp0s3 up
5. How to Disable an Network Interface
The “down” or “ifdown” flag with interface name (enp0s3) deactivates the specified network interface. For example, “ifconfig enp0s3 down” or “ifdown enp0s3” command deactivates the enp0s3 interface, if it is in active state.
#ifconfig enp0s3 down
6. How to Assign a IP Address to Network Interface
To assign an IP address to an specific interface, use the following command with an interface name (enp0s3) and ip address that you want to set.
For example, “ifconfig enp0s3 18.104.22.168” will set the IP address to interface enp0s3.
#ifconfig enp0s3 22.214.171.124
7. How to Assign a Netmask to Network Interface
Using the “ifconfig” command with “netmask” argument and interface name as (enp0s3) allows you to define an netmask to an given interface.
For example, “ifconfig enp0s3 netmask 255.255.255.224” will set the network mask to an given interface enp0s3.
#ifconfig enp0s3 netmask 255.255.255.224
8. How to Assign a Broadcast to Network Interface
Using the “broadcast” argument with an interface name will set the broadcast address for the given interface.
For example, “ifconfig enp0s3 broadcast 172.16.25.65” command sets the broadcast address to an interface enp0s3.
#ifconfig enp0s3 broadcast 172.16.25.65
9. How to Assign a IP, Netmask and Broadcast to Network Interface
To assign an IP address, Netmask address and Broadcast address all at once using “ifconfig” command with all arguments as given below.
#ifconfig enp0s3 172.16.25.125 netmask 255.255.255.224 broadcast 172.16.25.65
10. How to Change MTU for an Network Interface
The “mtu” argument set the maximum transmission unit to an interface. The MTU allows you to set the limit size of packets that are transmitted on an interface. The MTU able to handle maximum number of octets to an interface in one single transaction.
For example, “ifconfig eth0 mtu 1000” will set the maximum transmission unit to given set
(i.e. 1000). Not all network interfaces supports MTU settings.
#ifconfig enp0s3 mtu 1000
11. How to Enable Promiscuous Mode
What happens in normal mode, when a packet received by a network card, it verifies that the packet belongs to itself. If not, it drops the packet normally, but in the promiscuous mode is used to accept all the packets that flows through the network card.
Most of the today’s network tools uses the promiscuous mode to capture and analyze the packets that flows through the network interface. To set the promiscuous mode, use the following command.
#ifconfig enp0s3 promisc
12. How to Disable Promiscuous Mode
To disable promiscuous mode, use the “-promisc” switch that drops back the network interface in normal mode.
#ifconfig enp0s3 -promisc
from all these ifconfig commands we are easily setup and network configuration in linux systems.