Static routing.
OVH network assigns IP addresses on a /32 subnet, so we can't add a default gateway because it's outside the subnet.
This commit is contained in:
parent
f05200bffc
commit
c5d95d0e5e
5 changed files with 87 additions and 1 deletions
|
@ -40,6 +40,8 @@ templates:
|
|||
- "/etc/sysctl.d/coredump.conf"
|
||||
- "/etc/docker/daemon.json"
|
||||
- "/etc/ntp.conf"
|
||||
executables:
|
||||
- "/usr/libexec/ifupdown-ng/routes"
|
||||
services:
|
||||
- runlevel: "sysinit"
|
||||
service: "devfs"
|
||||
|
|
|
@ -9,6 +9,12 @@
|
|||
dest: "/mnt{{ item }}"
|
||||
mode: "640"
|
||||
loop: "{{ templates }}"
|
||||
- name: "Also executables."
|
||||
template:
|
||||
src: "templates{{ item }}.j2"
|
||||
dest: "/mnt{{ item }}"
|
||||
mode: "750"
|
||||
loop: "{{ executables }}"
|
||||
- name: "And services."
|
||||
template:
|
||||
src: "templates{{ item }}.j2"
|
||||
|
|
|
@ -7,6 +7,12 @@
|
|||
dest: "{{ item }}"
|
||||
mode: "640"
|
||||
loop: "{{ templates }}"
|
||||
- name: "Also executables."
|
||||
template:
|
||||
src: "templates{{ item }}.j2"
|
||||
dest: "{{ item }}"
|
||||
mode: "750"
|
||||
loop: "{{ executables }}"
|
||||
- name: "And services."
|
||||
template:
|
||||
src: "templates{{ item }}.j2"
|
||||
|
|
|
@ -6,7 +6,7 @@ auto eth0
|
|||
|
||||
iface eth0 inet static
|
||||
address {{ ansible_host }}/{{ netmask }}
|
||||
gateway {{ gateway }}
|
||||
routes-static {{ gateway }},default via {{ gateway }}
|
||||
|
||||
{% if ip6 is defined %}
|
||||
iface eth0 inet6 static
|
||||
|
|
72
templates/usr/libexec/ifupdown-ng/routes.j2
Executable file
72
templates/usr/libexec/ifupdown-ng/routes.j2
Executable file
|
@ -0,0 +1,72 @@
|
|||
#!/bin/sh
|
||||
# https://github.com/ifupdown-ng/ifupdown-ng/issues/42#issuecomment-849135927
|
||||
[ -z "${VERBOSE}" ] || set -x
|
||||
|
||||
# routes-static 1.2.3.0/24,10.0.0.0/8 via 1.2.3.4
|
||||
# routes-rule dport 25 table 123,dport 587 table 123
|
||||
|
||||
# adds $3 to $1 if $1 does not contain $2
|
||||
addif() {
|
||||
if [ "$1" = "${1%$2*}" ]; then
|
||||
echo $1 $3
|
||||
else
|
||||
echo $1
|
||||
fi
|
||||
}
|
||||
decidr() {
|
||||
echo "${1%/*}"
|
||||
}
|
||||
addsrc() {
|
||||
addif "$1" src "src $(decidr $IF_ADDRESS)"
|
||||
}
|
||||
adddev() {
|
||||
addif "$1" dev "dev $IFACE"
|
||||
}
|
||||
|
||||
# $1: input string
|
||||
# $2: delimeter
|
||||
# $3: function to call
|
||||
foreach() {
|
||||
list="$1"
|
||||
|
||||
while [ -n "$list" ]; do
|
||||
line="${list%%$2*}"
|
||||
list="${list#*$2}"
|
||||
"$3" "$line"
|
||||
|
||||
[ "$line" = "$list" ] && break
|
||||
done
|
||||
}
|
||||
|
||||
# add a route
|
||||
prep() {
|
||||
route="$1"
|
||||
route=$(addsrc "$route")
|
||||
route=$(adddev "$route")
|
||||
echo $route
|
||||
}
|
||||
routeadd() {
|
||||
${MOCK} ip route add $(prep "$1")
|
||||
}
|
||||
routedel() {
|
||||
${MOCK} ip route del $(prep "$1")
|
||||
}
|
||||
|
||||
ruleadd() {
|
||||
${MOCK} ip rule add $1
|
||||
}
|
||||
ruledel() {
|
||||
${MOCK} ip rule del $1
|
||||
}
|
||||
|
||||
case "$PHASE" in
|
||||
up)
|
||||
foreach "$IF_ROUTES_STATIC" , routeadd
|
||||
foreach "$IF_ROUTES_RULE" , ruleadd
|
||||
;;
|
||||
down)
|
||||
foreach "$IF_ROUTES_STATIC" , routedel
|
||||
foreach "$IF_ROUTES_RULE" , ruledel
|
||||
;;
|
||||
*) exit 0 ;;
|
||||
esac
|
Loading…
Reference in a new issue