logo

Practical Computing Advice and Tutorials

Sun: 26 May 2019


Site Content

Programming
&
Development


Technical Knowhow


Command Line Interface


Security

Linux | Ifconfig

The ifconfig (interface configuration) command can be used to simply find the LAN IP address of the machine. Used without any arguments, it simply outputs the interface configuration of any active, known as up, interfaces the computer has, but the command is also used to control said interfaces and is a very useful tool.

Run the command and you'll see an output similar to this...

:~$ ifconfig
eth0     Link encap:Ethernet HWaddr 00:1c:23:36:0d:ff
         inet addr:192.168.0.4 Bcast:192.168.0.255 Mask:255.255.255.0
         inet6 addr: fe80::21c:23ff:fe36:dff/64 Scope:Link
         UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
         RX packets:138 errors:0 dropped:0 overruns:0 frame:0
         TX packets:130 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:1000
         RX bytes:14883 (14.8 KB) TX bytes:20189 (20.1 KB)
         Interrupt:17

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:160 errors:0 dropped:0 overruns:0 frame:0
         TX packets:160 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:0
         RX bytes:11840 (11.8 KB)
         TX bytes:11840 (11.8 KB)

To see inactive interfaces, known as down, we need include the -a switch, which means all, like this...

:~$ ifconfig -a
eth0     Link encap:Ethernet HWaddr 00:1c:23:36:0d:ff
         inet addr:192.168.0.4 Bcast:192.168.0.255 Mask:255.255.255.0
         inet6 addr: fe80::21c:23ff:fe36:dff/64 Scope:Link
         UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
         RX packets:138 errors:0 dropped:0 overruns:0 frame:0
         TX packets:130 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:1000
         RX bytes:14883 (14.8 KB) TX bytes:20189 (20.1 KB)
         Interrupt:17

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:160 errors:0 dropped:0 overruns:0 frame:0
         TX packets:160 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:0
         RX bytes:11840 (11.8 KB)
         TX bytes:11840 (11.8 KB)

wlan0    Link encap:Ethernet HWaddr 00:1f:3c:2c:d3:04
         BROADCAST 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:1000
         RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

Now we can see that there's also a wlan0 interface, which is a Wireless LAN (Wi-Fi) interface, but because it's down, it didn't show before.

To bring that interface up, we need sys admin privileges. Prefixing any command with sudo grants a temporary escalation to admin privileges, after providing a valid admin password.

If you get an output like this...

:~$ sudo ifconfig wlan0 up
[sudo] password for rob:
SIOCSIFFLAGS: Operation not possible due to RF-kill
:~$

... it's likely that the computer has an external switch that puts the computer into a so-called flight mode or Aeroplane Mode, which simply means that the radio transceiver is disabled, which is a common feature with portable computers. There'll be a switch or a button somewhere on the machine which we'll need to find so that we can enable the radio transceiver. Another thing to check with Linux systems that are running a DTE is that this option could also be in a control panel, which may look something like this...

WiFi Setting Dialogue Box

Having done that and re-entered the command, no output is seen, but if we again issue a ifconfig command, we'll see that the wlan0 interface is now displayed and as such is 'up'.

:~$ sudo ifconfig wlan0 up
:~$
:~$ ifconfig
eth0     Link encap:Ethernet HWaddr 00:1c:23:36:0d:ff
         inet addr:192.168.0.4 Bcast:192.168.0.255 Mask:255.255.255.0
         inet6 addr: fe80::21c:23ff:fe36:dff/64 Scope:Link
         UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
         RX packets:138 errors:0 dropped:0 overruns:0 frame:0
         TX packets:130 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:1000
         RX bytes:14883 (14.8 KB) TX bytes:20189 (20.1 KB)
         Interrupt:17

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:160 errors:0 dropped:0 overruns:0 frame:0
         TX packets:160 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:0
         RX bytes:11840 (11.8 KB)
         TX bytes:11840 (11.8 KB)

wlan0    Link encap:Ethernet HWaddr 00:1f:3c:2c:d3:04
         BROADCAST 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:1000
         RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

As you can probably guess, we can also deactivate an interface with the down option and before changing the parameters of an interface, it should be first taken down.

ifconfig wlan0 192.168.1.200 will assign that static ip address and a standard mask to the wlan0 interface and bring it up.

Be careful, as this could interrupt a ssh session. e.g: if the remote machine is using wlan1 and you 'bring up' wlan0, the remote machine may switch to wlan0 thus terminating the wlan1 connection

A network mask can be assigned with ifconfig wlan0 netmask 255.255.255.0

A broadcast address can be assigned with ifconfig wlan0 broadcast 192.168.1.255

These configurations can be combined in a single command...

ifconfig wlan0 192.168.1.200 netmask 255.255.255.0 broadcast 192.168.1.255

Remember, you'll need to prefix some commands with sudo if the admin privilege is required.

I'll be covering the netmask in more detail when I get around to posting about subnetting {Update:~ that page is now done}, so for now, just know that your netmask will be 255.255.255.0 unless your LAN is already divided into subnets.

ifconfig can only assign a static IP address to a network interface. If you want to assign a dynamic IP address using DHCP, you should use the dhclient command, which is fine for a 'eth' interface, but for a 'wlan' interface, we'll need to gather some more information and I'll have to write a new tutorial.