Adding routes to modern Linuxes

Shamelessly robbed from http://www.akadia.com/services/redhat_static_routes.html

Overview

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.

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 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 and add your static routes using the route statement.

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

Force the old static-routes file to work under Redhat 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:

#!/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

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”

No Comments

Useful IOS commands

Shamefully taken from  https://www.eng.uwaterloo.ca/twiki/bin/view/Engcomp/CommonCiscoCommands

To enable privileged command mode

enable

To enter switch configuration mode (from privileged command mode)

configure terminal

To enter port configuration mode (from switch configuration mode)

interface FastEthernet0/5

To return from one mode to the previous mode

exit

To show the mac table

show mac-address-table

To show port information

show interfaces

To show the switch version

show version

To save the configuration

write memory

To show the configuration

show running-config

To set the port description of FastEthernet0/5 to “engmail”

configure terminal
interface FastEthernet0/5
description engmail
exit

To remove the port description from FastEthernet0/5

configure terminal
interface FastEthernet0/5
no description
exit

To set FastEthernet0/5 to 100/full

configure terminal
interface FastEthernet0/5
speed 100
duplex full
exit

To set FastEthernet0/5 to auto/auto

configure terminal
interface FastEthernet0/5
speed auto
duplex auto
exit

To turn FastEthernet0/5 into a dot1q trunk

configure terminal
interface FastEthernet0/5
no switchport access vlan
switchport mode trunk
switchport trunk encapsulation dot1q
exit

To turn FastEthernet0/5 into a non trunk

configure terminal
interface FastEthernet0/5
no switchport mode trunk
no switchport trunk encapsulation
no switchport trunk allowed vlan
no switchport trunk native vlan
switchport mode access
exit

To set the allowed vlans on trunk port FastEthernet0/5 to 20,50,100

configure terminal
interface FastEthernet0/5
switchport trunk allowed vlan 20,50,100
exit

To remove the allowed vlans from trunk port FastEthernet0/5 (will default to all vlans in vlan database)

configure terminal
interface FastEthernet0/5
no switchport trunk allowed vlan
exit

To restrict the number of mac address on FastEthernet0/5 to 1

2900/3500 series…

configure terminal
interface FastEthernet0/5
port security max-mac-count 1
exit

2950/3550 series…

conf term
interface FastEthernet0/5
switchport port-security
switchport port-security maximum 1
switchport port-security violation protect
switchport port-security mac-address sticky
switchport port-security aging static
exit

To remove the mac address restriction from FastEthernet0/5

configure terminal
interface FastEthernet0/5
no port security
exit

To set the vlan on FastEthernet0/5 to 150

configure terminal
interface FastEthernet0/5
switchport access vlan 150
exit

To remove the vlan from FastEthernet0/5 (port will default to vlan 1)

configure terminal
interface FastEthernet0/5
no switchport access vlan
exit

To set the native vlan (untagged vlan) on trunk FastEthernet0/5 to 75

configure terminal
interface FastEthernet0/5
switchport trunk native vlan 75
exit

To remove the native vlan (untagged vlan) from trunk FastEthernet0/5

configure terminal
interface FastEthernet0/5
no switchport trunk native vlan
exit

To set FastEthernet0/5 to portfast

configure terminal
interface FastEthernet0/5
spanning-tree portfast
exit

To set FastEthernet0/5 to not be portfast

configure terminal
interface FastEthernet0/5
no spanning-tree portfast
exit

To disable spanning tree on vlan 20

configure terminal
no span vlan 20
exit

To enable spanning tree on vlan 20

configure terminal
span vlan 20
exit

To disable port FastEthernet0/5

configure terminal
interface FastEthernet0/5
shutdown
exit

To enable port FastEthernet0/5

configure terminal
interface FastEthernet0/5
no shutdown
exit

To get a GBIC port to talk to a BayStack

configure terminal
interface GigabitEthernet0/2
no negotiation auto
exit

IOS upgrade (general procedure)

Important. Read the Cisco documentation. This procedure is minimal, and does not install the web management interface. Do not follow these instructions unless you are familliar with the procedure.

dir flash:

delete the html directory, and diag file (if any)

