[2024-feb-29] Sad news: Eric Layton aka Nocturnal Slacker aka vtel57 passed away on Feb 26th, shortly after hospitalization. He was one of our Wiki's most prominent admins. He will be missed.

Welcome to the Slackware Documentation Project

¡Esta es una revisión vieja del documento!


Traducción en progreso. Victor.

Redes

Netconfig

Las computadoras no son muy interesantes por sí mismas. Claro, puedes instalar juegos en ellos, pero eso los convierte en consolas de entretenimiento glorificadas. Hoy en día, las computadoras necesitan poder hablar entre sí; necesitan estar en red. Ya sea que esté instalando una red de negocios con cientos o miles de computadoras o simplemente esté configurando una sola PC para el acceso a Internet, Slackware es simple y fácil. Este capítulo debería enseñarle cómo configurar redes cableadas típicas. La configuración inalámbrica común se tratará en detalle en la siguiente sección, pero gran parte de lo que lea aquí también será aplicable allí.

Existen muchas formas diferentes de configurar su computadora para conectarse a una red o a Internet, pero se dividen en dos categorías principales: estática y dinámica. Las direcciones estáticas son sólidas; se establecen con el entendimiento de que no se cambiarán, al menos no en el corto plazo. Las direcciones dinámicas son fluidas; el supuesto es que la dirección cambiará en algún momento en el futuro. Normalmente, cualquier tipo de servidor de red requiere una dirección estática simplemente para que otras máquinas sepan dónde contactarla cuando necesiten servicios. Las direcciones dinámicas tienden a usarse para estaciones de trabajo, clientes de Internet y cualquier máquina que no requiera una dirección estática por ningún motivo. Las direcciones dinámicas son más flexibles, pero presentan complicaciones propias.

Puede encontrar muchos tipos diferentes de protocolos de red, pero la mayoría de las personas solo tendrán que lidiar con el Protocolo de Internet (IP). Por esa razón, nos centraremos exclusivamente en IP en este libro.

Configuración manual

Bien, entonces instaló Slackware, configuró un escritorio, pero no puede conectarse a Internet o a la LAN de su empresa (red de área local), ¿qué hace? Afortunadamente, la respuesta a esa pregunta es simple. Slackware incluye una serie de herramientas para configurar su conexión de red. Lo primero que veremos es el muy poderoso ifconfig (8), que se usa para configurar o modificar la configuración del hardware más común para la conexión a redes: una tarjeta de interfaz de red (NIC o Ethernet). ifconfig es una herramienta increíblemente poderosa capaz de hacer mucho más que configurar direcciones IP. Para una introducción completa, debes leer su página de manual. Por ahora, solo lo usaremos para mostrar y cambiar las direcciones de red de algunos controladores Ethernet.

darkstar:~# ifconfig
lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:699 errors:0 dropped:0 overruns:0 frame:0
          TX packets:699 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:39518 (38.5 KiB)  TX bytes:39518 (38.5 KiB)

wlan0     Link encap:Ethernet  HWaddr 00:1c:b3:ba:ad:4c  
          inet addr:192.168.1.198  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::21c:b3ff:feba:ad4c/64 Scope:Link          
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1630677 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1183224 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1627370207 (1.5 GiB)  TX bytes:163308463 (155.7 MiB)

wmaster0  Link encap:UNSPEC  HWaddr 00-1C-B3-BA-AD-4C-00-00-00-00-00-00-00-00-00-00  
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

Como puede ver claramente aquí, cuando se ejecuta sin ningún argumento, ifconfig mostrará toda la información que tiene en todas las tarjetas Ethernet (y tarjetas Ethernet inalámbricas) presentes en su sistema. Lo anterior representa una conexión inalámbrica típica desde mi computadora portátil, así que no tenga miedo si lo que ve en su sistema no coincide. Sin embargo, si no ve ninguna interfaz ethX o wlanX, es posible que la interfaz esté inactiva. Para mostrar todas las NIC presentes actualmente si son “up” o “down” , simplemente pase el argumento - a .

darkstar:~# ifconfig -a
eth0      Link encap:Ethernet  HWaddr 00:19:e3:45:90:44  
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:122780 errors:0 dropped:0 overruns:0 frame:0
          TX packets:124347 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:60495452 (57.6 MiB)  TX bytes:17185220 (16.3 MiB)
          Interrupt:16 

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:699 errors:0 dropped:0 overruns:0 frame:0
          TX packets:699 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:39518 (38.5 KiB)  TX bytes:39518 (38.5 KiB)

wlan0     Link encap:Ethernet  HWaddr 00:1c:b3:ba:ad:4c  
          inet addr:192.168.1.198  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::21c:b3ff:feba:ad4c/4 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:1630677 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1183224 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:1627370207 (1.5 GiB)  TX bytes:163308463 (155.7 MiB)

