1

This question is an exact duplicate of:

I used pre-up in /etc/network/interfaces. It's strange, I have two Ubuntu server, one a PC and another a VPS. This method works on my PC but not on my VPS.

This is the /etc/network/interfaces on my PC

# ifupdown has been replaced by netplan(5) on this system.  See
# /etc/netplan for current configuration.
# To re-enable ifupdown on this system, you can run:
#    sudo apt install ifupdown

auto dsl-provider
iface dsl-provider inet ppp
pre-up /bin/ip link set eno1 up # line maintained by pppoeconf
provider dsl-provider

#auto eno1
#iface eno1 inet manual

pre-up iptables-restore < /etc/iptables.rules

This is the /etc/network/interfaces on my VPS

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
pre-up iptables-restore < /etc/iptables.rules

source /etc/network/interfaces.d/*

marked as duplicate by Mitch 2 days ago

This question was marked as an exact duplicate of an existing question.

0

Netplan does not support hook scripts:

https://netplan.io/faq#use-pre-up-post-up-etc-hook-scripts

The workaround is to use networkd-dispatcher. The above FAQ gives an example on how to do it.

The following is an example of using networkd-dispatcher to run existing ifup hooks via a script installed in /etc/networkd-dispatcher/routable.d/50-ifup-hooks:

#!/bin/sh

for d in up post-up; do
    hookdir=/etc/network/if-${d}.d
    [ -e $hookdir ] && /bin/run-parts $hookdir
done
exit 0

Similarly, here is an example of an ifdown hook installed in /etc/networkd-dispatcher/off.d/50-ifdown-hooks:

#!/bin/sh

for d in down post-down; do
    hookdir=/etc/network/if-${d}.d
    [ -e $hookdir ] && /bin/run-parts $hookdir
done
exit 0

Not the answer you're looking for? Browse other questions tagged or ask your own question.