User Tools

Site Tools


sysconfig:networking

Configuring Network Interfaces

Cucumber Linux provides a series of scripts for configuring and managing network interfaces. These scripts are found primarily in the /etc/network directory. This directory has three subdirectories: interfaces, methods and templates.

The methods directory stores helper scripts for each configuration method. Each method script is a driver for the networking configuration system that handles one specific type of network configuration. For example, the dhcp method script is the driver that configures a network interface to use DHCP.

The interfaces directory is where the actual configuration files reside. This is the only directory you will ever need to edit files in. The configuration files use Bash sytax: they define several variables for controlling the configuration for a network interface. The name of the configuration file is the network interface that will be configured by that file, as displayed by ifconfig. For example, the lo file configures the lo (loopback) interface.

The templates directory contains various template configuration files. These files provide near complete configurations that can be copied over to the interfaces directory, and then edited to fit your needs.

Every configuration file (in the /etc/network/interfaces directory) is required to define two variables: ONBOOT and METHOD. The ONBOOT variable controls whether or not this network interface should be automatically brought up when the system boots. It should be set to yes or no. The METHOD variable controls which configuration method will be used for this interface. It can be set to any method in the /etc/network/methods directory.

Some configuration methods require that additional variables be defined in the interface configuration file (for example, using a static configuration would require you to define ADDRESS). Which additional variables can be used varies from one configuration method to the next. To see which variables are valid for a specific method, run the command ifhelp <method>, where <method> is a configuration method from /etc/network/methods.

Additionally, some configuration methods will allow you to chainload another configuration method. What this means is that when the interface is brought up, the method specified by METHOD will run first, and then the chainloaded method will run. This is particularly useful when connecting to wireless networks: METHOD will be set to wireless or wireless-wpa. These configuration methods only connect you to the wireless network; they do not handle IP address assignment. Therefore, they possess the ability to chainload to another configuration method (like static or dhcp) and let that method handle the address assignment. When chainloading, it will be necessary to define all the variables required by both the primary method and the chainloaded method.

Once you have written a configuration file for an interface, run the command # ifup interface to bring up the network interface using the configuration. Network interfaces can manually be brought up and down at any time by using the # ifup <interface> and # ifdown <interface> commands respectively (as root). Alternatively, you may run # /etc/init.d/network restart to restart the networking service, which will bring up all the network interfaces that have ONBOOT set to yes in their configuration files.

Setting a Static IP Address

To configure a network interface to get a static IPv4 address, copy the static template from /etc/network/templates/dhcp to /etc/network/interfaces/<interface>, where <interface> is the name of the interface to configure, as it appears in ifconfig. Edit the configuration file you just created in /etc/network/interfaces, and change the ADDRESS, NETMASK, BROADCAST, and GATEWAY variables to the desired IPv4 address, subnet mask, broadcast address and default gateway respectively. Only the address field is strictly required: you can delete the other fields; however, this may result in issues. Unless you specifically know that you do not need the optional fields, you should fill them all out. Then change the line ONBOOT=no to ONBOOT=yes. Finally, restart the network service by running # /etc/init.d/network restart.

To configure the interface to use IPv6 instead of IPv4, use the static6 template rather than the static template. In this case, you need only set the IPV6_ADDRESS and IPV6_GATEWAY variables the IPv6 address (with the CIDR slash notation for the subnet mask) and the and IPv6 default gateway respectively. Otherwise proceed as you would for configuring IPv4.

To configure a dual IPv4 and IPv6 stack, use the static4and6 template. Fill out both the IPv4 and IPv6 sections as directed above.

Using DHCP to get a Dynamic IP Address

To configure a network interface to use DHCP to attempt to get IPv4 and IPv6 addresses, copy the dhcp template from /etc/network/templates/dhcp to /etc/network/interfaces/<interface>, where <interface> is the interface name you want to configure DHCP on, as it appears in ifconfig. Next, edit the configuration file you just created in /etc/network/interfaces and change the line ONBOOT=no to ONBOOT=yes. Finally, restart the network service by running # /etc/init.d/network restart.

