Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

 

Subtitle
Prefixfigure
SubtitleTextstatic route tab
AnchorNamestatic_route_tab

Image Modified

Subtitle
Prefixfigure
SubtitleTextstatic route create
AnchorNamestatic_route_create

Image Modified

Subtitle
Prefixfigure
SubtitleTextstatic route created
AnchorNamestatic_route_created

Image Modified

Subtitle
Prefixfigure
SubtitleTextstatic route list
AnchorNamestatic_route_list

Image Modified

Subtitle
Prefixfigure
SubtitleTextstatic route edit delete
AnchorNamestatic_route_edit_delete

Image Modified

Warning
The static routes configuration is an advanced topic. It has to be done only if strictly necessary and can lead to serious communication issues if not perfectly understood.
Note

The following lines are partially excerpted from the http://www.centos.org/docs/5/html/5.1/Deployment_Guide/s1-networkscripts-static-routes.html page. All rights granted.

Static route configuration is stored in a /etc/sysconfig/network-scripts/route-interface file. For example, static routes for the eth0 interface would be stored in the /etc/sysconfig/network-scripts/route-eth0 file. The route-interface file has two formats: IP command arguments and network/netmask directives. We will refer just to the first case.

IP Command Arguments Format

Define a default gateway on the first line. This is only required if the default gateway you set above is not good for this NIC

default X.X.X.X dev interface

X.X.X.X is the IP address of the default gateway. The interface is the interface that is connected to, or can reach, the default gateway.

Define a static route. Each line is parsed as an individual route:

X.X.X.X/X via X.X.X.X dev interface

X.X.X.X/X is the network number and netmask for the static route. X.X.X.X and interface are the IP address and interface for the default gateway respectively. The X.X.X.X address does not have to be the default gateway IP address. In most cases, X.X.X.X will be an IP address in a different subnet, and interface will be the interface that is connected to, or can reach, that subnet. Add as many static routes as required.

The following is a sample route-eth0 file using the IP command arguments format. The default gateway is 192.168.0.1, interface eth0. The two static routes are for the 10.10.10.0/24 and 172.16.1.0/24 networks:

default 192.168.0.1 dev eth0
10.10.10.0/24 via 192.168.0.1 dev eth0
172.16.1.0/24 via 192.168.0.1 dev eth0

Static routes should only be configured for other subnets. The above example is not necessary, since packets going to the 10.10.10.0/24 and 172.16.1.0/24 networks will use the default gateway anyway. Below is an example of setting static routes to a different subnet, on a machine in a 192.168.0.0/24 subnet. The example machine has an eth0 interface in the 192.168.0.0/24 subnet, and an eth1 interface (10.10.10.1) in the 10.10.10.0/24 subnet:

10.10.10.0/24 via 10.10.10.1 dev eth1

 

Warning
titleDuplicate Default Gateways

If the default gateway is already assigned from DHCP, the IP command arguments format can cause one of two errors during start-up, or when bringing up an interface from the down state using the ifup command: "RTNETLINK answers: File exists" or 'Error: either "to" is a duplicate, or "X.X.X.X" is a garbage.', where X.X.X.X is the gateway, or a different IP address. These errors can also occur if you have another route to another network using the default gateway. Both of these errors are safe to ignore.

 

Navbar