Ifconfig

From LQWiki
Jump to: navigation, search

ifconfig is short for Interface Configuration, the UNIX command for configuring a network interface. Usually given in the form of ifconfig interface name -options

  ifconfig eth0 192.168.0.1 netmask 255.255.255.0

Just typing ifconfig will show information of all the currently configured network interfaces.

Uses for ifconfig

Discovering your MAC address

You can generally find your MAC address with ifconfig

# /sbin/ifconfig eth0
eth0     Link encap:Ethernet  HWaddr 00:90:F5:03:4B:69
         inet addr:192.168.0.2  Bcast:192.168.0.255  Mask:255.255.255.0
         inet6 addr: fe80::290:f5ff:fe03:4b69/64 Scope:Link
         UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
         RX packets:911573 errors:0 dropped:0 overruns:0 frame:0
         TX packets:656393 errors:0 dropped:0 overruns:0 carrier:0
         collisions:0 txqueuelen:1000
         RX bytes:604721438 (576.7 Mb)  TX bytes:58964684 (56.2 Mb)
         Interrupt:10 Base address:0xf000

The entry "HWaddr" on the first line tells the hardware address for your network card.

Set up two IPs on one interface

To set up an additional ip address on one NIC, issue

ifconfig eth0:0 192.168.0.1

This will set up the additional ip address 192.168.0.1 on your network device eth0.

Changing the address

In Linux the MAC address can be changed with most network card drivers. This can be useful in cases where there is security based on MAC addresses and you get a new network card. Example to change it:

# ifconfig eth0 hw ether 00:00:00:00:00:00

This just changes it in the software drivers, not the actual MAC address on the hardware (so it has to be done after every boot). Some on-board network cards allow the address to be changed in the BIOS.

See also