wmaster0  Link encap:UNSPEC  HWaddr 00-1C-B3-BA-AD-4C-00-00-00-00-00-00-00-00-00-00  
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

Observe que la interfaz eth0 ahora se encuentra entre las devoluciones. ifconfig también puede cambiar la configuración actual en una NIC. Por lo general, necesitaría cambiar la dirección IP y la máscara de subred, pero puede cambiar prácticamente cualquier parámetro.

darkstar:~# ifconfig eth0 192.168.1.1 netmask 255.255.255.0
darkstar:~# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr 00:19:e3:45:90:44  
          inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:122780 errors:0 dropped:0 overruns:0 frame:0
          TX packets:124347 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:60495452 (57.6 MiB)  TX bytes:17185220 (16.3 MiB)
          Interrupt:16 

Si observa detenidamente, notará que la interfaz ahora tiene la dirección IP 192.168.1.1 y una máscara de subred 255.255.255.0. Ahora hemos configurado los conceptos básicos para la conexión a nuestra red, pero aún necesitamos configurar una puerta de enlace predeterminada y nuestros servidores DNS. Para hacer eso, necesitaremos ver algunas herramientas más.

A continuación, en nuestra parada a través de la red, está el igualmente poderoso route (8). Esta herramienta es responsable de modificar la tabla de enrutamiento del kernel de Linux que afecta a toda la transmisión de datos en una red. Las tablas de enrutamiento pueden volverse inmensamente complejas o pueden ser sencillas y directas. La mayoría de los usuarios solo necesitarán configurar una puerta de enlace predeterminada, por lo que le mostraremos cómo hacerlo aquí. Si, por algún motivo, necesita una tabla de enrutamiento más compleja, le recomendamos que lea la página de manual completa para route , así como que consulte otras fuentes. Por ahora, echemos un vistazo a nuestra tabla de enrutamiento inmediatamente después de configurar eth0.

darkstar:~# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
loopback        *               255.0.0.0       U     0      0        0 lo

No explicaré todo aquí, pero la información general debería ser fácil de recopilar si está familiarizado con las redes. Los campos Destino y Genmask especifican un rango de direcciones IP para que coincidan. Si se define una puerta de enlace, la información en forma de paquetes se enviará a ese host para su reenvío. También especificamos una interfaz en el campo final que la información debe atravesar. En este momento, solo podemos comunicarnos con computadoras con direcciones entre 192.168.1.0 y 192.168.1.255 y nosotros mismos a través de la interfaz de bucle de retorno, un tipo de NIC virtual que se usa para enrutar información desde esta computadora hacia sí misma. Para poder llegar al resto del mundo, necesitaremos configurar una puerta de enlace predeterminada.

darkstar:~# route add default gw 192.168.1.254
darkstar:~# route
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.1.0     *               255.255.255.0   U     0      0        0 eth0
loopback        *               255.0.0.0       U     0      0        0 lo
default         192.168.1.254   0.0.0.0         UG    0      0        0 eth0

You should immediately notice the addition of a default route. This specifies what router should be used to reach any addresses that aren't specified elsewhere in our routing table. Now, when we try to connect to say, 64.57.102.34, the information will be sent to 192.168.1.254 which is responsible for delivering the data for us. Unfortunately, we're still not quite through. We need some way of converting domain names like slackware.com into IP addresses that the computer can use. For that, we need to make use of a DNS server.

Fortunately, setting up your computer to use an external (or even an internal) DNS server is very easy. You'll need to use your favorite text editor and open the /etc/resolv.conf file. Don't ask me what happened to the e. On my computer, resolv.conf looks like this.

# /etc/resolv.conf
search lizella.net
nameserver 192.168.1.254

Many users won't need the search line. This is used to map hostnames to domain names. Basically, if I attempt to connect to “barnowl”, the computer knows to look for “barnowl.lizella.net” thanks to this search line. We're mainly interested in the nameserver line. This tells Slackware what domain name servers (DNS) to connect to. Generally speaking, these should always be specified by IP address. If you know what DNS servers you should use, you can just add them one at a time to individual nameserver lines. In fact, I don't know of any practical limit to the number of nameservers that can be specified in resolv.conf, so add as many as you like. Once this is done, you should be able to communicate with other hosts via their fully qualified domain name.

But Alan! That's a lot of hard work! I don't want to do this time and again for dozens or even hundreds of machines. You're absolutely right, and that's why smarter people than you and me created DHCP. DHCP stands for Dynamic Host Control Protocol and is a method for automatically configuring computers with unique IP addresses, netmasks, gateways, and DNS servers. Most of the time, you'll want to use DHCP. The majority of wireless routers, DSL or cable modems, even firewalls all have DHCP servers to can make your life much easier. Slackware includes two main tools for connecting to an exising DHCP server and can even act as a DHCP server for other computers. For now though, we're just going to look at DHCP clients.

