Ifconfig 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 only needed when debugging or when system tuning is needed.
If no arguments are given, ifconfig displays the status of the currently active interfaces. If a single interface argument is given, it displays the status of the given interface only; if a single -a argument is given, it displays the status of all interfaces, even those that are down. Otherwise, it configures an interface.
Newer Linux operating systems such as Debian 9 and incarnations of Arch Linux may not have ifconfig installed. The developers have deprecated it in favor of 'ip' command. It is still possible to install ifconfig by installing the ‘net-tools’ package using your distribution’s package manager.
If the first argument after the interface name is recognized as the name of a supported address family, that address family is used for decoding and displaying all protocol addresses. Currently supported address families include:
# ifconfig [-v] [-a] [-s] interface options | address
Note: You must be root (or have permissions) to use ifconfig.
# ifconfig interface
Displays the configuration of a specific interface:
# ifconfig -s
Displays a short list:
$ ip address
NOTE: ‘ip address’ can be shortened to ‘ip addr’ or ‘ip a’.
This command is the iproute counterpart to the previous ifconfig command. Like the last command, it shows the IPv4 and IPv6 addresses, the MTU, broadcast, and flags associated with each interface. If the -s parameter is included in the command (ip -s address), information about transmitted packets will be included in the output as well. Including -s twice (ip -s -s address) will reveal more information about packet transmission.
Displays all interfaces which are currently available, even if down:
$ ip address
$ sudo ifconfig enp0s3 up
We just took the ethernet connection up. If we run ‘ifconfig’ with no parameters this interface will not show on the list as it has been deactivated.
An ethernet connection is possible again using this device. This is the iproute equivalent:
$ sudo ip link set enp0s3 up
$ sudo ifconfig enp0s3 down
This is the iproute equivalent of deactivating an interface.
$ sudo ip link set enp0s3 down
We just took the ethernet connection down. If we run ‘ifconfig’ with no parameters this interface will not show on the list as it has been deactivated.
Whenever a network interface is deactivated, the driver controlling the device is shut down so the system cannot use it. It will still know that the device is there and you can start the driver by activating said network device.
# ifconfig -v
Be more verbose for some error conditions:
# ifconfig interface [-]arp
Advanced ifconfig Commands
Advanced actions can, of course, be performed using ifconfig and ip. These are just a few examples of such actions. Toggling promiscuous mode, creating aliases for interfaces, and setting IP addresses, are just a few examples that also require superuser privileges to carry out on the command-line.
Enable or disable the use of the ARP protocol on this interface:
# ifconfig interface arp
# ifconfig interface -arp
By default, an interface has this feature turned off. Normally an interface receives only the packets intended for that interface. Turning on promiscuous mode (if the network device supports it) will have the interface accept all incoming packets on the network. Promiscuous mode is used for packet sniffing, mostly for diagnosing network connectivity problems.
To see if an interface has promiscuous mode turned on: look for the “PROMISC” keyword in the output of ‘ifconfig’ relating to that interface.
Enable the promiscuous mode of the interface:
$ sudo ifconfig enp0s3 promisc
Disable the promiscuous mode of the interface:
$ sudo ifconfig enp0s3 -promisc
ifconfig Equivalent to iproute for managing promiscuous mode
As with ifconfig, to see if an interface has promiscuous mode turned on, look for “PROMISC” keyword in the output of ‘ip address’ to see if the interface is in promiscuous mode.
To enable, run:
$ sudo ip link set enp0s3 promisc on
To disable, run:
$ sudo ip link set enp0s3 promisc off
Enable or disable all-multicast mode:
# ifconfig interface allmulti
# ifconfig interface -allmulti
Setting Static IP Addresses
This step isn’t necessary if you are running a DHCP client (such as dhclient on Linux) to fetch IP addresses, which is usually the case. If you do need to assign a static IP address to a network interface it is a very simple task.
$ sudo ifconfig enp0s3 10.0.2.15
Or for iproute -
$ sudo ip address add 10.0.2.15/24 dev enp0s3
Creating “aliases” is really simply assigning another IP address to an interface. There are situations where this is desired. To do so with ifconfig, run this:
$ sudo ifconfig enp0s3:0 10.0.2.16
You can have multiple addresses assigned to an interface.
$ sudo ifconfig enp0s3:1 10.0.2.17
To remove an alias:
$ sudo ifconfig enp0s3:0 down
If any other aliases were created after enp0s3:0 (e.g. enp0s3:1 and enp0s3:2), then those will be removed too.
$ sudo ip address add 10.0.2.16/24 dev enp0s3
$ sudo ip address delete 10.0.2.16/24 dev enp0s3
Keep in mind that these IP addresses will disappear anyway once the computer is shut down. Place these commands for assigning multiple IPv4 addresses to one device in a startup script if you want to have such configurations after shutting down.
Most common ifconfig Commands
Listing network interfaces and detailed information about them, activating and deactivating network devices are basically the most common uses for ifconfig and the ‘ip’ command.
Show Active Interfaces
This simply lists all of the network interfaces that are currently active. Information from each entry includes the MAC address of the device (HWaddr) except for the local loopback interface (lo), number of packets transmitted, how many errors occurred when transmitting these packets, the Maximum Transfer Unit (MTU) of each interface, and flags shown for a device (such as UP and BROADCAST). If online (up), the IPv4 (inet addr) and IPv6 (inet6 addr) addresses assigned to the device are shown as well as the broadcast and netmask addresses.
For a shortened version run ‘ifconfig -s’.
This command is the iproute equivalent to running ‘ifconfig’.
$ ip address show up
Show a Single Interface
If you only want information from a single interface, use its device name (e.g. eth0) as a parameter:
$ ifconfig enp0s3
Or using ‘ip’:
$ ip address show enp0s3
You can use ifconfig (part of the net-tools package) to manage connections via different interfaces, be they ethernet or wireless, and find information from the network devices. With it, and ‘ip’, you can connect and disconnect interfaces, allow for packet sniffing and diagnostics, and assigning IP addresses to an interface, if necessary. Many of these are quite simple using the terminal. On newer Linux systems, ‘ip’ from the iproute toolkit is preferred over ‘ifconfig’, even though ifconfig will still be used for some time on Linux, and other UNIX-based systems.
Most Read Articles
Translate Our Site
Notice : Please be careful, after translation commands will change.
This website uses marketing and tracking technologies. Opting out of this will opt you out of all cookies, except for those needed to run the website. Note that some products may not work as well without tracking cookies.Opt Out of Cookies