0

I am setting up a new server with 18.04 based on instructions written for 14.04. I have got as far as these steps:

/sbin/iptables -A FORWARD -p tcp --destination-port 80 -j ACCEPT
/sbin/iptables -t nat -A PREROUTING -j REDIRECT -p tcp --destination-port 80 --to-ports 8080
/sbin/iptables-save
# To save permanently (reset-persistent):
sudo sh -c "iptables-save > /etc/iptables.rules"
# Modify in /etc/network/interfaces
# Add this line:
    pre-up iptables-restore < /etc/iptables.rules    
# As below:

# The loopback network interface
auto lo
iface lo inet loopback
    pre-up iptables-restore < /etc/iptables.rules

# The primary network interface
auto eth0 eth1
iface eth0 inet static
        address XXX.XXX.XX.XXX
        netmask 255.255.255.0
        gateway XXX.XXX.XX.1
        dns-nameservers 8.8.4.4 8.8.8.8 XXX.XXX.0.3
iface eth1 inet static
        address XX.XXX.67.47
        netmask 255.255.0.0

But it turns out that 18.04 does things a different way, using something called netplan.

I have found questions and answers related to how to revert back to how things were done in 14.04, but I am wondering whether it is better to do the same thing the new way.

How can I do what is being done the old way using netplan?

  • As you can probably tell from my question, I don't really know what I'm doing. This may have already been asked, but if there is already such a question, I don't have the knowledge to find it. – Matthew Taylor Feb 13 at 14:35
  • A good reference to look at for help is netplan.io/examples – heynnema Feb 13 at 15:41
  • @heynnema Thanks. I've already looked at that, but as i don't know what these steps do, I can't translate into netplan. – Matthew Taylor Feb 13 at 16:21
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

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

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