Reader Prerequisites: To get the most from this article, understand the following concepts before reading: basic Core Utilities, configuration files, text editors, DNS, TCP/IP, DHCP, netmask, gateway |
|
?Discuss_this_Page |
Table of Contents
Contents
Setting up an Ethernet Interface
The majority of network setup can be done via the interfaces configuration file at /etc/network/interfaces. Here, you can give your network card an IP address (or use dhcp), set up routing information, configure IP masquerading, set default routes and much more.
Remember to add interfaces that you want brought up at boot time to the 'auto' line.
See man interfaces for more options.
Using DHCP to automatically configure the interface
If you're just using DHCP then all you need is something like:
auto eth0 iface eth0 inet dhcp
Configuring the interface manually
If you're configuring it manually then something like this will set the default gateway (network, broadcast and gateway are optional):
iface eth0 inet static address 192.168.0.7 netmask 255.255.255.0 gateway 192.168.0.254
See man interfaces for more options.
Setting the speed and duplex
On some networks, autonegotiation is not possible. If you must set your interface's speed and duplex by hand, then some trial and error may be required. Here are the basic steps:
Install the ethtool and net-tools packages, so that you have the ethtool and mii-tool programs. One or both of these might work for your interface.
Make sure you have a way to login to the system in case the network interface becomes nonfunctional. An ?ssh connection could be disrupted, so you should have a fallback strategy.
- Identify the interface in question (it will often be eth0). Adjust the remainder of these instructions accordingly.
- Try to determine what its current speed and duplex settings are. This is where it gets fun:
As root, try ethtool eth0 first, and see whether the "Speed:" and "Duplex:" lines look valid. If not, the ethtool may not be supported by your device.
As root, try mii-tool -v eth0 and see whether its output looks correct. If not, them mii-tool may not be supported by your device.
If neither one is supported, you may have to set parameters directly on the kernel driver module. Identify which driver module you're using by reading the output of dmesg and lsmod. You can then try modinfo MODULENAME to see what parameters it accepts, if any. (You can use modinfo even on modules that are not loaded, for comparison.) TODO: where does one set kernel module parameters?
- Next, try to change the settings of the interface while it's operating. You'll need to be root, of course. Either:
ethtool -s eth0 autoneg off speed 100 duplex full (assuming 100 Mbps and full duplex)
mii-tool -F 100baseTx-FD eth0 (same assumption)
If one of these commands successfully set your NIC, then you can put it into /etc/network/interfaces so it runs when you bring the interface up (e.g. at boot time). However, before you do that, you should understand that some drivers and devices behave differently than others. When the driver module is loaded, the NIC may begin autonegotiation without any way to stop it (particularly with drivers that do not accept parameters). The settings from interfaces are applied at some point after that, which may be right in the middle of the negotiation. So, some people find it necessary to delay the ethtool or mii-tool command by a few seconds. Thus:
iface eth0 inet static address ... netmask ... gateway ... up sleep 5; ethtool -s eth0 ...
Or the analogous mii-tool command.
- Reboot the machine to make sure it comes up correctly, and be prepared to intervene manually (e.g. Ctrl-Alt-Del and then boot into single-user mode from GRUB or LILO) if things don't work.
Bringing up an interface without an IP address
To create a network interface without an IP address at all use the manual method and use pre-up and post-down commands to bring the interface up and down.
iface eth0 inet manual pre-up ifconfig $IFACE up post-down ifconfig $IFACE down
Defining the (DNS) Nameservers
Before a computer can connect to an external network resource (say, for example, a web server), it must have a means of converting any alpha-numeric names (e.g. wiki.debian.org) into numeric network addresses (e.g. 140.211.166.4). (The Internet uses these structured numeric IP addresses as network addresses.)
There are two primary ways to define the nameservers. Which one you use depends on how your system is configured.
Manually edit the resolv.conf configuration file at /etc/resolv.conf, or
Use the resolvconf program.
The resolv.conf configuration file
The configuration file resolv.conf at /etc/resolv.conf contains information that allows a computer connected to a network to resolve names into addresses. (Note: Do not confuse this configuration file with the program resolvconf, which unfortunately has a nearly identical name.)
The resolv.conf file typically contains the IP addresses of nameservers (DNS name resolvers) that will attempt to translate names into addresses for any node available on the network. There will be a line or lines that look like this:
nameserver 12.34.56.78 nameserver 12.34.56.79
In this example, the system is using nameservers at the IP addresses 12.34.56.78 and 12.34.56.79. Simply edit the file and enter the IP addresses of the nameservers you need to use after each nameserver. Add more nameserver lines if you have more nameservers. Don't use this method if you have the resolvconf program installed.
The resolv.conf configuration file has many other options for defining how resolver looks up names. See man resolv.conf for details.
The resolvconf program
The resolvconf program keeps track of system information about the currently available nameservers. It should not be confused with the configuration file resolv.conf, which unfortunately has a nearly identical name. The resolvconf program is optional on a Debian system.
The configuration file resolv.conf contains information about the the nameservers to be used by the system. However, when multiple programs need to dynamically modify the resolv.conf configuration file they can step on each other and the file can become out-out-sync. The resolvconf program addresses this problem. It acts as an intermediary between programs that supply nameserver information (e.g. dhcp clients) and programs that use nameserver information (e.g. resolver).
When resolvconf is properly installed, the resolv.conf configuration file at /etc/resolv.conf is replaced by a symbolic link to /etc/resolvconf/run/resolv.conf and the resolver instead uses the configuration file that is dynamically generated by resolvconf at /etc/resolvconf/run/resolv.conf.
The resolvconf program is generally only necessary when a system has multiple programs that need to dynamically modify the nameserver information. In a simple system where the nameservers do not change often or are only changed by one program, the resolv.conf configuration file is adequate.
If the resolvconf program is installed, you should not edit the resolv.conf configuration file manually as it will be dynamically changed by programs in the system. If you need to manually define the nameservers (as with a static inferface), add a line something like the following to the interfaces configuration file at /etc/network/interfaces:
dns-nameservers 12.34.56.78 12.34.56.79
Place the line indented within an iface stanza, e.g., right after the gateway line. Enter the IP addresses of the nameservers you need to use after dns-nameservers. Put all of them on one line separated by spaces. Don't forget the "s" on the end of dns-nameservers.
The resolvconf program is a fairly new addition to Debian and many older programs need to be updated or reconfigured to work properly with it. If you have problems, see /usr/share/doc/resolvconf/README. It has lots of information on making other programs get along with resolvconf.
Howto create fault tolerant bonding with vlan (Etch)
Howto configure one of the above server active backup bonding 3 vlan {vlan10,vlan20,vlan30} Debian networking without SPOF without native vlan.
aptitude install vlan ifenslave-2.6
Network config
Cisco switch interface example config
interface GigabitEthernet1/2 description eht1 www.niif.hu :) switchport switchport trunk encapsulation dot1q switchport trunk allowed vlan 10,20,30 switchport mode trunk no ip address no cdp enable spanning-tree portfast trunk
bonding with active backup
cat > /etc/modprobe.d/bonding
alias bond0 bonding options bonding mode=active-backup miimon=100 downdelay=200 updelay=200 primary=eth1
/etc/network/interfaces
# The loopback network interface auto lo iface lo inet loopback # The primary network interface auto bond0 iface bond0 inet manual up ifconfig bond0 0.0.0.0 up slaves eth1 eth0 auto vlan10 iface vlan10 inet static address 10.10.10.12 netmask 255.255.0.0 network 10.10.0.0 broadcast 10.10.255.255 vlan-raw-device bond0 gateway 10.10.0.1 dns-search hup.hu dns-nameservers 10.10.0.2 auto vlan20 iface vlan20 inet static address 10.20.10.12 netmask 255.255.0.0 network 10.20.0.0 broadcast 10.20.255.255 vlan-raw-device bond0 auto vlan30 iface vlan30 inet static address 10.30.10.12 netmask 255.255.0.0 network 10.30.0.0 broadcast 10.30.255.255 vlan-raw-device bond0