systemadmin.es > Redes > Cambiar la máscara de red

Cambiar la máscara de red

El comando ifconfig va a ser progresivamente substituido por ip. Vamos a ver como cambiar la máscara de red sin cortes mediante el comando ip.

Mediante ip addr show podemos ver un equivalente a ifconfig:

[root@hook ~]# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 qlen 1000
    link/ether 00:24:00:69:ff:b4 brd ff:ff:ff:ff:ff:ff
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 qlen 1000
    link/ether 00:24:00:69:ff:b4 brd ff:ff:ff:ff:ff:ff
4: sit0: <NOARP> mtu 1480 qdisc noop 
    link/sit 0.0.0.0 brd 0.0.0.0
5: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue 
    link/ether 00:24:00:69:ff:b4 brd ff:ff:ff:ff:ff:ff
    inet 10.12.50.86/28 brd 10.12.50.95 scope global bond0
    inet6 fe80::224:1337:10ff:ffb4/64 scope link 
       valid_lft forever preferred_lft forever

Para cambiar la máscara de red primero deberemos calcular la dirección de broadcast, por ejemplo mediante ipcalc:

# ipcalc -b 10.10.10.86/27
BROADCAST=10.10.10.95

A continuación añadimos al interfaz la misma IP con la máscara diferente y la IP de broadcast calculada:

# ip addr add 10.12.50.86/27 broadcast 10.12.50.95 dev bond0

Podremos ver como no hemos perdido conectividad y con ip addr show nos muestra la interfaz con las dos máscaras:

# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 qlen 1000
    link/ether 00:24:00:69:ff:b4 brd ff:ff:ff:ff:ff:ff
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 qlen 1000
    link/ether 00:24:00:69:ff:b4 brd ff:ff:ff:ff:ff:ff
4: sit0: <NOARP> mtu 1480 qdisc noop 
    link/sit 0.0.0.0 brd 0.0.0.0
5: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue 
    link/ether 00:24:00:69:ff:b4 brd ff:ff:ff:ff:ff:ff
    inet 10.12.50.86/28 brd 10.12.50.95 scope global bond0
    inet 10.12.50.86/27 brd 10.12.50.95 scope global bond0
    inet6 fe80::224:1337:10ff:ffb4/64 scope link 
       valid_lft forever preferred_lft forever

A continuación ya podemos eliminar la IP con la máscara anterior:

# ip addr del 10.12.50.86/28 dev bond0

Podremos ver el cambio aplicado:

# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 qlen 1000
    link/ether 00:24:00:69:ff:b4 brd ff:ff:ff:ff:ff:ff
3: eth1: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 qlen 1000
    link/ether 00:24:00:69:ff:b4 brd ff:ff:ff:ff:ff:ff
4: sit0: <NOARP> mtu 1480 qdisc noop 
    link/sit 0.0.0.0 brd 0.0.0.0
5: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue 
    link/ether 00:24:00:69:ff:b4 brd ff:ff:ff:ff:ff:ff
    inet 10.12.50.86/27 brd 10.12.50.95 scope global bond0
    inet6 fe80::224:1337:10ff:ffb4/64 scope link 
       valid_lft forever preferred_lft forever

A continuación deberemos recordar de cambiar la máscara en los scripts de inicio, en RedHat y derivados en /etc/sysconfig/network-scripts/. Para el caso del bond0 sería:

/etc/sysconfig/network-scripts/ifcfg-bond0 

Deja un comentario:

XHTML - Tags permitidos:<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>