How to restart the networking service?

1,841,087

Solution 1

For Desktops

Try

sudo service network-manager restart

Or on recent Ubuntu versions:

sudo systemctl restart systemd-networkd

instead.

Ubuntu uses network-manager instead of the traditional Linux networking model. so you should restart the network-manager service instead of the network service. Or use ifup/down.

For Servers

Check this answer.

Solution 2

For Servers

Restarting networking on a desktop machine will cause dbus and a bunch of service to stop and never be started again, usually leading to the whole system being unusable.

As Ubuntu does event based network bring up, there quite simply isn't a way to undo it all and redo it all, so a restart just isn't plain possible. The recommended way instead is to use ifdown and ifup on the interfaces you actually want to reconfigure:

sudo ifdown --exclude=lo -a && sudo ifup --exclude=lo -a

Solution 3

You could try

ifconfig eth0 down && ifconfig eth0 up

(or whatever your network interface is called) to restart the network.

Solution 4

ubuntu CLI: to restart the network service either

sudo /etc/init.d/networking restart

or

ifdown eth0
ifup eth0

Solution 5

For ubuntu server 18.04, this works :

sudo systemctl restart systemd-networkd
Share:
1,841,087

Related videos on Youtube

waspinator
Author by

waspinator

Updated on September 18, 2022

Comments

  • waspinator
    waspinator over 1 year

    I tried to use

    sudo service networking restart
    

    and

    sudo /etc/init.d/network restart
    

    but they both crash the window manager and I can no longer use my keyboard for input into X.

    when I use the /etc/init.d/ method it complains saying that I should use the service utility

    e.g. service networking restart
    

    but it crashes just the same.

    Is there a GUI method of restarting networking?

    • Admin
      Admin almost 11 years
      I also faced similar issue on Gnome 3 on Ubuntu 13.03. Screen disorted as top bar gone. Short keys not worked. As no menu/Activies shown I get no way to operate the system. Luckily console was opened already. So reboot command can be typed.
    • Admin
      Admin over 9 years
      if you are looking for GUI method just open dash, type "Network" and select that. now press "On/Off" button to turn off and again click to on. your networking is restarted now.
  • Marilou
    Marilou over 10 years
    I'm getting ifup: failed to open lockfile /run/network/.ifstate.lock: Permission denied even on --force
  • aProperFox
    aProperFox over 10 years
    @waspinator - it happens to me too. (FYI.)
  • waspinator
    waspinator almost 10 years
    @Jorge Castro: is this behavior going to be fixed, or is it broken by design?
  • Jorge Castro
    Jorge Castro almost 10 years
    @waspinator the bug is marked fixed as of march of this year: bugs.launchpad.net/ubuntu/+source/dbus/+bug/1072518
  • Samveen
    Samveen almost 10 years
    This does not restart the network services, that is, no retry for DHCP addresses etc.
  • moritz
    moritz about 9 years
    ... as far as I know, this doesn't update the interface's config according to /etc/network/interfaces ... which you might want
  • tarkeshwar
    tarkeshwar about 9 years
    When using sudo: sudo ifconfig eth0 down && sudo ifconfig eth0 up. Otherwise if you are connected over ssh, you will have to reboot machine.
  • wolfgang
    wolfgang over 8 years
    I get a ifdown: interface eth0 not configured RTNETLINK answers: File exists Failed to bring up eth0.
  • Jon B
    Jon B over 8 years
    after trying ifup/ifdown and the reg service networking call, this finally worked for me
  • Jeff Atwood
    Jeff Atwood over 8 years
    what's the purpose of exclude=lo here?
  • Abdennour TOUMI
    Abdennour TOUMI over 8 years
    Autocomplete give networking, however , the right cmd is network-manager
  • SomeoneSomewhereSupportsMonica
    SomeoneSomewhereSupportsMonica almost 8 years
    @JeffAtwood Loopback is used for X, dbus etc. Disabling it causes... issues.
  • Derek Mahar
    Derek Mahar over 7 years
    Worked on Ubuntu Server 16.04.1. Ubuntu Server doesn't appear to include Network Manager, so askubuntu.com/a/230751/13756 doesn't work.
  • cloudsurfin
    cloudsurfin over 7 years
    Try "systemctl restart networking.service" on server 16.04.
  • Underverse
    Underverse over 7 years
    How is this better than sudo service network-manager restart and why?
  • danijelc
    danijelc over 7 years
    This is solution which works always on 16.04. In my experience Ubuntu 16.04 have issues to restart Wi-Fi after returning from hibernation.
  • kcpr
    kcpr over 7 years
    @Underverse, I believe that sudo service network-manager restart just didn't work for me when posting this answer.
  • josircg
    josircg about 7 years
    This used to work for older kernels. Now it seems that do not work indeed. Prefered ifconfig eth0 down & ifconfig eth0 up
  • Jonathan
    Jonathan about 7 years
    I wish I had tried Jorge's answer first.
  • Nikolay Kostov
    Nikolay Kostov almost 7 years
    Beware not to use this command when connecting on remote machine.
  • gilad905
    gilad905 almost 6 years
    I think it's better than the accepted answer because ifup doesn't handle bonded interfaces correctly, while ifconfig does
  • Eduardo Lucio
    Eduardo Lucio over 5 years
    The ifdown --exclude=lo -a && ifup --exclude=lo -a command did not work for Ubuntu Server 14.04. The ifconfig eth0 down && ifconfig eth0 up command worked (askubuntu.com/a/230804/134723).
  • Gringo Suave
    Gringo Suave over 5 years
    Don't need the ".service" part at the end.
  • van abel
    van abel over 5 years
    Thus save my life, since I run /etc/init.d/iptables restart on my VPS, which turns the host has no ip address even after reboot. This solves my problem.
  • Ejoso
    Ejoso about 5 years
    As of 18.04.2 the answer is: systemctl restart systemd-networkd
  • LandiLeite
    LandiLeite almost 4 years
    To new LTS 20.04 the comand above work, thanks!
  • user643722
    user643722 over 3 years
    On my Desktop system this answer gave me Failed to restart network-manager.service: Unit network-manager.service not found. I found the answer from @dagrha seems to work.
  • Mohammed Noureldin
    Mohammed Noureldin over 2 years
    I confirm! This works on 20.04! Thanks!
  • Moritz Friedrich
    Moritz Friedrich over 2 years
    Why oh why do they change the name every year. Sigh. That works on 20.04.