Configure a router based on Linux

Source: Internet
Author: User
Article title: configure a router based on Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Network structure. the computer of the Linux router is identified as A. It is connected to three network segments, 192.168.1.0/24, 10.0.0.0/8, and 172.16.0.0/16.
  
  
  
Computer A must have three NICs connected to the three network segments.
  
Hypothesis:
  
Eth0 is connected to 172.16.0.0,
Eth1 is connected to 10.0.0.0,
Eth2 is connected to 192.168.1.0.
  
Configure eth0 first. Assign the address 172.16.1.1 to this network interface and run the following command:
  
# Ifconfig eth0 172.16.1.1 netmask 255.255.0.0
  
To make the address disappear after the computer is no longer restarted, edit the/etc/sysconfig/network-scripts/ifcfg-eth0 file to the following format:
  
DEVICE = eth0
ONBOOT = yes
BROADCAST = 172.16.0000255
NETWORK = 172.16.0.0
NETMASK = 255.255.0.0
IPADDR = 172.16.1.1
  
Add a static route:
  
# Route add-net 172.16.0.0 netmask 255.255.0.0
In this way, a static route is added to the system:
  
# Route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface
172.16.0.0*255.255.0.0 U 0 0 0 eth0
  
Next, configure eth1, and connect eth1 to the 10.0.0.0 network segment. the address assigned to it is 10.254.254.254. use the ifconfig command to configure parameters for it:
  
Add another static route:
  
# Route add-net 10.0.0.0 netmask route 0.0.0
  
The current route table in the network is
  
# Route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface
  
172.16.0.0*255.255.0.0 U 0 0 0 eth0
10.0.0.0*255.0.0.0 U 0 0 0 eth1
  
Finally, configure eth3 to connect to the network segment 192.168.1.0 and assign the IP address 192.168.1.254. run the following command:
  
# Ifconfig eth2 192.168.1.254 netmask 255.255.255.0
  
Edit the ifcfg-eth2 file under the/etc/sysconfig/network-scripts directory with the following content:
  
DEVICE = eth2
ONBOOT = yes
BROADCAST = 192.168.1.255
NETWORK = 192.168.1.0
NETMASK = 255.255.255.0
IPADDR = 192.168.1.254
  
Add another static route:
  
# Route add-net 192.168.1.0 netmask 255.255.255.0
  
In this way, there are three static route records in the network: # route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface
  
172.16.0.0*255.255.0.0 U 0 0 0 eth0
10.0.0.0*255.0.0.0 U 0 0 0 eth1
192.168.1.0*255.255.255.0 U 0 0 0 eth2
  
Add a default route for the system, because the default route sends all data packets to the Gateway at the upper level (assuming the address is 172.16.1.100, this address depends on the network used, assigned by the network administrator), so add the following default route records:
  
# Route add default gw 172.16.1.100
  
In this way, the system's static route table is created, and its content is
  
# Route Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use Iface
  
172.16.0.0*255.255.0.0 U 0 0 0 eth0
10.0.0.0*255.0.0.0 U 0 0 0 eth1
192.168.1.0*255.255.255.0 U 0 0 0 eth2
Default 172.16.1.100 0.0.0.0 UG 0 0 0 eth0
  
The last step is to add the system's IP forwarding function. This function is controlled by the ip_forward file in the/proc/sys/net/ipv4 Directory. run the following command to enable the ip forwarding function:
  
Echo 1>/proc/sys/net/ipv4/ip_forward
  
In this way, our router is basically configured
  
Test the working status of the router.
  
Test on a linux Router:
  
Step 1: test whether your network works properly. run the following command:
  
Ping 172.16.1.1
Ping 192.168.1.254
Ping 10.254.254.254
  
If all these addresses can be pinged, the first step is successful. otherwise, locate the cause and eliminate the error.
  
Step 2: Test the connectivity with the Gateway of the upper-level.
  
Ping 172.16.1.100
  
If it is unobstructed, it is normal; otherwise, you can find the cause of the error.
  
In the network of 192.168.1.0, assume that its address is 192.168.1.1,
  
Step 1: test whether the system works properly. ping 192.168.1.1
Step 2: Test connectivity with the gateway. ping 192.168.1.254
Step 3: Test connectivity with 10.254.254.99. this is a computer in the 10.0.0.0 network segment that can ping 10.254.254.99.
Step 4: test whether the connection to the Internet address is ping 172.16.1.100. if the connection is established, the vro configuration is correct. otherwise, locate the cause and eliminate the cause.
  
# Ifconfig eth1 10.254.254.254 netmask 255.0.0.0
  
Similarly, edit the ifcfg-eth1 file under the/etc/sysconfig/network-scripts directory with the following content:
  
DEVICE = eth1
ONBOOT = yes
BROADCAST = 10.20.0000255
NETWORK = 10.0.0.0
NETMASK = 255.0.0.0
IPADDR = 10.254.254.254
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.