From 373f0f03ca62f08c9fb5757c6c88bc6fc51fe609 Mon Sep 17 00:00:00 2001 From: crocandr Date: Wed, 2 Jan 2019 17:03:56 +0100 Subject: [PATCH] route file option added --- README.md | 3 ++- config/route.list | 5 +++++ docker-compose.yml | 2 ++ files/start.sh | 29 +++++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 config/route.list diff --git a/README.md b/README.md index ec971cf..cf7a55a 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,8 @@ You can choose working mode on the web page. If you turn on bridge (mode) on the Check my Github page for an example docker-compose.yml file. - modify the `NETWORK_ID` - - modify the `ROUTES` and use `,;,` if you would like to use Site-to-Site function between the networks. But do not forget to add the routes to your router too! + - modify the `ROUTES` and use `,;,;...` if you would like to use Site-to-Site function between the networks. But do not forget to add the routes to your router too (because DHCP clients on LAN use default routes)! + - You can use `config/route.list` files for route rules too. Check the example file for format. ``` docker-compose up -d diff --git a/config/route.list b/config/route.list new file mode 100644 index 0000000..e810ce6 --- /dev/null +++ b/config/route.list @@ -0,0 +1,5 @@ +# format examples: +# space separated +# 192.168.0.0/16 10.144.25.133 +# comma separated +# 10.1.0.0/24,10.144.33.242 diff --git a/docker-compose.yml b/docker-compose.yml index 164a1b9..23f2298 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,6 +6,8 @@ services: environment: - NETWORK_ID=9b............34 # - ROUTES=10.10.12.0/23,10.147.20.115;10.10.14.0/23,10.147.20.220 + volumes: + - './config/route.list:/config/route.list:ro' network_mode: host privileged: true restart: always diff --git a/files/start.sh b/files/start.sh index ea8a7b6..e92f8de 100644 --- a/files/start.sh +++ b/files/start.sh @@ -16,7 +16,10 @@ do sleep 5 done +# # add route rules +# from variable +# if [ ! -z $ROUTES ] then for routeline in $( echo $ROUTES | sed "s@;@\n@g" ) @@ -32,5 +35,31 @@ then ip route fi +# +# add route rules +# from file +# +if [ -e /config/route.list ] +then + echo "Route file found: /config/route.list" + cat config/route.list | while read line + do + for routeline in "$( echo $line | grep -iv '^#' )" + do + # if empty line found - skip this loop + [ -z "$routeline" ] && { continue; } + + ADDR="$( echo $routeline | cut -f1 -d',' | cut -f1 -d' ' )" + GW="$( echo $routeline | cut -f2 -d',' | cut -f2 -d' ' )" + if [ ! -z $ADDR ] && [ ! -z $GW ] + then + echo "adding route ... $ADDR via $GW" + ip route add "$ADDR" via "$GW" + fi + done + done + ip route +fi + # something that keep the container running tail -f /dev/null