First on our list is dhcpcd(8), part of the ISC DHCP utilities. Assuming your computer is physically connected to your network, and that you have an operating DHCP server on that network, you can configure your NIC in one shot.

darkstar:~/ dhcpcd eth0

If everything went according to plan, your NIC should be properly configured, and you should be able to communicate with other computers on your network, and with the Internet at large. If for some reason, dhcpcd fails, you may want to try dhclient(8). dhclient is an alternative to dhcpcd and works in basically the same way.

darkstar:~/ dhclient eth0
Listening on LPF/eth0/00:1c:b3:ba:ad:4c
Sending on   LPF/eth0/00:1c:b3:ba:ad:4c
Sending on   Socket/fallback
DHCPREQUEST on eth0 to 255.255.255.255 port 67
DHCPACK from 192.168.1.254
bound to 192.168.1.198 -- renewal in 8547 seconds.

Why does Slackware include two DHCP clients? Sometimes a particular DHCP server may be broken and not respond well to either dhcpcd or dhclient. In those cases, you can fall back to the other DHCP client in hopes of getting a valid response from the server. Traditionally, Slackware uses dhcpcd, and this works in the vast majority of cases, but it may become necessary at some point for you to use dhclient instead. Both are excellent DHCP clients, so use whichever you prefer.

Automatic Configuration with rc.inet1.conf

Manually configuring interfaces is an important skill to have, but it can become tedious. No one wants to manually setup their Internet connection every time the system boots. More importantly, you may not always have physical access to the machine when it boots. Slackware makes it easy to automatically configure ethernet (and wireless) cards at system startup with /etc/rc.d/rc.inet1.conf. For now, we're going to focus on traditional wired ethernet networking; the next chapter will discuss various wireless options.

rc.inet1.conf is an incredibly powerful configuration file, capable of configuring most of your network cards automatically when Slackware is started. The file is filled with useful comments, but there is also a man page that more thoroughly discusses its use. To begin, we're going to look at some of the options used on one of my personal machines.

# Config information for eth0:
IPADDR[0]="192.168.1.250"
NETMASK[=]"255.255.255.0"
USE_DHCP[0]=""
DHCP_HOSTNAME[0]=""
# Some lines ommitted.
GATEWAY="192.168.1.254"

This represents most of the information necessary to configure a static IP address on a single ethernet controller. netconfig will usually fill in these values for a single ethernet device for you. If you have multiple network cards in your machine and need all of them activated automatically at boot time, then you'll need to edit or add additional entries into this file in the same manner as above. First, let me go over some of the basics.

As you may have already guessed, IPADDR[n] is the Internet Protocol Address for the n network interface card. Typically, n corrosponds to eth0, eth1, and so on, but this isn't always the case. You can specify these values to pertain to a different network controller with the IFNAME[n] variable, but we will reserve that for wireless networking, as it more commonly pertains to wireless network controllers.

Likewise, NETMASK[n] is the subnet mask to use for the network controller. If these lines are left empty, then static IP addresses will not be automatically assigned to this network controller. The USE_DHCP[n] variable tells Slackware (naturally) to use DHCP to configure the interface. DHCP_HOSTNAME[n] is rarely used, but some DHCP servers may require it. In that case, it must be set to a valid hostname. Finally, we come to the GATEWAY variable. It is actually set lower in the file than it appears in my example, and it controls the default gateway to use. You may be wondering why there is no GATEWAY[n] variable. The answer to that lies in how Internet Protocol works. I won't go into an in-depth discussion on that subject, but suffice it to say that there is only ever one default route that a computer can use no matter how many interfaces are attached to it.

If you need to use static IP addressing, you will have to obtain a unique static IP address and the subnet mask for the interface, as well as the default gateway address, and enter those here. There is no place to enter DNS information in rc.inet1.conf, so DNS servers will have to be manually placed into resolv.conf as discussed in Manual Configuration. Of course, if you use netconfig, this will be handled for you by that program. Now let's take a look at another interface on my computer.

# Config information for eth1:
IPADDR[1]=""
NETMASK[1]=""
USE_DHCP[1]="yes"
DHCP_HOSTNAME[1]=""

Here I am telling Slackware to configure eth1 using DHCP. I do not need to set the IPADDR[1] or NETMASK[1] variables when using DHCP (in fact, if they are set, they will be ignored). Slackware will happily contact a DHCP server as soon as the machine begins to boot.

Chapter Navigation

Previous Chapter: Emacs

Next Chapter: Wireless Networking

Sources

  • Originally written by Alan Hicks, Chris Lumens, David Cantrell, Logan Johnson

 es:slackbook:network ()