Gentoo:Network configuration

From Linux 101, The beginner's guide to all things Linux.

Jump to: navigation, search

[edit] /etc/conf.d/net

The main portion of Gentoo's network configuration will take place inside the /etc/conf.d/net file. The default behavior of Gentoo is to assume that the network interface will be utilizing DHCP to attain an IP address and as such the file is simply filled with comments explaining this. A completely empty file will cause the same behavior. This is most likely correct for the majority of users. There are, however, instances in which specifying specific options is desirable, especially for wireless devices. For example, a user might wish to set a static IP address. In order to do this, the following notation is used inside the /etc/conf.d/net file:

# This symbol denotes the start of a comment in the file
# Static IP Configuration Example
config_eth0=("192.168.0.1 netmask 255.255.255.0")

This will set the ethernet device eth0 to have an IP address of 192.168.0.1 and a netmask of 255.255.255.0 (Class C). For changes to take effect, the configuration script must be reloaded and the device restarted.

[edit] Managing interfaces

There is a simple script which will easily allow you manage your interface, /etc/init.d/net.eth0. If this file does not exist and you have eth0, or any ethernet device with a different device name, you can simply create a symlink from /etc/init.d/net.lo to /etc/init.d/net.X where X is the name of the device. An example for a non-existent eth0 file is listed below.

# ln -s /etc/init.d/net.lo /etc/init.d/net.eth0

Once this is achieved, simply type

# /etc/init.d/net.eth0 start

Provided the interface has not already been started, this will bring it up. If, however, it has already been started, then you will want to restart it instead.

# /etc/init.d/net.eth0 restart

If for any reason you wish to simply bring the device down, issuing

# /etc/init.d/net.eth0 stop

will do this for you. If for any reason the init script states the device is already up, but you know for a fact it is down, you can force the script into making it know it is down through

# /etc/init.d/net.eth0 zap

which will reset the device status, according to the script, to down. If you want the interface to be brought up on boot, then use of the rc-update command is required.

# rc-update add net.eth0 default

This will add the net.eth0 script to the default runlevel, which will then cause the interface to be started on boot.

[edit] Wireless Configuration

If you need to configure a wireless interface, you will need the wireless-tools package installed.

# emerge wireless-tools

The /etc/conf.d/wireless.example file provides fairly comprehensive documentation regarding the various configurations available to you. The ones you will probably be most interested in revolve around that of ESSID selection and WEP encryption.

key_CLEMSON="XXXX enc open"
key_LINKSYS="XXXX enc open"
preferred_aps=("CLEMSON" "LINKSYS")

key_CLEMSON sets the WEP key for the CLEMSON network to XXXX, and enc open sets its encryption method to open. The same is done for the LINKSYS network. preferred_aps sets the order in which your interface will attempt to connect to networks. If you are so inclined, you may also simply run a series of commands through a bash script which does exactly this, except only when the script is executed. ipw3945 would be whichever wireless module you are using (if any) and eth1 would be the wireless interface.

#!/bin/bash
ifconfig eth1 down
rmmod ipw3945
modprobe ipw3945
ifconfig eth1 up
iwconfig eth1 key XXXX enc open
dhcpcd eth1


Navigation: Gentoo Index
Personal tools