linux: system wide static /etc/network/routes #71
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
please refer to:
https://askubuntu.com/questions/168033/how-to-set-static-routes-in-ubuntu-server
There is a package ifupdown-extra avaible in Ubuntu.
It provides automatic scripts (installed in /etc/network/*/), one of which is used to add static routes.
The configuration file for this is /etc/network/routes
The top of this config file has a good description:
This configuration file is read by the static-routes if-updown script and the /etc/init.d/networking-routes script to setup a list of routes associated either with a given interface or global routes.
An example route I use is:
192.168.240.0 255.255.255.0 192.168.130.3 em3
How to use, in case your default gateway interface is 'enp0s29f7u2c4i2'
$ python chnroutes.py -p routes
$ sed -i 's/Interface/enp0s29f7u2c4i2/g' routes
$
$ # if you didn't have ifupdown-extra installed
$ sudo apt-get install ifupdown-extra
$
$ sudo cat routes >>/etc/network/routes
this is a very draft commit, I don't know have any experience with
python. if any thing goes into issues, please help...
the routes will automatic added when the interface brings up, and also
removed when the interface is down or removed (usb hotspot or usb network
adapter).
the poster writen the nic as 'em3', I guess this maybe also works under
pfsense or *BSD gateways, never know.
Signed-off-by: Du Huanpeng u74147@gmail.com