To configure the interface to use only IPv4 or IPv6 instead of a dual network stack, use the dhcp4 or dhcp6 template respectively in place of the dhcp template.

Configuring a Wireless Network Interface

Configuring a wireless network interface to connect to a wireless network is a little trickier.

Scanning to get a List of Available Wireless Networks

If you do not know the SSID of the network you will be connecting to, it will be necessary to scan for a list of available wireless networks. To do this, first ensure that your wireless interface is turned on; this can be done by running # ifconfig <interface> up, where <interface> is your wireless interface. Next, scan for available networks by running # iwlist scan. This generates a lot of output, so you may want to pipe it to less or redirect it to a file.

Scroll through this output until you find the network you wish to connect to. Take note of ESSID: and Encryption Key: fields. Also take note of whether or not there is a line containing something similar to IEEE 802.11i/WPA; you will need this information later.

Choosing the Right Template

There are several wireless templates in /etc/network/templates: any template that starts with wireless- or wpa- is a template for a wireless configuration. It is very important that you choose the right template here. This can be a little complicated and confusing at first, so here is a guide for choosing the correct template for your network:

Wireless templates make use of chainloading to connect to a network and get an IP address. Each wireless template name has two parts, separated by a dash. The first part is the primary configuration method (used to connect to the wireless network), and the second part is the chainloaded method (used to get an IP address after connecting). It is important to understand that connecting to a wireless network and getting an IP address are two completely independent processes, both of which must be completed successfully in order to communicate over a wireless network connection.

Use a template where first part of the template name is wireless or wpa. This indicates that the network you are connecting to is an unsecured network or a wpa secured network respectively. If the network had Encryption Key:On and a line similar to IEEE 802.11i/WPA, then use a template that starts with wpa. Otherwise, use a template that starts with wireless.

Choose the second part of the template based on how you would like the IP address to be assigned after connecting to the network. Choose the template ending in dhcp to get a dynamic IP address via DHCP or the template ending in static to manually assign a static IP address.

Editing the Configuration File

Once you have chosen the correct template, copy the template from /etc/network/templates/<template> to /etc/network/interfaces/<interface>, where <interface> is the name of the interface you are configuring and <template> is the name of the template you chose in the previous section. Then edit the configuration file you just created in /etc/network/interfaces and change the line ONBOOT=no to ONBOOT=yes.

Now, change the WIRELESS_SSID or WPA_SSID variable to the ESSID field value from the # iwlist scan command ran earlier (you will see only one of these variables; fill out the one you see and ignore the other). If you are connecting to a WPA secured network, set the WPA_PASSPHRASE variable to the passphrase for the network (when you do this, make sure to escape any special characters in passphrase by putting a backslash before them).

Next, find the lines that say something like:

##### End Wireless/WPA Method Specific Configuration #####

##### Begin DHCP/Statis Method Specific Configuration #####

Proceed to fill out all the lines below here as directed Setting a Static IP Address or Using DHCP to get a Dynamic IP Address section, depending on which template you chose.

Finally, save the changes to the config file and restart the network service by running # /etc/init.d/network restart.

Example Configurations

Configuring an Ethernet Interface with DHCP

In this example, we will configure the ethernet interface enp0s3. If your ethernet interface has a different name, replace enp0s3 with the name of your ethernet interface. A list of all present network interfaces can be obtained by running ifconfig -a.

  1. First, copy over the DHCP configuration template by running cp /etc/network/templates/dhcp /etc/network/interfaces/enp0s3.
  2. Next, edit the file you just created (/etc/network/interfaces/enp0s3) using your favorite text editor. Change the line ONBOOT=no to ONBOOT=yes.
  3. Finally, restart the networking service by running /etc/init.d/network restart.

That's it. Wait a minute for your machine to get assigned an IP address, and then your ethernet interface will be ready to use.

sysconfig/networking.txt · Last modified: 2018/08/30 20:04 (external edit)