Вы находитесь на странице: 1из 9

Configuracin de IP en Unix

Contenido

Configuracin de Sistemas Unix


Escenarios
Interfaces
Rutas
Configuracin de Sistemas Unix
Escenarios

Vamos

a configurar las
interfaces y ruta de esta red
IP.

Los

comandos
de
configuracin indicados son
vlidos para cualquier sistema
Unix.

Nuestro primer objetivo es


habilitar los pings entre Alice
y Bob.

Interfaces
Configuracin de la Interfaz I
Vamos a empezar la configuracin de Alice.
Si desea eliminar cualquier @ IP configurada previamente en una interfaz:
alice:~# ifconfig 0.0.0.0 eth0
alice:~# ifconfig
eth0
Link encap:Ethernet
HWaddr fe:fd:00:00:01:00
inet6 addr: fe80::fcfd:ff:feOO:100/64 Scope:Link
UP BROADCAST RUNNING PROMISC MULTICAST MTU:1500 Metric:1
RX packets:27 errors:0 dropped:0 overruns:0 frame:0
TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3582 (3.4 KiB) TX bytes:468 (468.0 B)
Interrupt:5
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:10 errors:0 dropped:0 overruns:0 frame:0
TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:660 (660.0 B)
TX bytes:660 (660.0 B)

Usted puede comprobar que en la actualidad, la tabla de enrutamiento est vaca:

alice:~# route -n
Kernel IP routing table
Destination Gateway Genmask

Use Iface

Configuracin de la Interfaz II
Vamos a configurar una direccin IP y una mscara para

eth 0 de Alice:

alice:~# ifconfig eth0 10.0.0.40 netmask 255.255.255.128


alice:~# ifconfig eth0
eth0
Link encap:Ethernet
HWaddr fe:fd:00:00:01:00
inet addr:10.0.0.40
Beast:10.0.0.127 Mask:255.255.255.128
inet6 addr: fe80::fcfd:ff:fe00:100/64 Scope:Link
UP BROADCAST RUNNING PROMISC MULTICAST
MTU:1500
Metric:1
RX packets:28 errors:0 dropped:0 overruns:0 frame:0
TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3669 (3.5 KiB) TX bytes:468 (468.0 B)
Interrupt:5

Si revisamos la tabla de enrutamiento de Alice:


alice:~# route -n
Kernel IP routing table
Destination Gateway
Genmask
10.0.0.0
0.0.0.0
255.255.255.128

Como se puede observar, el comando

Flags Metric Ref


U
0
0

Use Iface
0
eth0

ifconfig no slo configura la direccin y la mscara,

sino tambin configura la tabla de enrutamiento con la entrada correspondiente a la entrega


directa.

En este caso, la entrada para la red es 10.0.0.0/25.


Routes
Configuracin de Rutas I
En el escenario, el

phyhost

tiene interfaces

TapX conectados a switches

SWX

en el

escenario.

Hagamos un

ping a Bob:

alice:~# ping -c 1 10.0.0.240


connect: Network is unreachable

Las medias de los errores previos que existen no tienen ninguna entrada vlida en la tabla
de enrutamiento de alice para la direccin IP de destino.

As, no veremos nada si capturamos en

t ap 0 .

Por lo tanto, es necesario definir una ruta indirecta en alice.


Podemos usar el comando
aadir, eliminar o ver las rutas.

route

que est presente en cualquier sistema tipo Unix para

route

La sintaxis ms comnmente usada para


# route (add|del) -net @NET netmask

es la siguiente:

MASK [gw

@IP

dev

IF]

Tambin podemos utilizar la notacin CIDR @NET/X.

Podemos ver la tabla de enrutamiento actual con la opcin

n , lo que significa ver la

tabla de enrutamiento numricamente (sin resolucin de nombres).

Configuracin de Rutas II
Podemos aadir entradas de enrutamiento para hosts con la opcin

host .

Una ruta de host es la entrada ms especfica que puede ser utilizado desde que el destino
debe coincidir completamente con los 32 bits de la entrada de enrutamiento.

Por ltimo, podemos definir una ruta predeterminada con:


route add default gw @IP

Vamos a configurar una ruta indirecta a la red de bob:


