¿Cómo reiniciar con éxito una red sin reiniciar a través de SSH?


98

En Ubuntu 14.04 ya no hago sudo service networking restartni sudo /etc/init.d/networking restartnada más. Ambos también salen con el código 1. Algo obviamente ha cambiado (o medio cambiado) pero no puedo encontrar qué. Obviamente, esto causa problemas con la reconfiguración de red remota y herramientas como Ansible.

$ sudo bash -x /usr/sbin/service networking restart
[sudo] password for wirehive:
++ basename /usr/sbin/service
+ VERSION='service ver. 0.91-ubuntu1'
++ basename /usr/sbin/service
+ USAGE='Usage: service < option > | --status-all | [ service_name [ command | --full-restart ] ]'
+ SERVICE=
+ ACTION=
+ SERVICEDIR=/etc/init.d
+ OPTIONS=
+ '[' 2 -eq 0 ']'
+ cd /
+ '[' 2 -gt 0 ']'
+ case "${1}" in
+ '[' -z '' -a 2 -eq 1 -a networking = --status-all ']'
+ '[' 2 -eq 2 -a restart = --full-restart ']'
+ '[' -z '' ']'
+ SERVICE=networking
+ shift
+ '[' 1 -gt 0 ']'
+ case "${1}" in
+ '[' -z networking -a 1 -eq 1 -a restart = --status-all ']'
+ '[' 1 -eq 2 -a '' = --full-restart ']'
+ '[' -z networking ']'
+ '[' -z '' ']'
+ ACTION=restart
+ shift
+ '[' 0 -gt 0 ']'
+ '[' -r /etc/init/networking.conf ']'
+ which initctl
+ grep -q upstart
+ initctl version
+ case "${ACTION}" in
+ stop networking
stop: Job failed while stopping
+ :
+ exec start networking
start: Job is already running: networking

¿Cuál es la forma correcta de reiniciar la red en Ubuntu 14.04 Server de forma remota?


¿Realmente desea reiniciar las redes o simplemente reiniciar una interfaz como eth0? En cualquier caso, probablemente romperá la conexión ssh.
chili555

1
Dado que ambos son scripts de shell, obtenga información con sudo bash -x /usr/sbin/service networking restartysudo bash -x /etc/init.d/networking restart
waltinator

@terdon se volvió un poco tonto tener una etiqueta para 14.04 entonces, especialmente porque la descripción dice que es la versión "actual" que no lo es. Dicho esto, este problema es totalmente reproducible en 13.10.
SimonJGreen

@ chili555 lo que quiero que suceda es que los cambios en / etc / network / interfaces surtan efecto. Antes de que estos scripts dejaran de funcionar, las conexiones SSH sobreviven a este reinicio.
SimonJGreen

@waltinator información adicional agregada a la pregunta, gracias por la sugerencia
SimonJGreen

Respuestas:


121

Resulta que esta es una "característica". La única forma compatible de reiniciar una interfaz en Ubuntu Server essudo ifdown eth0 && sudo ifup eth0

https://bugs.launchpad.net/ubuntu/+source/ifupdown/+bug/1301015


8
Asegúrese de ejecutar 'sudo ifdown eth0 && sudo ifup eth0' (tenga en cuenta el segundo sudo) si no está ejecutando este comando como root
mtpettyp

3
¿Está bien hacerlo si está conectado a través de ssh? Es decir, ¿se ejecutarán ambos comandos antes de la desconexión?
meawoppl

2
En mi caso, correr sudo service networking restartparecía haber arruinado las cosas. Así que tuve que correr sudo ifdown eth0 && sudo ifup eth0dos veces. Sí dos veces.
polarizar

@ExceptionSlayer: No, no funcionaron para mí. Tuve que apagar el servidor físicamente y volver a encenderlo (Ubuntu 14.04).
Xdg

44
¿No está usando una opción en ;lugar de &&una más segura?
Isaac

72

ifdown, ifup no funcionó para mí (probable tiempo de espera de conexión SSH antes del segundo comando). Lo que funcionó fue:

sudo service network-manager restart

Esto fue en un sistema de escritorio ubuntu 14.04.


44
La respuesta aceptada no funcionó para mí; este lo hizo. (Instalación nueva del 14.04.1)
u2n

