How to create post-up and pre-down routes in interfaces file?
19,511
Try with up
and down
instead of post-up
and pre-down
.
Example :
auto eth0
iface eth0 inet static
address 192.168.1.1
netmask 255.255.255.0
up route add -net 192.168.2.0 netmask 255.255.255.0 gw 192.168.1.1
Or, but I didn't test it, you can write a bash script and put it in the folder /etc/network/if-up.d/
and /etc/network/if-down.d/
(you can use the variable $IFACE to know which interface is getting a connection).
In /etc/network/if-up.d/some-script
:
#!/bin/bash
if [[ $IFACE == "eth0" ]]; then
ip route add x.x.x.0/24 via x.x.x.254 dev $IFACE
fi
Hope this help.
Related videos on Youtube
Author by
Biff
Updated on September 18, 2022Comments
-
Biff over 1 year
I recently installed a new VM using Ubuntu 16.04, but I am unable to copy the
post-up
andpre-down
rules that I use in my 14.04 install.Can you please advise what to use? I've added a few notes to indicate what each of my edited out ips are
Example of the 14.04 config:
# The primary network interface auto eth0 iface eth0 inet static address x.x.x.109 #vm ip netmask 255.255.255.255 broadcast x.x.x.109 #vm ip post-up route add x.x.x.254 dev eth0 #root machine gateway post-up route add default gw x.x.x.254 #root machine gateway pre-down route del x.x.x.254 dev eth0 #root machine gateway pre-down route del default gw x.x.x.254 #root machine gateway dns-nameservers 213.186.33.99 8.8.8.8
-
Biff almost 6 yearsSorry, but can anyone help?
-