alice:~# route add -net 10.0.0.192/26 gw 10.0.0.31
alice:~# route -n
Kernel IP routing table
Destination Gateway
Genmask
Flags Metric Ref Use Iface
10.0.0.192 10.0.0.31
255.255.255.192
UG
0
0
0
eth0
10.0.0.0 0.0.0.0
255.255.255.128
U
0
0
0
eth0
alice:~# ping -c 1 10.0.0.240
PING 10.0.0.240 (10.0.0.240) 56(84) bytes of data.
From 10.0.0.40 icmp_seq=l Destination Host Unreachable
--- 10.0.0.240 ping statistics --1 packets transmitted, 0 received,
+1 errors,
100% packet loss, time 0ms

Ahora el problema es que el

etho 0 NIC de r1 no est configurado correctamente.

Configuracin de alice I (continuacin)


Una regla de oro para la configuracin de rutas es que no se puede configurar una ruta
indirecta mediante un router si usted no est conectado directamente:
alice:~# route -n
Kernel IP routing table
Destination Gateway
Genmask
10.0.0.192 10.0.0.31
255.255.255.192
10.0.0.0
0.0.0.0
255.255.255.128
alice:-# route add -net 10.0.0.128/26 gw
SIOCADDRT: Network is unreachable
alice:-# route add -net 10.0.0.128/26 gw
SIOCADDRT: Network is unreachable

Flags Metric Ref


UG
0
0
U
0
0
10.0.0.131

Use Iface
0
eth0
0
eth0

10.0.0.202

Configuremos correctamente la ruta indirecta para la red de carla:


alice:-# route add -net
alice:~# route -n
Kernel IP routing table
Destination Gateway
10.0.0.128 10.0.0.31
10.0.0.192 10.0.0.31

10.0.0.128/26 gw 10.0.0.31

Genmask
255.255.255.192
255.255.255.192

Flags Metric Ref


UG
0
0
UG
0
0

Use Iface
0
eth0
0
eth0

10.0.0.0

0.0.0.0

255.255.255.128

eth0

Configuracin de alice II (continuacin)


Tambin podemos definir rutas especficas para determinados hosts:
alice:-# route add -host 10.0.0.140 gw 10.0.0.31
alice:~# route -n
Kernel IP routing table
Destination
Gateway
Genmask
Flags
10.0.0.140
10.0.0.31
255.255.255.255
UGH
10.0.0.128
10 .0.0.31
255.255.255.192
UG
10.0.0.192
10 .0.0.31
255.255.255.192
UG
10.0.0.0
0.0.0.0
255.255.255.128
U

Metric
0
0
0
0

Ref
0
0
0
0

Use
0
0
0
0

Iface
eth0
eth0
eth0
eth0

Observe que r1 es el nico nodo que puede ser usado por alice para enviar su trfico
indirecta.

As, podemos eliminar las rutas indirectas anteriores y aadir una ruta por defecto:
alice:~# route del -host 10.0.0.140
alice:-# route del -net 10.0.0.128/26
alice:-# route del -net 10.0.0.192/26
alice:~# route add default gw 10.0.0.31
alice:~# route -n
Kernel IP routing table
Destination Gateway
Genmask
10.0.0.0
0.0.0.0
255.255.255.128
0.0.0.0
10.0.0.31
0.0.0.0

Flags Metric Ref


U
0
0
UG
0
0

Use Iface
0
eth0
0
eth0

Configuracin de r1 I
Vamos a configurar

eth 0 en r 1 y probar algunos

pings desde alice:

R1:-# ifconfig ethO 10.0.0.31/25


alice:~# arp -n
alice:~# ping -c 1 10.0.0.31
PING 10.0.0.31 (10.0.0.31) 56(84) bytes of data.
64 bytes from 10.0.0.31:
icmp_seq=l ttl=64 time=20.6 ms
--- 10.0.0.31 ping statistics --1 packets transmitted,
1 received,
0% packet loss, time Oms
rtt min/avg/max/mdev = 20.617/20.617/20.617/0.000 ms
alice:~# arp -n
Address
HWtype
HWaddress
Flags Mask Iface
10.0.0.31
ether
FE:FD:00:00:02:00
C
eth0

Como se puede observar, el ping trabaja para 0.31.


