UNIX Hints & Hacks |
||||||||||||||||||||||
Chapter 2: Networking |
|
|||||||||||||||||||||
|
A system can use two methods, static routing or routed, for determining where the gateways are so packets can be routed to reach their destination. Both have advantages and disadvantages.
Flavors: AT&T and BSD
Syntax:
ifconfig interface netstat -rn route command [[modifiers] args] [metric]
Adding a static route to direct packets to the local gateway optimizes the transmission of all nonlocal packets. In using this method, there is no overhead in searching the local network for available gateways. The system knows that all packets are directed to one specific default gateway for delivery.
Suppose you have two network interface cards in one system and these cards sit on two distinct subnets ( 206.19.11 and 139.107.100). If you want to send some packets to one subnet and the rest of the packets to another subnet, you can set up static routes. To route the packets to the 139.107.100 gateway and the other packets to the 206.19.11 gateway, set it up like this:
# ifconfig ec0 ec0: flags=c63<UP,BROADCAST,NOTRAILERS,RUNNING,FILTMULTI,MULTICAST> inet 206.19.11.3 netmask 0xffffff00 broadcast 206.19.11.255 # ifconfig ec2 ec2: flags=c63<UP,BROADCAST,NOTRAILERS,RUNNING,FILTMULTI,MULTICAST> inet 139.107.100.18 netmask 0xffffff00 broadcast 139.107.100.255
# route add default 206.19.11.254 1 # route add net 139.107.100 139.107.100.254 1
# netstat -rn Destination Gateway Netmask Flags Refs Use Interface default 206.19.11.254 UG 21 523617 ec0 139.107.243 139.107.100.254 0xffffff00 UG 0 6854 ec2
Lines 1-4: Show the current configurations of the network interface. Each interface has a unique IP address on its respective subnets.
Line 6: Add a route that, by default, sends all packets to 206.19.16.254 at a cost of only one hop if no other static routes are defined.
Line 7: Add a route that sends all packets going to the 139.107.100 network to the gateway address 139.104.100.254 at a cost of only one hop.
Line 9: Use the netstat -rn command to display all the routing table information as IP addresses instead of attempting to resolve its hostname.
Lines 10-12: Show the output of the routing information.
All packets for subnet 139.104.243 are sent to the gateway address 139.104.100.254, using the gateway that is up through the interface ec2.
If the packets are not for subnet 139.107.100, send everything else to the default IP address at 206.19.11.254, which is a gateway that is up and can be reached by using the interface ec0.
Flavors: AT&T, BSD
Syntax:
routed [-q] [-s]
routed is very simple to use. This makes it attractive, but simple things can sometimes cause great headaches. Being a bit of a resource hog, this daemon can be definitely dangerous to run when used at the wrong time or in the wrong way. You must take caution when and how routed is to be used. There are primarily two modes to run routed in: quiet mode and server mode.
# route -q
In quiet mode, set with the -s option, the daemon receives any routing information that gets broadcast over the network. After this new routing information is received, it becomes integrated into the routing database and the kernel's routing table. This daemon should, in theory, run passively in the background, but that isn't always the case. This daemon is not to be trusted.
# route -s
Server mode is set with the -s option. It not only listens for broadcasts of routing information, but sprays the network every 30 seconds with information about routes that the server knows about. In large environments with a mixture of over 100 UNIX workstations and servers having the daemon running in server mode, there would be massive network traffic that consisted only of basic routing information. If the daemon were ever to be started in a server mode, it could be started only when a system has multiple network interface cards.
Packets need to find a way to their destination. In a large environment, the capability to statically route the packets to a particular gateway is a great benefit. When no router or gateway is available and isolated networks are in place, routed is perfect for this scenario.
When you receive a system from the vendors, they attempt to make it as easy to have up and running on a network as possible. routed is often shipped to come up in server mode at the time your system boots up. All you have to do is give a new system an IP address and routed starts collecting routing information. I find that users who acquire their own systems and try to set up as much as they can are notorious for leaving the routed in server mode. If you are really concerned about the amount of potential traffic, attach a sniffer to your network and turn routed on. See how much your network is actually affected.
Why have one more process running on your system than you need? If you have routers and gateways in place, let them do the job you bought them for. If you pass the packets off to them, they deliver the packets to the proper destination.
Recently I have found myself working in environments where two or three computers need to talk only to one another on an isolated network. Attaching each of them to a hublet and simply turning routed on in server mode makes setup easy. If two computers need to talk and there are no hublets, just get a twisted Ethernet cable and turn on routed again in server mode and you are finished.
Man pages
ifconfig, netstat, route, routed
UNIX Hints & Hacks |
||||||||||||||||||||||
Chapter 2: Networking |
|
|||||||||||||||||||||
|
© Copyright Macmillan USA. All rights reserved.