GNU/Linux: Persistent routing entries

Step-by-Step descriptions of how to do things.
Post Reply
User avatar
peter_b
Chatterbox
Posts: 370
Joined: Tue Nov 12, 2013 2:05 am

GNU/Linux: Persistent routing entries

Post by peter_b »

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:

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
For example:

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:
[TARGET] dev [NETWORK_DEVICE]
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:

Code: Select all

# This routing entry allows to access the .200.0/24 network on eth1:
192.168.200.0/24 dev eth1
Post Reply