Linux Networking How-To/Configuring a network interface.

From Wikibooks, the open-content textbooks collection

Jump to: navigation, search

When you have all of the programs you need and your address and network information you can configure your network interfaces. When we talk about configuring a network interface we are talking about the process of assigning appropriate addresses to a network device and to setting appropriate values for other configurable parameters of a network device. The program most commonly used to do this is the ifconfig (interface configure) command.

Typically you would use a command similar to the following:


       root# ifconfig eth0 192.168.0.1 netmask 255.255.255.0 up


In this case I'm configuring an ethernet interface `eth0' with the IP address `192.168.0.1' and a network mask of `255.255.255.0'. The `up' that trails the command tells the interface that it should become active, but can usually be omitted, as it is the default. To shutdown an interface, you can just call ``ifconfig eth0 down.

The kernel assumes certain defaults when configuring interfaces. For example, you may specify the network address and broadcast address for an interface, but if you don't, as in my example above, then the kernel will make reasonable guesses as to what they should be based on the netmask you supply and if you don't supply a netmask then on the network class of the IP address configured. In my example the kernel would assume that it is a class-C network being configured on the interface and configure a network address of `192.168.0.0' and a broadcast address of `192.168.0.255' for the interface.

There are many other options to the ifconfig command. The most important of these are:


  up this option activates an interface (and is the default).
  down
     this option deactivates an interface.
  [-]arp
     this option enables or disables use of the address resolution
     protocol on this interface
  [-]allmulti
     this option enables or disables the reception of all hardware
     multicast packets. Hardware multicast enables groups of hosts to
     receive packets addressed to special destinations. This may be
     of importance if you are using applications like desktop
  mtu N
     this parameter allows you to set the MTU of this device.
  netmask <addr>
     this parameter allows you to set the network mask of the network
     this device belongs to.
  irq <addr>
     this parameter only works on certain types of hardware and
     allows you to set the IRQ of the hardware of this device.
  [-]broadcast [addr]
     this parameter allows you to enable and set the accepting of
     datagrams destined to the broadcast address, or to disable
     reception of these datagrams.
  [-]pointopoint [addr]
     this parameter allows you to set the address of the machine at the remote end of a point to point link such as for slip or ppp.
 hw <type> <addr>
     this parameter allows you to set the hardware address of certain
     types of network devices. This is not often useful for ethernet,
     but is useful for other network types such as AX.25.


You may use the ifconfig command on any network interface. Some user programs such as pppd and dip automatically configure the network devices as they create them, so manual use of ifconfig is unnecessary.