Si el eliminar la entrada ARP (o esperar) y tratar un ping para 0.240:
alice:~# arp -d 10.0.0.31
alice:~# ping -c 1 10.0.0.240
PING 10.0.0.240 (10.0.0.240) 56(84) bytes of data.
From 10.0.0.31 icmp_seq=l Destination Net Unreachable
--- 10.0.0.240 ping statistics --1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms
alice:~# arp -n
Address
HWtype
HWaddress
Flags Mask Iface
10.0.0.31
ether
FE:FD:00:00:02:00
C
eth0

Configuracin de r1 II
Ahora, vamos a configurar eth1 en

r1 y la ruta indirecta para la red 10.0.0.192/26:

rl:~# ifconfig ethl 192.168.0.1/30


rl:~# route add -net 10.0.0.192/26 gw 192.168.0.2
rl:~# route -n
Kernel IP routing table
Destination Gateway
Genmask
Flags Metric
192.168.0.0 0.0.0.0
255.255.255.252 U
0
10.0.0.192
192.168.0.2 255.255.255.192 UG
0
10.0.0.0
0.0.0.0
255.255.255.128 U
0

Vamos a intentar de nuevo un

Ref
0
0
0

Use Iface
0
ethl
0
ethl
0
eth0

ping desde alice a .240:

alice:~# ping -c 1 10.0.0.240


PING 10.0.0.240 (10.0.0.240)
56(84) bytes of data.
From 10.0.0.31 icmp_seq=l Destination Host Unreachable
--- 10.0.0.240 ping statistics --1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms

Ahora el problema es que

et0

r2

de

no est configurado correctamente.

Configuracin de r2 I
Si tratamos el

ping de nuevo:

alice:~# ping -c 1 10.0.0.240


PING 10.0.0.240 (10.0.0.240) 56(84) bytes of data.
From 192.168.0.2 icmp_seq=l Destination Net Unreachable
--- 10.0.0.240 ping statistics --1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms

Ahora configuremos

et 1

de

r2

y tratemos de nuevo con el

ping :

r2:~# ifconfig ethl 10.0.0.202/26


r2:~# route -n
Kernel IP routing table
Destination
Gateway
Genmask
Flags Metric Ref Use
192.168.0.0
0.0.0.0
255.255.255.252
U
0
0
0
10.0.0.192
0.0.0.0
255.255.255.192
U
0
0
0
10.0.0.0
192.168.0.1 255.255.255.128
UG
0
0
0
alice:~# ping -c 1 10.0.0.240
PING 10.0.0.240 (10.0.0.240)
56(84) bytes of data.
From 192.168.0.2 icmp_seq=l Destination Host Unreachable
--- 10.0.0.240 ping statistics --1 packets transmitted, 0 received,
+1 errors,
100% packet loss,

Configuracin de bob I
Vamos a configurar

eth 0 de bob

y tratar el ping desde

bob:~# ifconfig ethO 10.0.0.240/26


alice:~# ping -c 1 10.0.0.240
PING 10.0.0.240 (10.0.0.240)
56(84)
--- 10.0.0.240 ping statistics ---

bytes of data.

alice :

Iface
eth0
ethl
eth0

time 0ms

1 packets transmitted,

0 received,

El mensaje ICMP es recibida por

100% packet loss,

time 0ms

bob , pero l no puede responder a alice .

Tenemos que definir una ruta para 10.0.0.0/25:


bob:~# route add -net 10.0.0.0/25 gw 10.0.0.202
bob:~# route -n
Kernel IP routing table
Destination
Gateway
Genmask
Flags Metric Ref Use
10.0.0.192
0.0.0.0
255.255.255.192
U
0
0
0
10.0.0.0
10.0.0.202
255.255.255.128
UG
0
0
0
Finalmente el

Iface
eth0
eth0

ping funciona!

alice:~# ping -c 1 10.0.0.240


PING 10.0.0.240 (10.0.0.240)
56(84) bytes of data.
64 bytes from 10.0.0.240: icmp_seq=l ttl=62 time=24.6 ms
--- 10.0.0.240 ping statistics --1 packets transmitted, 1 received, 0% packet loss, time Oms
rtt min/avg/max/mdev = 24.604/24.604/24.604/0.000 ms

Configuracin de bob II
Pero un ping desde

