# restart networking: debian

**URL:** <https://forum.ansible.com/t/restart-networking-debian/13694>\
**Category:** Ansible Project\
**Created:** [October 16, 2013, 3:58pm UTC](https://forum.ansible.com/t/restart-networking-debian/13694 "2013-10-16T15:58:18Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![senorsmile](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/senorsmile/32/9024_2.png) [@senorsmile](https://forum.ansible.com/u/senorsmile)\
**Post date:** [October 16, 2013, 3:58pm UTC](https://forum.ansible.com/t/restart-networking-debian/13694/1 "2013-10-16T15:58:18Z")

</div>

I am trying to restart the networking on a debian box if the /etc/network/interfaces file is out of sync (i.e. first time setting up this server).

I have tried

- name: restart networking  
service: name=networking state=restarted

But it just hangs.

I have tried

- name: restart networking  
shell: shutdown now -r  
async: 120  
poll: 5

but the next task doesn’t run because it errs out at:  
fatal: [192.168.11.123] =\> SSH encountered an unknown error during the connection.

How do others restart networking?

---

<div class="post-metadata">

**Author:** ![James\_Martin2](https://avatars.discourse-cdn.com/v4/letter/j/b9e5f3/32.png) [@James\_Martin2](https://forum.ansible.com/u/James_Martin2)\
**Post date:** [October 16, 2013, 5:41pm UTC](https://forum.ansible.com/t/restart-networking-debian/13694/2 "2013-10-16T17:41:56Z")

</div>

I can assure you that “shutdown now -r” is not how you restart networking. That will restart you entire machine, which would lead to that fatal error message you’re seeing. As for the first method you mention that is hanging – are you sure the settings you have assigned networking are valid? Why are you restarting the network?

- James

---

<div class="post-metadata">

**Author:** ![senorsmile](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/senorsmile/32/9024_2.png) [@senorsmile](https://forum.ansible.com/u/senorsmile)\
**Post date:** [October 16, 2013, 5:47pm UTC](https://forum.ansible.com/t/restart-networking-debian/13694/3 "2013-10-16T17:47:16Z")

</div>

why? I am dealing with servers with several NIC’s and dozens of virtual IP’s

I realize restarting the client isn’t the ideal solution, but tried it to see if it would work. The interfaces file is fine, as all interfaces come up on reboot just fine.

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [October 16, 2013, 6:02pm UTC](https://forum.ansible.com/t/restart-networking-debian/13694/4 "2013-10-16T18:02:39Z")

</div>

Debian networking is somewhat complicated. The networking init script and networking upstart jobs don’t do what most expect. Those scripts and their underlying utilities only configure what they know about from the interfaces file. If you remove something, or assign an IP to another interface, it won’t deconfigure the previous configuration, it will only apply the newly provided configurations.

Example:

1. 10.10.10.10 on eth0
2. Edit /etc/network/interfaces and remove 10.10.10.10 from eth0 and assign to eth1
3. Restart networking

The result is that you now have 10.10.10.10 on eth0 and eth1, because they don’t fully deconfigure the interface before applying the configuration of the interfaces file.

And it is not exactly straight forward to get it to completely deconfigure all interfaces and then reconfigure on start up.

I have a network init script for Debian/Ubuntu that mimics the functionality of the RHEL network init script at [https://github.com/sivel/scripts/blob/master/ubuntu/network-compat.sh](https://github.com/sivel/scripts/blob/master/ubuntu/network-compat.sh)

Your other options are to use the `ip` command to do all of your work after modifying /etc/network/interfaces, but that could be complicated, without knowing exactly what changed in the interfaces file.

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [October 16, 2013, 6:10pm UTC](https://forum.ansible.com/t/restart-networking-debian/13694/5 "2013-10-16T18:10:17Z")

</div>

ansible -s -K -m service -a “name=networking state=restarted” testmachines , works for me as long as the ip im using to access the box has not changed (wheezy and pangolin).

---

<div class="post-metadata">

**Author:** ![senorsmile](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/senorsmile/32/9024_2.png) [@senorsmile](https://forum.ansible.com/u/senorsmile)\
**Post date:** [October 16, 2013, 8:11pm UTC](https://forum.ansible.com/t/restart-networking-debian/13694/6 "2013-10-16T20:11:27Z")

</div>

That script looks great! On Debian 7, the ifup (and ifdown and ifquery) commands don’t have a -e option, so this errs out.

---

<div class="post-metadata">

**Author:** ![senorsmile](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/senorsmile/32/9024_2.png) [@senorsmile](https://forum.ansible.com/u/senorsmile)\
**Post date:** [October 16, 2013, 8:13pm UTC](https://forum.ansible.com/t/restart-networking-debian/13694/7 "2013-10-16T20:13:28Z")

</div>

Strangely enough, this is basically what I tried before attempting to put it into my playbook. I just tried again and waited about five minutes before determining that the interfaces were never going to come up. From the machine, I can ifup eth0 (the control interface) and ansible continues along happily. However, it doesn’t seem to bring the interfaces back up directly from ansible.

BTW, the client is running Debian 7.

---

<div class="post-metadata">

**Author:** ![senorsmile](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/senorsmile/32/9024_2.png) [@senorsmile](https://forum.ansible.com/u/senorsmile)\
**Post date:** [October 16, 2013, 8:15pm UTC](https://forum.ansible.com/t/restart-networking-debian/13694/8 "2013-10-16T20:15:38Z")

</div>

I should mention that I have also tried simply:

shell: ifdown eth0; ifup eth0

to no avail. Perhaps putting these commands into a shell script, copying the script to the client and then running it would do that trick?

---

<div class="post-metadata">

**Author:** ![senorsmile](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/senorsmile/32/9024_2.png) [@senorsmile](https://forum.ansible.com/u/senorsmile)\
**Post date:** [October 16, 2013, 8:28pm UTC](https://forum.ansible.com/t/restart-networking-debian/13694/9 "2013-10-16T20:28:45Z")

</div>

Simple fix:

### contents of etc.network.restartall

#!/bin/bash

ifdown -a  
ifup -a

---

<div class="post-metadata">

**Author:** ![senorsmile](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/senorsmile/32/9024_2.png) [@senorsmile](https://forum.ansible.com/u/senorsmile)\
**Post date:** [October 16, 2013, 8:29pm UTC](https://forum.ansible.com/t/restart-networking-debian/13694/10 "2013-10-16T20:29:54Z")

</div>

I should add that the switch -a, only affects interfaces marked as auto in /etc/network/interfaces.
