ubuntu:network:routing:create_a_persistent_static_route
Differences
This shows you the differences between two versions of the page.
ubuntu:network:routing:create_a_persistent_static_route [2020/08/19 15:18] – created 192.168.1.1 | ubuntu:network:routing:create_a_persistent_static_route [2021/01/07 10:46] (current) – removed peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Ubuntu - Network - Routing - Create a persistent static route ====== | ||
- | |||
- | To create a persistent static route to a remote network via a gateway. | ||
- | |||
- | ---- | ||
- | |||
- | ===== Scenario ===== | ||
- | |||
- | Suppose that a host is connected via eth0 to the subnet 192.168.0.0/ | ||
- | |||
- | The default gateway for this subnet is 192.168.0.1, | ||
- | |||
- | ---- | ||
- | |||
- | ===== Method ===== | ||
- | |||
- | Ideally the route should be added immediately after the relevant interface has been brought up, and removed immediately before it is taken down. | ||
- | |||
- | This can be achieved using up and down commands in **/ | ||
- | |||
- | First ensure that the relevant interface is down (if it is not already): | ||
- | |||
- | <file bash / | ||
- | ifdown eth0 | ||
- | </ | ||
- | |||
- | Next add suitable up and down commands to the relevant interface definition within the interfaces file. | ||
- | |||
- | If an interface definition does not already exist then you will need to add one: | ||
- | |||
- | <file bash / | ||
- | auto eth0 | ||
- | iface eth0 inet static | ||
- | address 192.168.0.7 | ||
- | netmask 255.255.255.0 | ||
- | gateway 192.168.0.1 | ||
- | up /sbin/route add -net 10.0.0.0 netmask 255.0.0.0 gw 192.168.0.2 | ||
- | down /sbin/route del -net 10.0.0.0 netmask 255.0.0.0 | ||
- | </ | ||
- | |||
- | If there is more than one route to be created then this can be done using multiple up and down commands. | ||
- | |||
- | Once the interfaces file has been modified, bring the interface back up: | ||
- | |||
- | <code bash> | ||
- | ifup eth0 | ||
- | </ | ||
- | |||
- | ---- | ||
- | |||
- | ===== Testing ===== | ||
- | |||
- | Print the routing table using the route command: | ||
- | |||
- | <code bash> | ||
- | route -n | ||
- | </ | ||
- | |||
- | When the interface is up you should be able to see the new route (the line with a destination of 10.0.0.0): | ||
- | |||
- | <code bash> | ||
- | Kernel IP routing table | ||
- | Destination | ||
- | 192.168.0.0 | ||
- | 10.0.0.0 | ||
- | 0.0.0.0 | ||
- | </ | ||
- | |||
- | If you take the interface down again then all three of these routes should disappear. | ||
- | |||
- | ---- | ||
- | |||
- | ===== Troubleshooting ===== | ||
- | |||
- | ==== Network is unreachable ==== | ||
- | |||
- | If ifup gives an error of the form: | ||
- | |||
- | <code bash> | ||
- | SIOCADDRT: Network is unreachable | ||
- | Failed to bring up eth0. | ||
- | </ | ||
- | |||
- | then the likely cause is that the specified gateway is not directly reachable via any local interface. | ||
- | |||
- | ---- | ||
- | |||
- | ==== No such process ==== | ||
- | |||
- | In place of ' | ||
- | |||
- | <code bash> | ||
- | SIOCDELRT: No such process | ||
- | Failed to bring up eth0. | ||
- | </ | ||
- | |||
- | ---- | ||
- | |||
- | ==== File exists ==== | ||
- | |||
- | An error of the form: | ||
- | |||
- | <code bash> | ||
- | SIOCADDRT: File exists | ||
- | Failed to bring up eth0. | ||
- | </ | ||
- | |||
- | indicates that there is already a route to the specified destination via the specified gateway. | ||
- | |||
- | One way this could happen is by bringing the interface up manually (using ifconfig and route) and then attempting to bring it up using ifup. | ||
- | |||
- | If you suspect that something like this has happened then you should manually restore the interface and routing table (using ifconfig and route) to the state expected by ifup and ifdown. | ||
ubuntu/network/routing/create_a_persistent_static_route.1597850308.txt.gz · Last modified: 2020/08/19 15:18 by 192.168.1.1