How to install TCP / IP router with Linux
Recommended: LONGERTREE Posted: May 18, 2001 Reading: 250
-------------------------------------------------- ------------------------------
The following will be described below for each subject:
* Linux When Router's prerequisites.
* How to plan the IP address of the Subnet.
* How to set the network address of the router.
* How to set the ROUTER's kernel routing table.
* How to set up the network location of the machine in Subnet and the kernel routing table.
* Set the Proxy ARP to connect the Subnet.
Linux When Router's prerequisites
To use Linux as Router, you must first confirm that your Linux kernel has support IP forwarding.
The function is to select the IP Forwarding option when Make Kernel.
In the figure, Router connects Class B Net and Subnet with two network cards, so let
Linux is to catch the two online cards when booting, which has become a prerequisite. The method is
/ etc / lilo. Add in Conf
Append = "Ether = IRQ_0, IO_PORT_0, ETH0 Ether = IRQ_1, IO_PORT_1, Eth1"
Afterwards, row row LILO-C LILO. CONF, then turn on, you should catch two online cards.
To check if there are two online cards, you can see whether there is Eth0 in the / proc / net / dev file.
Eth1 two network interfaces, or the value row ifconfig, see if there is both Eth0 and Eth1 network interface,
If there is no, it may be that your Kernel does not support the kind of online card, then you must re-re-
Make kernel, contains the options of the online card.
How to plan Subnet's IP Address
In the figure, the two network interfaces of Router are connected to both NETs, and their IP address,
Eth0 = 140.115.50.67 for connecting Class B Net IP Address
Eth1 = 140.115.50.161 is an IP address for connecting SUBNET
Now let's take a look at how to plan the Subnet.
First we must first decide that there are several machines in the Subnet, which is to divide several IP address on the SUBNET.
In the Subnet, I will explain with 32 machines in Subnet. Therefore, the IP scope of the SUBNET is
140.115.50.160 ~ 140.115.50.191, why ??
140.115.50.160 ===> 140.115.50.101 00000
^^^^^^^^^^^^^^ ^^^^^
Network address Host Address
140.115.50.191 ===> 140.115.50.101 11111
^^^^^^^^^^^^^^ ^^^^^
Network address Host Address
Its NetMask is
255.255.255.224 ===> 255.255.255.111 00000
^^^^^^^^^^^^^^^ ^^^^^
Its Broadcast is
140.115.50.191 ===> 140.115.50.101 11111
^^^^^^^^^^^^^^ ^^^^^
Host Address has 5 Bit, so you can decide 2 ^ 5 = 32 machines, of course, you can also use 140.115.50.96 ~ 140.115.50.127 for your subnet address, as long as you don't have to do with others.
So we can set up the Subnet's online settings:
IP Address = 140.115.50.160 ~ 140.115.50.191
Netmask = 255.255.255.224
Broadcast = 140.115.50.191
Network address = 140.115.50.160
How to set up a network address of Router
After determining the Subnet's IP Address, next is the two network interfaces of Config Eth0 and Eth1, joined in /etc/rc.d/rc, inet1
Ifconfig Eth0 140.115.50.67 Netmask 255.255.0.0 Broadcast 140.115.255.255
Ifconfig eth1 140.115.50.161 Netmask 255.255.255.224 Broadcast 140.115.50.191
After executing Rc.inet1 or reboots again. You can use the ifconfig command to check if the setting is correct, the following is the output of the router value row IFConfig:
Lo Link Encap: Local Loopback
INET Addr: 127.0.0.1 Bcast: 127.255.255.255 Mask: 255.0.0.0
Up Broadcast Loopback Running MTU: 2000 Metric: 1
RX Packets: 0 Errors: 0 Dropped: 0 overruns: 0
TX Packets: 24 Errors: 0 Dropped: 0 overruns: 0
Eth0 Link ENCAP: 10Mbps Ethernet Hwaddr 04: 00: 23: 53: 90: 21
INET AddR: 140.115.50.67 Bcast: 140.115.255.255 Mask: 255.255.0.0
Up Broadcast Running Multicast MUNTU: 1500 metric: 1
RX Packets: 107061 Errors: 0 Dropped: 0 overruns: 0
TX Packets: 22060 Errors: 0 Dropped: 0 overruns: 0
Interrupt: 5 Base Address: 0x290 Memory: D0000-D4000
Eth1 Link ENCAP: 10Mbps Ethernet Hwaddr 12: 30: 51: 47: 23: 85
inet addr: 140.115.50.161 Bcast: 140.115.50.191 Mask: 255.255.255.224
Up Broadcast Running Multicast MUNTU: 1500 metric: 1
RX Packets: 107061 Errors: 0 Dropped: 0 overruns: 0
TX Packets: 22060 Errors: 0 Dropped: 0 overruns: 0
Interrupt: 6 Base Address: 0x350 Memory: D8000-DB000
How to set the Kernel Routing Table of Router
After the network is set, the next step is to set the kernel routing table. When ROUTER receives a packet, it will go to the kernel routing table comparison according to the destination of the packet, and determine the network. The interface is sent, so the kernel routing table is wrong, and the packet cannot be sent to the destination by the correct network interface.
Kernel Routing Table is also added to /etc/rc.d/rc.inet1
Route Add -Net 140.115.0.0 Netmask 255.255.0.0 Eth0
Route Add -Net 140.115.50.160 Netmask 255.255.255.224 Eth1
Route Add Default GW 140.115.1.254 metric 1
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This is GATEWAY to the school
After the Rc.inet1 or reboot, you can use the route instruction to check if the setting is correct, the following is the output of the router row Route:
Destination Gateway Genmask Flags MSS Window Uses
140.115.50.160 * 255.255.255.224 u 1436 0 234 Eth1
140.115.0.0 * 255.255.0.0 U 1436 0 29125 Eth0
127.0.0.0 * 255.0.0.0 U 1936 0 34 LO
Default 140.115.1.254 * ug 1436 0 79 ETH0
How to set the network location of the machine in Subnet and kernel routing table
The machine in the Subnet has its setting method than ROUTER. It has only one network card, which is Eth0, so adds to the machine DS170 /et1.
Ifconfig eth0 140.115.50.170 Netmask 255.255.255.224 Broadcast 140.115.50.191
Route Add -Net 140.115.50.160 Netmask 255.255.255.224 Eth0
Route Add Default GW 140.115.50.161 metric 1
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
I will set Gateway to Router Eth1 IP Address
Set proxy arp to connect SUBNET
After the above setting is completed, you can connect to the DS170 by the router, or by the DS170, if you want to connect directly from the DS170 to the machine, such as DSLAB, you cannot communicate directly, because DS170 is directly Send Package to Router (Note Your Data is not ARP) (can be determined by Static Routing Table), and the router will help you send ARP in the Class B Network, so DSLAB will hear this ARP, but when DSLAB wants to send ARP Since Router or Gateway blocks Broadcast and Multicast's package, not Forwarding, the ARP responded by DSLAB cannot make DS170 received, so we need to set up Proxy ARP on Router, and its function is in the subnet The machine responds to the ARP of the machine Broadcast in Class B, lets the copy of the Subnet to the Subnet, then help it to the machine in the SUBNET.
So you should join in the router /etc/rc.d/rc.inet1
ARP -S 140.115.50.170 04: 00: 23: 53: 90: 21 PUB
^^^^^^^^^^^^^^^^^^
This is the hardware address of the Router eth0 interface.
Author: unknown
source:
http://www.9headbird.com/detail.php3?id=20999