service networking restart does not apply changes
tersmitten opened this issue · 2 comments
tersmitten commented
- http://www.configserverfirewall.com/ubuntu-linux/ubuntu-restart-network-interface/
- http://manpages.ubuntu.com/manpages/precise/man5/interfaces.5.html
- http://askubuntu.com/questions/441619/how-to-successfully-restart-a-network-without-reboot-over-ssh/449916#449916
- http://askubuntu.com/questions/656232/ifquery-working-but-not-ifdown-or-ifup
tersmitten commented
# 14.04
ip addr flush eth0;
service restart networking;
# 16.04
ip addr flush eth0;
systemctl restart networking;
# all
# --read-environment does not exist (in older versions)
[ -n "$(ifquery --list --exclude=lo)" ] && udevadm settle;
# will disconnect
ip addr flush;
ip addr flush eth0;
# works
ifdown -a --exclude=lo || true && ifup -a --exclude=lo;
# cat /lib/systemd/system/networking.service
[Unit]
Description=Raise network interfaces
Documentation=man:interfaces(5)
DefaultDependencies=no
Wants=network.target
After=local-fs.target network-pre.target apparmor.service systemd-sysctl.service systemd-modules-load.service
Before=network.target shutdown.target network-online.target
Conflicts=shutdown.target
[Install]
WantedBy=multi-user.target
WantedBy=network-online.target
[Service]
Type=oneshot
EnvironmentFile=-/etc/default/networking
ExecStartPre=-/bin/sh -c '[ "$CONFIGURE_INTERFACES" != "no" ] && [ -n "$(ifquery --read-environment --list --exclude=lo)" ] && udevadm settle'
ExecStart=/sbin/ifup -a --read-environment
ExecStop=/sbin/ifdown -a --read-environment --exclude=lo
RemainAfterExit=true
TimeoutStartSec=5min
# cat /etc/default/networking
# Configuration for networking init script being run during
# the boot sequence
# Set to 'no' to skip interfaces configuration on boot
#CONFIGURE_INTERFACES=yes
# Don't configure these interfaces. Shell wildcards supported/
#EXCLUDE_INTERFACES=
# Set to 'yes' to enable additional verbosity
#VERBOSE=no
root@app-staging-02:/root
# ifquery --read-environment --list --exclude=lo
eth0
root@build-03:/root
# ifquery --read-environment --list --exclude=lo
eth2
tersmitten commented
[ -n "$(ifquery --list --exclude=lo)" ] && udevadm settle && ip addr flush eth0 && (ifdown eth0 --exclude=lo || true) && ifup eth0 --exclude=lo;
[ -n "$(ifquery --list --exclude=lo)" ] && udevadm settle && ip addr flush enp0s3 && (ifdown enp0s3 --exclude=lo || true) && ifup enp0s3 --exclude=lo;
[ -n "$(ifquery --list --exclude=lo)" ] && udevadm settle && ip addr flush eth1 && (ifdown eth1 --exclude=lo || true) && ifup eth1 --exclude=lo;
[ -n "$(ifquery --list --exclude=lo)" ] && udevadm settle && ip addr flush enp0s8 && (ifdown enp0s8 --exclude=lo || true) && ifup enp0s8 --exclude=lo;