How to install a TCP/IP router in Linux

Source: Internet
Author: User
To use Linux as a Router, you must first confirm that your LinuxKernel supports IPForwarding, that is

Prerequisites for Linux as a Router

To use Linux as a Router, you must first confirm that your Linux Kernel supports IP Forwarding, that is, you must select the IP Forwarding option when making Kernel.

The Router connects Class B net and Subnet with two network cards respectively. Therefore, when Linux is started on, it is necessary to catch these two network cards. The method is in/etc/lilo. Append = "ether = irq_0, io_port_0, eth0 ether = irq_1, io_port_1, eth1" is added to the conf file, and then the value is lilo C lilo. Conf, and then re-boot, you should be able to catch two network cards.

If you want to check whether two network cards are caught, you can check whether the/proc/net/dev file has two network interfaces, eth0 and eth1, or if the Value Line is ifconfig, check whether there are two network interfaces: eth0 and eth1. if there is no network interface, it may be that your Kernel does not support that type of network card. then you must make the Kernel again, include the network card options.

How to plan Subnet IP address

The two network interfaces of the Router are connected to two net networks, and each has its own IP address. eth0 = 140.115.50.67 is the IP address eth1 = 140.115.50.161 connected to Class B net.

Now let's look at how to plan Subnet.

First, we need to determine how many machines exist in Subnet, that is, to divide several IP addresses into Subnet. I will take 32 machines in Subnet as an example to illustrate this. Therefore, the IP range of Subnet is

  1. 140.115.50.160 ~ 140.115.50.191, WHY ??
  2. 140.115.50.160 ==> 140.115.50.101 00000
  3. ^
  4. Network address host address
  5. 140.115.50.191 ==> 140.115.50.101 11111
  6. ^
  7. Network address host address

All netmasks are

Required bytes before ==> required bytes before 111 00000

^

Its broadcast is

140.115.50.191 ==> 140.115.50.101 11111

^

The host address has 5 bits, so you can decide 2 ^ 5 = 32 Machines. of course, you can also use 140.115.50.96 ~ 140.115.50.127 is your Subnet address, as long as you don't rush with others, so we can organize the Subnet network settings:

  1. IP address = 140.115.50.160 ~ 140.115.50.191
  2. Netmask = zookeeper
  3. Broadcast = 140.115.50.191
  4. Network address = 140.115.50.160

How to set the network address of the Router

After determining the Subnet IP address, the following two network interfaces are Config eth0 and eth1. add them to/etc/rc. d/rc and inet1.

Ifconfig eth0 implements netmask 255.255.0.0 broadcast 140.115.255.255 ifconfig eth1 140.115.50.161 netmask then implements fixed bandwidth upgrade and then executes rc. inet1 or restarts. you can use the ifconfig command to check whether the settings are correct,

The output of the Router Value Line ifconfig is as follows::

  1. Lo Link encap: Local Loopback
  2. Inet addr: 127.0.0.1 Bcast: 127.20.255 Mask: 255.0.0.0
  3. Up broadcast loopback running mtu: 2000 Metric: 1
  4. RX packets: 0 errors: 0 dropped: 0 overruns: 0
  5. TX packets: 24 errors: 0 dropped: 0 overruns: 0
  6. Eth0 Link encap: 10 Mbps Ethernet HWaddr 04: 00: 23: 53: 90: 21
  7. Inet addr: 140.115.50.67 Bcast: 140.115.255.255 Mask: 255.255.0.0
  8. Up broadcast running multicast mtu: 1500 Metric: 1
  9. RX packets: 107061 errors: 0 dropped: 0 overruns: 0
  10. TX packets: 22060 errors: 0 dropped: 0 overruns: 0
  11. Interrupt: 5 Base address: 0x290 Memory: d1_d4000
  12. Eth1 Link encap: 10 Mbps Ethernet HWaddr 12: 30: 51: 47: 23: 85
  13. Inet addr: 140.115.50.161 Bcast: 140.115.50.191 Mask: too many bytes
  14. Up broadcast running multicast mtu: 1500 Metric: 1
  15. RX packets: 107061 errors: 0 dropped: 0 overruns: 0
  16. TX packets: 22060 errors: 0 dropped: 0 overruns: 0
  17. Interrupt: 6 Base address: 0x350 Memory: d8000db000
  18. How to set the Kernel Routing table of the Router

After the network address is set, the next step is to set the Kernel Routing table. when the Router receives a Packet, it compares the Kernel Routing table according to the target address in the Packet, therefore, if the Kernel Routing table is set incorrectly, Packet cannot be delivered to the destination by the correct network interface.

  1. The setting of the Kernel Routing table is also added to/etc/rc. d/rc. inet1.
  2. Route add net 140.115.0.0 netmask 255.255.0.0 eth0
  3. Route add net 140.115.50.160 netmask too many requests against eth1
  4. Route add default gw 140.115.1.254 metric 1
  5. ^

Run rc. inet1 or reboot after the Gateway is connected to the external server. you can use the route command to check whether the setting is correct. The following is the output of the Router Value Line route:

  1. Destination Gateway Genmask Flags MSS Window Use Iface
  2. 140.115.50.160 * 255.20.0000u 1436 0 234 eth1
  3. 140.115.0.0*255.255.0.0 U 1436 0 29125 eth0
  4. 127.0.0.0*255.0.0.0 U 1936 0 34 lo
  5. Default 140.115.1.254 * ug1436 0 79 eth0

How to set the network address of the machine in Subnet and the machine in the Kernel Routing table Subnet is easier to set than the Router. it only has one network card, that is, eth0, so it is stored in/etc/rc of ds170. d/rc. add in inet1

  1. Ifconfig eth0 140.115.50.170 netmask zookeeper broadcast 140.115.50.191
  2. Route add net 140.115.50.160 netmask implements dynamic route eth0
  3. Route add default gw 140.115.50.161 metric 1
  4. ^

Here we set the Gateway as the eth1 IP address of the Router and set the Proxy ARP to connect to Subnet.

After the preceding settings are complete, you can connect ds170 or ds170 to the Router by the Router. however, to directly connect ds170 to a machine in Class B net, such as dslab, in this case, the ds170 directly sends the package (note that the data is not ARP) to the router (which can be determined by the static routing table). The router then sends ARP to the class B network, dslab will hear this ARP, but when dslab wants to send ARP back, the router or gateway will block the package of broadcast and multicast, instead of forwarding, therefore, the ARP responded by dslab cannot be received by ds170. Therefore, we need to set the Proxy ARP on the Router, the function is to respond to the broadcast ARP of the machine in class B on behalf of the machine in subnet, so that the package in class B needs to be sent to subnet first to the router, then the router sends it to the machine in subnet.

Therefore, add it to/etc/rc. d/rc. inet1 of the Router.

Arp s 140.115.50.170 04: 00: 23: 53: 90: 21 pub ^

This is the hardware address of the Router eth0 interface.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.