Difference between revisions of "Static Routes in Redhat"
From Free Knowledge Base- The DUCK Project: information for everyone
(New page: <nowiki>-------------------------------------------------------------------------------</nowiki> <nowiki>-- Static Routes in Redhat - New isn't always better (static-routes) --</...) |
m (Protected "Static Routes in Redhat" [edit=sysop:move=sysop]) |
(No difference)
|
Latest revision as of 14:27, 26 June 2007
------------------------------------------------------------------------------- -- Static Routes in Redhat - New isn't always better (static-routes) -- ------------------------------------------------------------------------------- This document discusses traditional routing and the static-routes configuration. The document does not cover iproute2 and the 'ip' commands. With the introduction of Redhat version 8 and continued into version 9, the /etc/sysconfig/static-routes file no longer seems to function correctly. Linux static routes changed in 8.0 to a new format. Now you are to create a file in /etc/sysconfig/network-scripts for each Ethernet interface you wish to create static routes on. for example: touch /etc/sysconfig/network-scripts/route-eth0 The syntax for this file is different from the traditional route format used in /etc/sysconfig/static-routes . Redhat has yet to document the change on their web site as of June 2003. Syntax based on a usenet post (we have been unable to verify this): go to /etc/sysconfig/network-scripts Make a file called route-devicename (ex: route-eth0) and populate it with your static routes for that device so if you wanted to make a static route to the 192.168.0.0/24 network through 152.3.182.5 type: 192.168.0.0/24 via 152.3.182.5 [persistent static routes for ANY linux distribution] ------------------------------------------------------------------------------- You may use this method to add static routes and it will work under any Linux distribution. However, it is considered by some a 'hack' or the 'ugly way'. edit your /etc/rc.local file 'vi /etc/rc.local' and add your static routes using the route statement. for example: route add -net 10.10.98.0 netmask 255.255.255.0 gw 10.164.234.132 dev eth1 route add -net 10.164.234.96 netmask 255.255.255.252 gw 10.164.234.132 dev eth1 route add -net 10.164.234.112 netmask 255.255.255.240 gw 10.164.234.132 dev eth1 [a word on the default static route] ------------------------------------------------------------------------------- The default route of your system has network 0.0.0.0 and netmask 0.0.0.0 with only the gateway of the router device. for example: route add -net 0.0.0.0 netmask 0.0.0.0 gw 10.164.234.132 -or- route add default gw 10.164.234.132 - or specify an interface- route add -net 0.0.0.0 netmask 0.0.0.0 gw 10.164.234.132 ethX route add default gw 10.164.234.132 ethX yeilds same result as having GATEWAY=10.164.234.132 in /etc/sysconfig/network in routing table (route -nv) looks like this: 0.0.0.0 10.164.234.132 0.0.0.0 UG 0 0 0 ethX Now everything to 17.102.0.0/16 to go though one gateway and everything else defaults to the default route. for example: route add default gw 10.164.234.132 route add -net 17.102.0.0 netmask 255.255.0.0 gw 10.40.1.1 [force the old static-routes file to work under Redhat 8 - 9] ------------------------------------------------------------------------------- Clear out the new /etc/sysconfig/network-scripts/ifup-routes script so that you can populate it with the original shell script from Redhat 7.x. cat /dev/null > /etc/sysconfig/network-scripts/ifup-routes vi /etc/sysconfig/network-scripts/ifup-routes type in the following (or copy and paste) not including the tilde lines: ~start typing~ #!/bin/sh # adds static routes which go through device $1 if [ "$1" = "" ]; then echo "usage: $0 <net-device>" exit 1 fi if [ ! -f /etc/sysconfig/static-routes ]; then exit 0 fi #note the trailing space in the grep gets rid of aliases grep "^$1 " /etc/sysconfig/static-routes | while read device args; do /sbin/route add -$args $device done grep "^any " /etc/sysconfig/static-routes | while read ignore type net netmask mask bogus dev ; do if [ "$dev" = "$1" ]; then /sbin/route add -$type $net $netmask $mask $dev fi done ~stop typing~ [syntax for adding routes into /etc/sysconfig/static-routes] ------------------------------------------------------------------------------- example: eth0 net 0.0.0.0 netmask 0.0.0.0 gw 10.164.234.254 eth2 net 0.0.0.0 netmask 0.0.0.0 gw 192.168.1.1 eth2 net 192.168.1.0 netmask 255.255.255.252 gw 192.168.1.1 [remember to use /etc/sysconfig/network for your default gateway] ------------------------------------------------------------------------------- If you only intend to add one route, your default gateway, then you need not worry about the static routes file or using the route command. Simply add your default gateway in /etc/sysconfig/network. example: NETWORKING=yes HOSTNAME="hostname.linux.org" GATEWAY="10.164.234.1" GATEWAYDEV="eth0" FORWARD_IPV4="yes" 169.254.0.0 Automatic Private IP Addressing (www.zeroconf.org) -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- The 169.254.0.0 is the windows Automatic Private IP Addressing(APIPA). If your computer cannot detect dhcp, you may want to try to disable this service in windows. You will get served the 169.254.~.~ address if dhcp is unsuccessful. Zero Configuration Networking: 169.254.0.0 is a pseudo private class b that windows boxen default to if they can't find a dhcp server to use, it's all part of microsofts plan to get people that have know idea what they are doing to network their pc's. Redhat Linux added this 'feature' in version 9. Look in the script file /etc/sysconfig/network-scripts/ifup for ip route replace 169.254.0.0/16 and a reference in /etc/sysconfig/network-scripts/network-functions-ipv6 Adding NOZEROCONF=yes to all ifcfg interfaces including ifcfg-lo will eliminate the unnecessary route. To immediately remove the route type: route del -net 169.254.0.0 netmask 255.255.0.0 gw 0.0.0.0 dev eth0 ------------------------------------------------------------------------------- Wed Jun 25 17:27:38 CDT 2003 Fri Sep 26 15:13:39 CDT 2003