2
Puedo confirmar que esto funciona para mí en Trusty (Ubuntu 14.04).
gerlos

3
La respuesta "ifdown / ifup" tampoco funcionó para mí en Ubuntu 14.04, pero esto sí.
dieuwe

44
La respuesta aceptada es aplicable para Ubuntu 12.04 y versiones inferiores. Esta respuesta es aceptable para 14.04.
Suiza

44
En mi 14.04.2 este servicio no existe: reinicio de sudo service network-manager.
Xdg

6

Lo que ha cambiado es que ya no quieren que "rebotes" en la red. parando y comenzando, todavía funciona. reiniciar ya no funciona. Acabo de "resolver" este "problema", es decir, recuperé el comportamiento anterior. Para volver al comportamiento anterior: tome un archivo 13.10 /etc/init/networking.conf y reemplace el archivo 14.04 con él. (editar: aclarado cuál reemplaza cuál)

El proceso se ve así:

(Just before this, I configured my /etc/network/interfaces for eth1 on a 192.168.117.x address)

"/etc/network/interfaces" 16L, 413C written  
root@1404-Anode:~# service networking restart  
stop: Job failed while stopping  
start: Job is already running: networking  
root@1404-Anode:~# echo "hmm, wth?"
hmm, wth?
root@1404-Anode:~# ifconfig  
eth0      Link encap:Ethernet  HWaddr 00:0c:29:d6:a8:19  
          inet addr:192.168.115.105  Bcast:192.168.115.255  Mask:255.255.255.0  
          inet6 addr: 2002:4077:9050:1234:a08c:29c1:ce9b:a57b/64 Scope:Global  
          inet6 addr: fe80::20c:29ff:fed6:a819/64 Scope:Link  
          inet6 addr: 2002:4077:9050:1234:20c:29ff:fed6:a819/64 Scope:Global  
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1  
          RX packets:646 errors:0 dropped:0 overruns:0 frame:0  
          TX packets:531 errors:0 dropped:0 overruns:0 carrier:0  
          collisions:0 txqueuelen:1000  
          RX bytes:58748 (58.7 KB)  TX bytes:75465 (75.4 KB)  
(lo removed here)  
root@1404-Anode:~# cd /etc/init
root@1404-Anode:/etc/init# diff networking.conf.1310 networking.conf.1404  
13c13  
<       and (stopped udevtrigger or container)) or runlevel [2345]  
---  
>     and (stopped udevtrigger or container)) or runlevel [2345] or stopped  networking   >RESULT=failed PROCESS=post-stop EXIT_STATUS=100  
16a17,20  
>     if [ "$UPSTART_EVENTS" = "stopped" ] && [ "$UPSTART_JOB" = "networking" ] && [ "$EXIT_STATUS" = "100" ]; then  
>         exit 0  
>     fi  
>  
21a26,31  
>     if [ -z "$UPSTART_STOP_EVENTS" ]; then  
>        echo "Stopping or restarting the networking job is not supported."  
>         echo "Use ifdown & ifup to reconfigure desired interface."  
>         exit 100  
>     fi  
root@1404-Anode:/etc/init#  

Haga lo mismo para el script /etc/init.d/networking, que es lo que el archivo /etc/init/networking.conf hace referencia / llama.

root@1404-Anode:/etc/init# cp networking.conf.1310 networking.conf  
root@1404-Anode:/etc/init# cd ../init.d  
root@1404-Anode:/etc/init.d# diff networking.1404 networking.1310  
15d14  
< STATEDIR="$RUN_DIR/state"
21a21,27
> # Make sure that it's clear to the user that they shouldn't use this
> # script under upstart
> if init_is_upstart; then
>       echo "ERROR: Calling a sysvinit script on a system using upstart isn't supported. Please use the 'service' command instead."  
>       exit 1
> fi
>
52,54d57
<       if ! chown root:netdev "$RUN_DIR" ; then
<           log_warning_msg "can't chown $RUN_DIR"
<       fi
160,162d162
<       if init_is_upstart; then
<               exit 1
<       fi
166c166
<       state=$(ifquery --state)
---
>       state=$(cat /run/network/ifstate)
root@1404-Anode:/etc/init.d# cp networking.1310 networking
root@1404-Anode:/etc/init.d# service networking restart
networking stop/waiting
networking start/running
root@1404-Anode:/etc/init.d# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0c:29:d6:a8:19
          inet addr:192.168.115.105  Bcast:192.168.115.255  Mask:255.255.255.0
          inet6 addr: 2002:4077:9050:1234:a08c:29c1:ce9b:a57b/64 Scope:Global
          inet6 addr: fe80::20c:29ff:fed6:a819/64 Scope:Link
          inet6 addr: 2002:4077:9050:1234:20c:29ff:fed6:a819/64 Scope:Global
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:3398 errors:0 dropped:0 overruns:0 frame:0
          TX packets:2545 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:318654 (318.6 KB)  TX bytes:418804 (418.8 KB)