r1 a bob

no funciona.

r1:-# ping -c 1 10.0.0.240


PING 10.0.0.240 (10.0.0.240)
56(84) bytes of data.
--- 10.0.0.240 ping statistics --1 packets transmitted, 0 received,
100% packet loss,

Podemos aadir una ruta a 192.168.0.0/30 en

b ob

time 0ms

para solucionar este problema:

bob:~# route add -net 192.168.0.0/30 gw 10.0.0.202


bob:~# route -n
Kernel IP routing table
Destination
Gateway
Genmask
Flags
10.0.0.192
0.0.0.0
255.255.255.192
U
10.0.0.0
10.0.0.202
255.255.255.128
UG
192.168.0.0
10.0.0.202
255.255.255.252
UG

Metric
0
0
0

Ref
0
0
0

Use
0
0
0

Iface
ethO
ethO
ethO

r1:~# ping -c 1 10.0.0.240


PING 10.0.0.240 (10.0.0.240)
56(84) bytes of data.
64 bytes from 10.0.0.240: icmp_seq=1 ttl=62 time=24.6 ms
--- 10.0.0.240 ping statistics --1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 24.604/24.604/24.604/0.000 ms

Configuracin de bob III


Una mejor solucin es aadir una "ruta por defecto" (y eliminar las otras rutas indirectas):
bob:~# route add default gw 10.0.0.202
bob:~# route del -net 192.168.0.0/30
bob:~# route del -net 10.0.0.0/25
bob:~# route -n
Kernel IP routing table
Destination
Gateway
Genmask
10.0.0.192
0.0.0.0
255.255.255.192
0.0.0.0
10.0.0.202
0.0.0.0

Flags Metric Ref Use Iface


U
0
0
0
eth0
UG
0
0
0
eth0

r1:~# ping -c 1 10.0.0.240


PING 10.0.0.240 (10.0.0.240)
56(84) bytes of data.
64 bytes from 10.0.0.240: icmp_seq=l ttl=62 time=24.6 ms
--- 10.0.0.240 ping statistics --1 packets transmitted,
1 received,
0% packet loss, time 0ms
rtt min/avg/max/mdev = 24.604/24.604/24.604/0.000 ms

Configuracin de Rutas Directas I


Rutas directas no se suelen configurar con

route , ya que se crean automticamente por

ifconfig .
Sin embargo, podemos quitar y aadir rutas directas tambin con el comando

route .

Vamos a realizar una prueba sobre las rutas directas.


En particular, queremos mostrar que la tabla de enrutamiento slo es necesario para enviar
los paquetes pero no para recibirlas.

Para ello, borramos la ruta directa hacia 10.0.0.0/25 en

r1 .

r1:~# route del -net 10.0.0.0/25


r1:~# ifconfig eth0
eth0 Link encap:Ethernet
HWaddr fe:fd:00:00:02:00
inet addr:10.0.0.31
Beast:10.0.0.127
Mask:255.255.255.128
inet6 addr: fe80::fcfd:ff:feOO:200/64 Scope:Link
UP BROADCAST RUNNING PROMISC MULTICAST
MTU:1500
Metric:1
RX packets:67 errors:0 dropped:0 overruns:0 frame:0
TX packets:34 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:4200
(4.1 KiB)
TX bytes:2424
(2.3 KiB)
Interrupt:5
r1:-# route -n
Kernel IP routing table
Destination
Gateway
Genmask
Flags Metric Ref
192.168.0.0
0.0.0.0
255.255.255.252
U
0
0
10.0.0.192
192.168.0.2 255.255.255.192
UG
0
0

Use
0
0

Iface
ethl
ethl

Configuracin de Rutas Directas II


Como se puede observar,

eth0

de

r1

todava tiene la direccin IP, pero hemos

eliminado la ruta directa asociada.

Cuando intentamos un
mensaje

echorequest

ping
cruza

Sin embargo, el mensaje de


un mensaje

desde

alice

bob

se observar en

tap2

que el

r1

genera

r1 .

echoreplay

no se puede enviar a

alice

destination unreachable .

Por ltimo, para reconfigurar la ruta directa se puede utilizar


r1:-# route -n
Kernel IP routing table
Destination
Gateway
192.168.0.0
0.0.0.0
10.0.0.192
192.168.0.2

