- Ifconfig Command in Linux
- Ifconfig Command Syntax
- 1) Display All network interface information
- 2) Enable or disable the network interface
- 3) Assign IP address and Netmask to network interface
- 4) Set IPV6 Address to network interface
- 5) How to Enable ARP protocol
- 6) How to Disable ARP protocol
- 7) Change MAC address of interface
- 8) How to enable Promiscuous mode
- 9) Changing the MTU
- 10) Add Alias to network interface
- Conclusion
- Linux networking: ifconfig versus ip
- More Linux resources
- Linux ifconfig command
- Description
- Viewing the configuration of all interfaces
- Viewing the configuration of a specific interface
- Enabling and disabling an interface
- Configuring an interface
- What about DHCP?
- Syntax
- Technical description
- About address families
- Options
- Examples
- Related commands
Ifconfig Command in Linux
The word ‘ifconfig’ stands for interface configuration. Ifconfig is used in Linux and Unix systems to debug, configure and manage network interfaces from the terminal.
Using ifconfig command you can assign IP address and netmask, display network configuration (including broadcast address, mac address, MTU), enable or disable an interface.
In this tutorial, we learn about ifconfig command and how to set different parameters on network interface.
Ifconfig Command Syntax
Let’s check ifconfig command syntax
We will explain the different options of ifconfig command in the following section.
1) Display All network interface information
If you run ifconfig command without any options it will give you the status of all interfaces which are in up status. From the output, we can find the assigned IP address and also many other interface details.
The following output shows ifconfig without any options:
If you want to see all interfaces information (including status up and down) then you have to use -a option.
You can check specific interface (say eth0) details using below command:
To display a short list use -s option.
Note: If you looking for MAC address binded to that interface you can find from the ifconfig output.
2) Enable or disable the network interface
For troubleshooting or debugging some system admin have to enable or disable the interface. The following command shows to enable and disable specific interface.
To enable interface eth0 run the following command:
To disable interface eth0 run the following command:
3) Assign IP address and Netmask to network interface
To assign IP address to an interface (eth0), use IP address followed by a specific interface name.
The following command set IP address ‘192.168.1.30’ to the interface ‘eth0’. The second command set netmask ‘255.255.255.0’ to ‘eth0’ interface.
You can set both IP address and netmask using one command. The following example configures eth0 with ip address ‘192.168.1.30’ with netmask ‘255.255.255.0’.
If you looking to set broadcast IP on the interface, use ‘ifconfig eth0 broadcast 192.168.1.32’ as shown below:
4) Set IPV6 Address to network interface
To add ipv6 address to a interface (etho) use the following syntx:
5) How to Enable ARP protocol
ARP stands for the address resolution protocol, it is used for resolution of network layer addresses into link layer addresses.
To enable arp on eth0 interface, use the following command:
6) How to Disable ARP protocol
To disable ARP on eth0 interface you have to add a hyphen ( — ) before arp option.
7) Change MAC address of interface
In order to change the MAC address, you should first disable the interface (NIC) and also make sure the hardware vendor supports this function. Alternative commands to change mac address are ip command and ‘macchanger’ utility.
The following command will change the MAC address for the interface (eth0) using the option hw ether .
8) How to enable Promiscuous mode
In promiscuous mode is a mode of operation in which every data packet transmitted can be received and read by a network adapter. The promisc mode is mostly enabled to monitor network card traffic via tcpdump command or Wireshark.
The following command set eth0 in promiscuous mode:
To disable promiscuous mode use -promisc as following:
9) Changing the MTU
MTU stands for Maximum Transmission Unit, it is the size of the largest block of data that can be transmitted as a single unit, the default value is 1500, you can change it as the below example
10) Add Alias to network interface
You can create additional logical network interfaces known as alias using ifconfig command. The following command set alias interface (eth0:0) and new ip address (192.168.1.31).
You can delete alias by bringing down the interface as shown below:
Conclusion
In this tutorial, we learned how to use ifconfig command in Linux to view and set interface parameters. Ifconfig is one of the deprecated command within net-tools that has not been maintained for many years. The functionalities of many commands is retained with more features under iproute2 suite.
Источник
Linux networking: ifconfig versus ip
More Linux resources
What was the first Linux networking command that you learned? If I were a betting man, I would wager that many of you (like myself) learned how to look at your IP address and ethernet configurations. I would also wager that an overwhelming majority of Linux users first learned to do so via the ifconfig command.
Interface Configuration, a.k.a. ifconfig , has to be one of the most used Linux commands of all time, and it’s pretty plain to see why. It’s easy to remember (unless you are coming from a Windows environment), and it displays most, if not all, of the necessary networking information for a huge number of use cases.
On the other hand, we have the ip command suite. This command-line tools package is the new kid on the block, relatively speaking, and has been chosen as the way forward by the bleeding edge of Linux users. With added functionality and a steadily growing user base, the ip command is a serious contender for your muscle memory or aliases.
So let’s take a look at these two commands to see what is on the ip command suite offers.
You know your favorite ball cap? The one that has the sweat stains inside the headliner, but throwing it on just feels right? That’s ifconfig . It’s safe, it’s familiar, and you feel comfortable using it. The ifconfig command still has a lot to offer its users. Whether its displaying network settings, configuring an IP address or netmask, creating aliases for interfaces, or setting MAC address, ifconfig can handle it. Let’s take a look at how to use ifconfig to accomplish some more common tasks you may find yourself working on completing.
Displaying current network settings
This is the most basic and overused form of the ifconfig command. Chances are, you are running this to get information about a particular interface, and while this works, it will probably over-deliver. Let’s look at the syntax and output and see where we could improve our I/O.
As you can see, there is a lot of information to sift through here. ifconfig , devoid of any arguments or options, will list all active interfaces with detail. So how can we narrow it down to exactly what we want? Many times you just want to look at a specific interface.
Display entries for specific interface
To view details for a specific interface, use the standard ifconfig command followed by the interface name. For example:
Enabling and disabling an interface
With the ifconfig command, you can do far more than just view configurations. Let’s take a look at how to enable and disable an interface.
To enable an interface, you have two options for syntax:
The same goes for disabling an interface. Only instead of up we use down , as seen here:
In this line of work, it really doesn’t get much easier than that.
Assigning an IP address to an interface
To assign an IP address to a given interface, you use the following syntax:
Assigning a netmask to an interface
To assign a netmask to an interface, you use the following:
It should look like this:
Set MTU for an interface
The MTU or Maximum Transmission Unit is a very important figure to pay attention to during troubleshooting. This value allows you to limit the size of packets sent over the specific interface. I once worked a data replication failure for over three weeks before figuring out that the MTU was too large for the replication interface. Fun times *insert eye roll here*. I say this to make a point. Not every network interface can support jumbo packets. Be sure that the set MTU is supported for your interface. To set the MTU:
There is a lot more that ifconfig can do; however, in the interest of brevity, I am going to move along. If you want more information on ifconfig , check out the man page or your friendly neighborhood search engine.
[ Getting started with networking? Check out the Linux networking cheat sheet. ]
The ip command is the future of network config commands. ifconfig has been officially deprecated for the ip suite, so while many of us are still using the old ways, it is time to put those habits to rest and move on with the world.
Since there is no «without options» variant of the ip command, let’s look at how to display IP addresses associated with interfaces.
You will notice that this presents much of the same information as the base ifconfig command.
Adding a new address
To add an IP address to an existing interface, use the following:
The dev flag is used before designating which device or interface that the IP address is being set on.
Removing an address
To remove an IP address from an interface, use the following:
Enable and disable an interface
Much like the ifconfig command, you can also cycle an interface on/off using the ip command. To enable an interface, use the following:
View the routing table
One of the best things you can use while troubleshooting is to view routing information. To do this, use the following:
You can also add and remove static routes from the routing table.
To add a static route, we use the following:
To remove a static route, we use the following:
Note that these are not persistent, and you must take additional steps to ensure that the routes created actually survive a reboot. To create the persistent route, we need to create an entry in /etc/sysconfig/network-scripts/route-eth0 (substitute eth0 with whatever interface the route is created on). Something like this:
Over before it began
This article is not so much a fight between the two as it is an exploration of old and new. The decision has already been made, as ifconfig is being deprecated. The ip command suite is the way forward. However, just because something is new doesn’t mean it is superior for every purpose. At the same time, however, «we’ve always done it this way» is not an excuse to stop improving. What are your thoughts? My honest takeaway is that ifconfig meets most of my needs (at this point in my career). However, the ip command is a more powerful tool and will be a staple for networking experts for years to come.
[ Want more for your network? Download a free ebook on network automation with Ansible. ]
Источник
Linux ifconfig command
On some Unix-like operating systems, ifconfig is used to configure, or view the configuration of, a network interface.
This page covers the GNU/Linux version of ifconfig.
On modern Linux systems, the ip command has replaced ifconfig.
Description
ifconfig stands for «interface configuration.» It is used to view and change the configuration of the network interfaces on your system.
Running the ifconfig command with no arguments, like this:
. displays information about all network interfaces currently in operation. The output resembles the following:
Here, eth0, lo and wlan0 are the names of the active network interfaces on the system.
- eth0 is the first Ethernet interface. (Additional Ethernet interfaces would be named eth1, eth2, etc.) This type of interface is usually a NIC connected to the network by a category 5 cable.
- lo is the loopback interface. This is a special network interface that the system uses to communicate with itself.
- wlan0 is the name of the first wireless network interface on the system. Additional wireless interfaces would be named wlan1, wlan2, etc.
These are the traditional naming conventions for network interfaces under Linux; other operating systems may have different names. For instance, under many BSD operating systems, Ethernet interfaces are named em0, em1, etc. Check your configuration, or consult your documentation, to determine the exact names of your interfaces.
Viewing the configuration of all interfaces
If you’d like to view the configuration of all network interfaces on the system (not just the ones that are currently active), you can specify the -a option, like this:
This produces output similar to running ifconfig, but if there are any inactive interfaces on the system, their configuration is also shown.
Viewing the configuration of a specific interface
To view the configuration of a specific interface, specify its name as an option. For instance,
. displays the configuration of device eth0 only.
Enabling and disabling an interface
When a network interface is active, it can send and receive data; when it is inactive, it is not able to transmit or receive. You can use ifconfig to change the status of a network interface from inactive to active, or vice versa.
To enable an inactive interface, provide ifconfig with the interface name followed by the keyword up.
Enabling or disabling a device requires superuser permissions, so you either have to be logged in as root, or prefix your command with sudo to run it with superuser privileges.
For instance, if network interface eth1 is inactive, you can activate it with the command:
Similarly, you can disable an active network interface using the down keyword. For instance, to disable the wireless network interface wlan0, use the command:
Configuring an interface
ifconfig can be used at the command line to configure (or re-configure) a network interface. This is often unnecessary since this configuration is often handled by a script when you boot the system. If you’d like to do so manually, you need superuser privileges, so we’ll use sudo again when running these commands.
To assign a static IP address to an interface, specify the interface name and the IP address. For example, to assign the IP address 69.72.169.1 to the interface wlan0, use the command:
To assign a network mask to an interface, use the keyword netmask and the netmask address. For instance, to configure the interface eth1 to use a network mask of 255.255.255.0, the command would be:
To assign a broadcast address to an interface, use the keyword broadcast and the broadcast address. For instance, to configure the interface wlan1 to use a broadcast address of 172.16.25.98, the command would be:
These configurations can combined in a single command. For instance, to configure interface eth0 to use the static IP address 192.168.2.5, the network mask 255.255.255.0, and the broadcast address 192.168.2.7, the command would be:
These are the most commonly-used configuration options for ifconfig. A complete list is provided below.
What about DHCP?
ifconfig can only assign a static IP address to a network interface. If you want to assign a dynamic IP address using DHCP, use the dhclient command.
Syntax
Technical description
ifconfig is used to configure the system’s 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 system’s 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» (inactive).
In all other cases, ifconfig configures an interface according to the options provided.
About address families
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, inet (TCP/IP; this is the default), inet6 (IPv6), ax25 (AMPR Packet Radio), ddp (Appletalk Phase 2), ipx (Novell IPX) and netrom (AMPR Packet Radio).
Options
-a | Display information for all network interfaces, even if they are down. |
-s | Display a short list in a format identical to the command «netstat -i«. |
-v | Verbose mode; display additional information for certain error conditions. |
interface | The name of the interface. This is usually a driver name followed by a unit number, for example «eth0» for the first Ethernet interface. If your kernel supports alias interfaces, you can specify them with eth0:0 for the first alias of eth0. You can use them to assign a second address. To delete an alias interface, use ifconfig eth0:0 down. Note: for every scope (i.e., same net with address/netmask combination) all aliases are deleted, if you delete the first (primary). |
up | This flag causes the interface to be activated. It is implicitly specified if an address is assigned to the interface. |
down | This flag causes the driver for this interface to be shut down. |
[—]arp | Enable (or disable, if the «—» prefix is specified) the use of the ARP protocol on this interface. |
[—]promisc | Enable (or disable, if the «—» prefix is specified) the promiscuous mode of the interface. If promiscuous mode is enabled, all packets on the network will be received by the interface. |
[—]allmulti | Enable or disable all-multicast mode. If multicast mode is enabled, all multicast packets on the network will be received by the interface. |
metric N | This parameter sets the interface metric, which is used by the interface to make routing decisions. N must be an integer between 0 and 4294967295. If you’re not sure what a network metric is, or whether to change it, you can safely leave this setting alone. |
mtu N | This parameter sets the MTU (maximum transfer unit) of an interface. This setting is used to limit the maximum packet size transferred by the interface. If you’re not sure about it, you can safely leave this setting alone. |
dstaddr address | Set the remote IP address for a point-to-point link (such as PPP). This keyword is now obsolete; use the pointopoint keyword instead. |
netmask address | Set the IP network mask for this interface. This value defaults to the usual class A, B or C network mask (as derived from the interface IP address), but it can be set to any value. |
add address/prefixlen | Add an IPv6 address to an interface. |
del address/prefixlen | Remove an IPv6 address from an interface. |
tunnel aa.bb.cc.dd | Create a new SIT (IPv6-in-IPv4) device, tunnelling to the given destination. |
irq address | Set the interrupt line used by this device. Not all devices can dynamically change their IRQ setting. |
io_addr address | Set the start address in I/O space for this device. |
mem_start address | Set the start address for shared memory used by this device. Only a few devices need this. |
media type | Set the physical port or medium type to be used by the device. Not all devices can change this setting, and those that can vary in what values they support. Typical values for type are 10base2 (thin Ethernet), 10baseT (twisted-pair 10 Mbps Ethernet), AUI (external transceiver), etc. The special medium type of auto tells the driver to auto-sense the media. Again, not all drivers can do this. |
[—]broadcast [address] | If the address argument is given, this sets the protocol broadcast address for this interface. Otherwise, it sets (or clear, if the «—» prefix is used) the IFF_BROADCAST flag for the interface. |
[—]pointopoint [address] | This keyword enables the point-to-point mode of an interface, meaning that it is a direct link between two machines with nobody else listening on it. If the address argument is also given, set the protocol address of the other side of the link, just like the obsolete dstaddr keyword does. Otherwise, set or clear the IFF_POINTOPOINT flag for the interface. |
hw class address | Set the hardware address of this interface, if the device driver supports this operation. The keyword must be followed by the name of the hardware class and the printable ASCII equivalent of the hardware address. Hardware classes currently supported include ether (Ethernet), ax25 (AMPR AX.25), ARCnet and netrom (AMPR NET/ROM). |
multicast | Set the multicast flag on the interface. This should not normally be needed as the drivers set the flag correctly themselves. |
address | The IP address to be assigned to this interface. |
txqueuelen length | Set the length of the transmit queue of the device. It is useful to set this to small values for slower devices with a high latency (such as a connection over a modem, or over ISDN) to prevent fast bulk transfers from disturbing interactive traffic like telnet too much. |
Examples
Running ifconfig with no options displays the configuration of all active interfaces.
Displays the configuration of all interfaces, both active and inactive.
View the network settings on the interface eth0, which (under Linux) is the first Ethernet adapter installed in the system.
Activate the network interface eth1.
Deactivate the network interface wlan0.
Configure the network interface wlan1 to use the static IP address 122.140.201.66.
Configure the network interface wlan0 to use the network mask 255.255.255.0.
Configure eth0 to use the static IP address 192.168.1.102 using the network mask 255.255.255.0, and the broadcast address 192.168.1.255.
Related commands
arp — Manipulate the system ARP cache.
dhclient — Communicate with a DHCP server to obtain a dynamic IP address.
ifup/ifdown — Enable/Disable a network interface.
ifquery — Parse information about a network interface.
ip — Display and manipulate information about routing, devices, policy routing and tunnels.
iwconfig — Configure a wireless network interface.
ping — Send ICMP ECHO_REQUEST packets to network hosts.
netstat — Print information about network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.
route — Display and manipulate the IP routing table.
Источник