eth1      Link encap:Ethernet  HWaddr 00:0c:29:d6:a8:23
          inet addr:192.168.117.105  Bcast:192.168.117.255  Mask:255.255.255.0
          inet6 addr: fe80::20c:29ff:fed6:a823/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:98 errors:0 dropped:58 overruns:0 frame:0
          TX packets:15 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:20055 (20.0 KB)  TX bytes:1226 (1.2 KB)
(lo removed)
root@1404-Anode:/etc/init.d# echo "hah, it works! *8^)"
Hah, it works! *8^)
root@1404-Anode:/etc/init.d#

(note: the steps where I scp'd the 1310 versions into the 1404 system are omitted for brevity). 

Obviamente, hay una razón por la que ponen una salida defensiva allí, pero no se molestan en mostrar realmente lo que está sucediendo muy bien.

Una entrada entra en /var/log/upstart/networking.log cuando lo intentas, que se ve así:

Stopping or restarting the networking job is not supported.  
Use ifdown & ifup to reconfigure desired interface.  

Pero realmente podrían / ​​deberían haber salido como mensaje de diálogo cuando intentas reiniciar la red de servicio. Ah bueno. lo descubrí e incluso una solución a la antigua.

EDITAR: He descubierto que esto provoca una activación involuntaria del script controlado por /etc/init/failsafe.conf, lo que no es deseable ya que causa un retraso de 120 segundos en cada arranque ... así como quizás enmascarando configuraciones / redes reales problemas que indicaría la aparición de este retraso, pero ya se muestra todo el tiempo. (por ejemplo, un cable desenchufado, que permitía el acceso a un recurso compartido de archivos de red mapeado en / etc / fstab, por ejemplo)

En cualquier caso, averiguaré qué está causando que esto siempre golpee el tiempo de espera y publicaré una solución cuando lo encuentre.


55
La sabiduría de modificar un comportamiento central del sistema operativo es discutible.
0xF2

¿Por qué eliminaron la capacidad de reiniciar? Me gustaría saber eso antes de restablecerlo.
flickerfly

@ 0xF2 - quieres decir questionable.
Dale Anderson el

@DaleAnderson eso también ;-)
0xF2

3

En referencia a la respuesta de kvm-user420, seguí adelante y configuré un script para reemplazar los scripts de red de Ubuntu 14.04 con el de Ubuntu 13.10

Puede encontrarlo aquí: https://github.com/metral/restore_networking

¡Disfrutar!


Esto funcionó para mí. Con suerte, un día Upstart desaparecerá ;-)
Andrew

0

Arreglo el problema con este script: agregue este script en "/etc/network/if-down.d"

cd /etc/network/if-down.d
vim ifdown

contenido :

#!/bin/bash 

for I in /sys/class/net/* 
do
        ifname=$(basename $I) 
        if [ $ifname != "lo" ] ; then 
                ip addr flush $ifname
        fi
done

y finalmente :

chmod +x ifdown

ahora puede cambiar la dirección IP y reiniciar el servicio de red con systemctl o el comando de servicio.
NOTA : este script es demasiado simple y NO MANEJA vm, tap, bridge, ... interfaces. enjuagar todas las interfaces excluye lo (loopback).

Al usar nuestro sitio, usted reconoce que ha leído y comprende nuestra Política de Cookies y Política de Privacidad.
Licensed under cc by-sa 3.0 with attribution required.