Genmask
255.255.255.252
255.255.255.192

ifconfig con arriba/abajo:

Flags Metric Ref


U
0
0
UG
0
0

Use Iface
0
eth1
0
eth1

r1:-# ifconfig eth0 down


r1:-# ifconfig eth0 up
r1:-# route -n
Kernel IP routing table
Destination
Gateway
192.168.0.0
0.0.0.0
10.0.0.192
192.168.0.2
10.0.0.0
0.0.0.0

Genmask
255.255.255.252
255.255.255.192
255.255.255.128

Flags
U
UG
U

Metric Ref Use Iface


0
0
0
eth1
0
0
0
eth1
0
0
0
eth0

Configuracin de Rutas Directas III


Sin embargo, cuando nos fijamos una interfaz hacia abajo todas las rutas indirectas que
utiliza esta interfaz tambin se eliminan de la tabla de enrutamiento.

Si usted no desea este comportamiento, puede utilizar el comando

dev

y la opcin

para crear rutas directas:

r1:~# route -n
Kernel IP routing table
Destination
Gateway
Genmask
192.168.0.0
0.0.0.0
255.255.255.252
10.0.0.192
192.168.0.2 255.255.255.192
10.0.0.0
0.0.0.0
255.255.255.128
r1:~# route del -net 192.168.0.0/30
r1:~# route -n
Kernel IP routing table
Destination
Gateway
Genmask
10.0.0.192
192.168.0.2 255.255.255.192
10.0.0.0
0.0.0.0
255.255.255.128
r1:~# ifconfig eth1 down
r1:~# ifconfig eth1

eth1
Link

route

Flags
U
UG
U0

Flags
UG
U0

encap:Ethernet
HWaddr fe:fd:00:00:02:01
inet addr:192.168.0.1
Beast:192.168.0.3
BROADCAST PROMISC MULTICAST
MTU:1500
RX packets:47 errors:0 dropped:0 overruns:0
TX packets:30 errors:0 dropped:0 overruns:0
collisions:0 txqueuelen:1000
RX bytes:3460 (3.3 KiB) TX bytes:2200 (2.1
Interrupt:5

Metric
0
0
0

Ref Use Iface


0
0
eth1
0
0
eth1
0
0
eth0

Metric Ref Use Iface


0
0
0 eth1
0
0
0 eth0

Mask:255.255.255.252
Metric:1
frame:0
carrier:0
KiB)

Configuracin de Rutas Directas IV


r1:~# route -n
Kernel IP routing table
Destination Gateway
Genmask
Flags Metric Ref Use
10.0.0.0
0.0.0.0
255.255.255.128
U
0
0
0
r1:~# ifconfig eth1 up
r1:~# route add -net 10.0.0.192/26 gw 192.168.0.2
r1:~# route -n
Kernel IP routing table
Destination Gateway
Genmask
Flags
Metric
192.168.0.0 0.0.0.0
255.255.255.252
U
0
10.0.0.192
192.168.0.2 255.255.255.192
UG
0

Iface
eth0

Ref
0
0

Use
0
0

Iface
eth1
eth1

10.0.0.0
0.0.0.0
255.255.255.128
r1:~# route del -net 192.168.0.0/30
r1:~# route -n
Kernel IP routing table
Destination Gateway
Genmask
10.0.0.192 192.168.0.2
255.255.255.192
10.0.0.0
0.0.0.0
255.255.255.128
r1:-# route add -net 192.168.0.0/30 dev eth1
r1:-# route -n
Kernel IP routing table
Destination Gateway
Genmask
192.168.0.0 0.0.0.0
255.255.255.252
10.0.0.192
192.168.0.2 255.255.255.192
10.0.0.0
0.0.0.0
255.255.255.128

Flags Metric
UG
0
U
0

Flags
U
UG
U

Metric
0
0
0

Ref
0
0

Use
0
0

Ref
0
0
0

Use
0
0
0

eth0

Iface
eth1
eth0

Iface
eth1
eth1
eth0

Finalizamos la configuracin del escenario con el menor nmero de entradas posible en las
tablas de enrutamiento (use la coincidencia ms larga) y haga que las rutas por defecto
apunten a Internet.

Вам также может понравиться