This article will outline how to display, configure, modify your network interface using ifconfig from the Linux command line.
Most Linux distributions these days have a fancy graphical user interface for changing your system settings, but sometimes you have to get down and dirty and use the command line. In some cases you are just ssh’d into your machine and do not have the option of using your gui.
Here are a set of examples for using ifconfig (depending on your distribution you may have to use sudo or run as root).
1. Display All Interface(s) Information Using ifconfig -a
If you do not know the interface names currently on your system using the -a flag will display all devices.
erik@debian:~$ /sbin/ifconfig -a
eth6 Link encap:Ethernet HWaddr 00:0C:29:5C:8E:E0
inet addr:192.168.3.123 Bcast:192.168.3.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe5c:8ee0/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1047636 errors:0 dropped:0 overruns:0 frame:0
TX packets:1101531 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:152028471 (144.9 MiB) TX bytes:1003430862 (956.9 MiB)
Interrupt:185 Base address:0x2000
eth7 Link encap:Ethernet HWaddr 00:0C:29:5C:8E:EA
inet6 addr: fe80::20c:29ff:fe5c:8eea/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:7456 errors:0 dropped:0 overruns:0 frame:0
TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:984140 (961.0 KiB) TX bytes:468 (468.0 b)
Interrupt:169 Base address:0x2080
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:28841 errors:0 dropped:0 overruns:0 frame:0
TX packets:28841 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:4458291 (4.2 MiB) TX bytes:4458291 (4.2 MiB)
As you can see, on my system I have eth6, eth7, an lo (the loopback) interface. This also displays the type of Link I have, the HWaddr or MAC address of that interface. You may recognize that I am using a VMware virtual machine via the OUI. I currently have IPv6 support, hence the IPv6 address. Among other things, there is also the packet count of received and sent packets and the total byte count. Pretty handy!
2. Display Specific Interface Information Using ifconfig ethX
Lets say you know which interface you want to look at. Execute the command ifconfig eth0 where eth0 is the interface name you want to look at.
erik@debian:~$ /sbin/ifconfig eth6
eth6 Link encap:Ethernet HWaddr 00:0C:29:5C:8E:E0
inet addr:192.168.3.123 Bcast:192.168.3.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe5c:8ee0/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1047863 errors:0 dropped:0 overruns:0 frame:0
TX packets:1101749 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:152082031 (145.0 MiB) TX bytes:1003540856 (957.0 MiB)
Interrupt:185 Base address:0x2000
3. Set The IP Address Of A Specific Interface
Now that you know how to display your interface, you probably want to know how to set the IP address. It is quite easy:
erik@debian:~$ /sbin/ifconfig eth6 192.168.3.100 up
Or if you need to set your network mask as well:
erik@debian:~$ /sbin/ifconfig eth6 192.168.3.100 netmask 255.255.255.0 up
4. Set The MAC Address Of A Specific Interface
To set the MAC address of an interface using ifconfig do the following:
erik@debian:~$ /sbin/ifconfig eth0 hw ether de:ad:be:ef:fe:ed
5. Set the MTU Size For Your Interface
Sometimes you may need to say the maximum transmission unit for your interface, especially if you are part of a virtual lan (vlan). To set the MTU size with ifconfig:
erik@debian:~$ /sbin/ifconfig eth0 mtu 1300 up
6. Clear The IP Address And Bring The Interface Down
To clear the IP address and bring your interface offline execute the command with ifconfig:
erik@debian:~$ /sbin/ifconfig eth0 0.0.0.0 down
7. Create Alias or Virtual Interface With ifconfig:
To make a virtual interface or network alias with ifconfig use the colon. For example, your interface is connected to a network with a switch, and on that switch there are two distinct networks. You can create an alias that will allow you to be on both networks simultaneously.
debian:/home/erik# ifconfig eth6:1 192.168.100.23 up
debian:/home/erik# ifconfig -a
eth6 Link encap:Ethernet HWaddr 00:0C:29:5C:8E:E0
inet addr:192.168.3.123 Bcast:192.168.3.255 Mask:255.255.255.0
inet6 addr: fe80::20c:29ff:fe5c:8ee0/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1048915 errors:0 dropped:0 overruns:0 frame:0
TX packets:1102915 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:152305452 (145.2 MiB) TX bytes:1004365368 (957.8 MiB)
Interrupt:185 Base address:0x2000
eth6:1 Link encap:Ethernet HWaddr 00:0C:29:5C:8E:E0
inet addr:192.168.100.23 Bcast:192.168.100.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
Interrupt:185 Base address:0x2000
To remove the alias just enter:
debian:/home/erik# ifconfig eth6:1 down