Configuring Network Devices


The simplest way to configure the network is through a GUI. From the main menu, use System image from book Administration image from book Networking to bring up the network configuration menu (see Figure 11-1). This menu shows each of the available network adapters and enables you to configure them. You can enable or disable interfaces, and set addresses statically or through DHCP. For modems, you can enter the ISP's phone number, login credentials, and whether to reconnect after any disconnects.

image from book
Figure 11-1: The Network Settings applet, showing the properties for eth0

If you are configuring the network without a GUI, you can still configure the network device. The command ifconfig -a lists all known network devices. The lo device is the local loop-back, eth0 is usually the first wired Ethernet adapter, and sit0 is used to bridge IPv4 and IPv6. Additional network devices may be enumerated, such as eth1 and eth2 for two additional Ethernet cards.

The configuration for each device is stored in file /etc/network/interfaces. This is where you can define static or dynamic configurations, and whether they start up automatically or only as needed. For example, my computer has two Ethernet cards, but only the first one is automatically configured (see Listing 11-1).

Listing 11-1: Sample /etc/network/interfaces

image from book
     # This file describes the network interfaces available on your system     # and how to activate them. For more information, see interfaces(5).     # The loopback network interface     auto lo     iface lo inet loopback     # The primary network interface     auto eth0     iface eth0 inet static     address 10.1.2.30     netmask 255.0.0.0     gateway 10.1.2.254     # The second network interface     auto eth1     iface eth1 inet dhcp 
image from book

Table 11-1 shows some of the common fields for /etc/network/interfaces. For additional information, see the online manual (man 5 interfaces).

Table 11-1: Common Fields for /etc/network/interfaces
Open table as spreadsheet

Field Name

Example

Purpose

iface

iface eth0 inet dhcp

Defines an interface. The parameters are the interface name (for example, eth0), protocol (inet for IPv4 or inet6 for IPv6), and whether the configuration is static, dhcp, ppp, or bootp.

address

address 10.1.2.5

Static IP or IPv6 address.

netmask

netmask 10.255.255.255

Static subnet mask.

gateway

gateway 10.1.2.254

Static default gateway.

hostname

hostname myhost.local.lan

When using DHCP, this is the host name to request.

auto

auto eth0 lo

Set one or more interfaces to automatically come up configured. If you want an interface to not come up automatically, then leave it off the auto field.

wireless-essid

wireless-essid home

For wireless networks, specifies the Service Set Identifier (SSID) to connect to (for example, "home").

wireless-key

wireless-key 0123456789abcdef0011223344

For wireless networks that use WEP for security, this string specifies the WEP key as 10 or 26 hex digits (for 64-bit or 104-bit encryption, respectively).

pre-up

pre-up /usr/local/bin/ myscript

Run this script before bringing up the network interface.

post-up

post-up /usr/local/bin/ myscript

Run this script after bringing up the network interface.

pre-down

pre-down /usr/local/bin/ myscript

Run this script before taking down the network interface.

post-down

post-down /usr/local/bin/ myscript

Run this script after taking down the network interface.

After configuring the /etc/network/interfaces file, you can load the settings using:

 sudo /etc/init.d/networking restart 

For interfaces that are not brought up automatically, you can use ifconfig to bring them up and down. For example, sudo ifconfig eth1 up and sudo ifconfig eth1 down.You can only use an interface when it is up.



Hacking Ubuntu
Hacking Ubuntu: Serious Hacks Mods and Customizations (ExtremeTech)
ISBN: 047010872X
EAN: 2147483647
Year: 2004
Pages: 124
Authors: Neal Krawetz

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net