delete flash:html/*

rename the existing image to the name of the new image

rename flash:c3500XL-c3h2s-mz.120-5.WC2.bin flash:c3500xl-c3h2s-mz.120-5.WC5a.bin 

conf term
boot system flash:c3500xl-c3h2s-mz.120-5.WC5a.bin
exit 

copy tftp://129.97.x.y/tmpdata/c3500xl-c3h2s-mz.120-5.WC5a.bin flash:c3500xl-c3h2s-mz.120-5.WC5a.bin

copy flash:c3500xl-c3h2s-mz.120-5.WC5a.bin tftp://129.97.x.y/tmpdata/junk

check the md5 on junk compared to c3500xl-c3h2s-mz.120-5.WC5a.bin before doing the reload

write mem
reload

No Comments

Useful Unix Tools

I can never remember any of these commands.  I know that you flip flop waring, bearded, leather patch wallahs can but heres a list they is very useful.

vmstat n – To show Virtual Machine, Disk I/O, Swap etc use.  The n makes it refresh every n seconds

/etc/sysconfig/network-scripts/ifcfg-eth1 – Use to set static interface on most Linux’s
Contents something like:

# Description of type
DEVICE=eth1
BOOTPROTO=static
IPADDR=x.x.x.x
NETMASK=x.x.x.x
ONBOOT=yes
TYPE=Ethernet

Remember to use /etc/sysconfig/network for your default gateway

NETWORKING=yes
HOSTNAME=”hostname.linux.org”
GATEWAY=”10.164.234.1″
GATEWAYDEV=”eth0″
FORWARD_IPV4=”yes”

TAR – Use extracting/imploding files to one file – does not compress
tar cvf nameoftarfile.tar -I textfile.txt – takes the contents of the text file and adds to tar
tar xcvf nameoftarfile.tar - extract and verify

Solaris and 802.1q tagged interfaces
Interfaces are usually called hostname.ceVLANID000

Adding Interfaces to Solaris – making sure they work on boot
vi /etc/netmasks – add the subnet to this
vi /etc/hosts – add the interface and VLAN
create a hostname.ceVLANID000 file
manually plumb:
  plumb eth1 (bring up L1)
  ifconfig add inet x.x.x.x netmask x.x.x.x broadcast x.x.x.x
  ifconfig eth1 up

Ill keep adding as I think of them

No Comments

All Discoed up

Finally I have a motor I can use daily and do some Greenlaning.  Have a look at http://blackcountrylaners.co.uk/photos/kevs_pictures/category1033.aspx for some pictures and http://blackcountrylaners.co.uk/forums/thread/1401.aspx for the story so far.

, , ,

No Comments

Network Overdesign….

Stumbled over on a real intresting document over on the Register (http://www.theregister.co.uk/2006/05/22/network_overdesign_gartner/) about Gartner saying companies waste money on overdesigning network kit.

So true however you wont see that with my designs

No Comments

Making Bootable Windows CD/DVD’s

Just a refresh and a quick note here…..

Main things to do:

  1. Put all the files into a main folder
  2. Get a copy of the boot files (various places including http://www.tacktech.com/pub/microsoft/bootfiles/bootfiles.zip)
  3. Use Nero to burn a new Bootable DVD/CD
  4. When the dialog opens, set Bootable Disc Type: to No Emulation.
    Click the “>>Advanced” button, and set the Load Segment: to 0×000 and the Sector Count: to 4. Now click “Browse” where the dialog asks you to “locate the image file that contains the bootable image.”
  5. Follow the usual process to make the DVD, remembering to keep a copy of the ISO/NRG image :)

Good luck

,

No Comments

Greenlaning site

One of my intrests is Greenlaning and Off Roading.  I used to own a real old Series IIA Land Rover that was a classic, but its no more – lost in time.

Luckilly some of my mukkas still have some top motors and we get away quite a lot.  Check out http://blackcountrylaners.co.uk for our site – specially the Files(Videos) and the Photo section 

, ,

No Comments

Windows Automated Installations – What to call workstations

One of the big problems I have found when creating build systems for companies is what to call machines when they are being built.

A good idea a few companies I have worked at is to use the vendor serial number that is affixed and labeled all over the machines.  On Dell machines its called the ‘Service Tag Number’

How to pipe that into installations is another story but if you are doing simple cloning using Ghost, PQ or Altris then this handy VBscript may come in useful.  It extracts the Dell Tag number using WMI and then sets a SYSTEM environment varible called DellTag

BTW – I’m not a hardcore coder so if anyone can make it better then please advise!  Fragments were made using the excellent Microsoft Scriptomatic2 tool.

‘ DellSN.vbs

‘ Version 1.0 – Kevin Iddles, Yawns.com Limited

‘ Script to extract Dell Tag Number from BIOS using WMI
‘ Outputs Dell tag to screen and sets a SYSTEM environment varible accordingly.

‘ Call from CMD by using —-  cscript //NoLogo DellSn.vbs
‘ Obviously will need to open a new session to pickup the setting

‘On Error Resume Next

Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20

Dim strSN

‘ Start Get the Dell Asset number from BIOS
   Set objWMIService = GetObject(“winmgmts:\\.\root\CIMV2″)
   Set colItems = objWMIService.ExecQuery(“SELECT SerialNumber FROM Win32_BIOS”, “WQL”, wbemFlagReturnImmediately + wbemFlagForwardOnly)

   For Each objItem In colItems
      WScript.Echo objItem.SerialNumber
      strSN = objItem.SerialNumber
   Next

‘ Debug – Echo results set in var
‘ Wscript.Echo strSN

‘ Start Set Env

‘ This gets set as a SYSTEM varible – user must be a local administrator for correct permissions
  Set EnvClass = GetObject(“WinMgmts:\\.\root\cimv2:Win32_Environment”)
  ‘ Make a new instance of that class
  Set EnvVarInst = EnvClass.SpawnInstance_
  ‘ File in the key props and props of interest on that instance
  EnvVarInst.UserName = “<SYSTEM>”
  EnvVarInst.Name = “DellTag”
  EnvVarInst.VariableValue = strSN
  ‘ Write the new instance in to WMI
  EnvVarInst.Put_
‘ End Set Env

No Comments

Welcome to my new Blog

Thanks for tuning in.

Keep checking out here for more posts and hopefuly useful articles. 

Kev

PS.  We are RSS enabled [:)]

No Comments