Jump to content

Linux Networking/Configuring a network interface

From Wikibooks, open books for an open world

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 ip command.

Typically you would use a command similar to the following:

ip addr add 192.168.0.1/24 dev eth0
ip link set eth0 up

In this case, I am configuring an ethernet interface "eth0" with the IP address 192.168.0.1 and a prefix length of 24 to specify the network size. The second command tells the operating system that it should set the interface active, but can usually be omitted, as it is the default. To shutdown an interface, you can just call `ip link set eth0 down`.

iproute2 assumes certain defaults when configuring interfaces. For example, if you do not specify a prefix length, it will use /32.

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

  up
     this option activates an interface (and is the default).
  down
     this option deactivates an interface.
  arp on/off
     this option enables or disables use of the address resolution
     protocol on this interface
  allmulticast on/off
     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.
  addr <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.

For ip addr, one can specify

  (ip addr add ...) brd addr
     this parameter allows you to enable and set the accepting of
     datagrams destined to the IPv4 broadcast address, or to disable
     reception of these datagrams. One can use `brd +` to automatically
     fill in the broadcast address.

You may use the ip 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.