GNU/Linux: Persistent routing entries
Posted: Mon Mar 23, 2015 11:29 am
HowTo add persistent, reboot-safe routing table entries on GNU/Linux systems
On Debian (v6, v7):
1) Edit the file "/etc/network/interfaces":
Edit or add the corresponding entry for the interface you'd like to define a new route for.
2) Add your desired routing table entry at the bottom of your "iface" rules:
For example:
On Red Hat Enterprise Linux (v6):
1) Create (or edit) the file "/etc/sysconfig/network-scripts/route-ethX":
Replace "ethX" with the corresponding name of your network interface on your machine which to apply the route to.
For example, "route-eth0" for routes for interface "eth0".
2) Add your desired routing table entry in that file:
For routing whole subnets, the syntax is:
On Debian (v6, v7):
1) Edit the file "/etc/network/interfaces":
Edit or add the corresponding entry for the interface you'd like to define a new route for.
2) Add your desired routing table entry at the bottom of your "iface" rules:
Code: Select all
# Routing to .200.0/24 subnet:
post-up route add -net 192.168.200.0 netmask 255.255.255.0 dev eth1
pre-down route del -net 192.168.200.0 netmask 255.255.255.0
Code: Select all
auto eth1
iface eth1 inet dhcp
# Routing to .200.0/24 subnet:
post-up route add -net 192.168.200.0 netmask 255.255.255.0 dev br1
pre-down route del -net 192.168.200.0 netmask 255.255.255.0
On Red Hat Enterprise Linux (v6):
1) Create (or edit) the file "/etc/sysconfig/network-scripts/route-ethX":
Replace "ethX" with the corresponding name of your network interface on your machine which to apply the route to.
For example, "route-eth0" for routes for interface "eth0".
2) Add your desired routing table entry in that file:
For routing whole subnets, the syntax is:
For example, to add routing to the "192.168.200.0" subnet with the classic 24-bit netmask "255.255.255.0", route-ethX looks like this:[TARGET] dev [NETWORK_DEVICE]
Code: Select all
# This routing entry allows to access the .200.0/24 network on eth1:
192.168.200.0/24 dev eth1