Como reiniciar com sucesso uma rede sem reinicializar através do SSH?

92

No Ubuntu 14.04, nem sudo service networking restart nem sudo /etc/init.d/networking restart fazem mais nada. Eles também saem com o código 1. Algo obviamente mudou (ou mudou pela metade), mas não consigo encontrar o quê. Isso obviamente causa problemas com a reconfiguração remota da rede e ferramentas como o 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 "" 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 "" 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

Qual é a maneira correta de reiniciar a rede no Ubuntu 14.04 Server remotamente?

    
por SimonJGreen 31.03.2014 / 20:27

5 respostas

115

Acontece que este é um "recurso". A maneira suportada apenas de reiniciar uma interface no Ubuntu Server é sudo ifdown eth0 && sudo ifup eth0

link

    
por SimonJGreen 02.04.2014 / 13:03
70
ifdown não funcionou para mim (provável tempo limite de conexão SSH antes do segundo comando). O que funcionou foi:

sudo service network-manager restart

Isso foi em um sistema 14.04 ubuntu-desktop.

    
por dpb 21.04.2014 / 04:25
6

O que mudou é que eles não querem mais que você "salte" na rede. parar e começar ainda funciona. reiniciar não funciona mais. Eu apenas "resolvi" esse "problema", isto é, recuperei o antigo comportamento. Para reverter a um comportamento anterior: Pegue um arquivo 13.10 /etc/init/networking.conf e substitua o arquivo 14.04 por ele. (editar: esclarecido que substitui o que)

O processo é assim:

(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#  

Faça o mesmo para o script /etc/init.d/networking, que é o que o arquivo /etc/init/networking.conf faz referência / chamadas.

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, há uma razão pela qual eles colocam uma saída defensiva lá, mas eles não se importam em mostrar o que está acontecendo muito bem.

Uma entrada entra em /var/log/upstart/networking.log quando você tenta, assim:

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

Mas eles realmente poderiam / deveriam ter uma saída como a mensagem de diálogo quando você tenta reiniciar a rede de serviços. Ah bem. descobri isso e até mesmo um trabalho antigo.

EDIT: Descobri que isso causa um acionamento não intencional do script controlado pelo /etc/init/failsafe.conf, o que é indesejável, pois causa um atraso de timeout de 120 segundos em cada inicialização ... bem como talvez mascarar o real. problemas de configuração de rede / rede que a aparência deste atraso indicaria, mas já está mostrando o tempo todo. (por exemplo, um cabo desconectado, que permitia acesso a um compartilhamento de arquivos de rede mapeado em / etc / fstab, por exemplo)

Em qualquer caso, vou descobrir o que está causando isso sempre atingindo o tempo limite e postar uma correção quando eu encontrá-lo.

    
por kvm-user420 18.04.2014 / 18:56
3

Em referência à resposta do kvm-user420, eu segui em frente e configurei um script para substituir os scripts de rede do Ubuntu 14.04 com o do Ubuntu 13.10

Você pode encontrá-lo aqui: link

Aproveite!

    
por metral 18.04.2014 / 22:23
0

Eu corrijo o problema com este script: por favor adicione este script em "/etc/network/if-down.d"

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

conteúdo:

#!/bin/bash 

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

e finalmente:

chmod +x ifdown

agora você pode alterar o endereço IP e reiniciar o serviço de rede com o comando systemctl ou service.
OBSERVAÇÃO : esse script é muito simples e NÃO MANUSEAR vm, toque em , bridge, ... interfaces. realmente liberar todas as interfaces excluem lo (loopback).

    
por mah454 24.09.2017 / 09:43