Build a router in Linux

Source: Internet
Author: User
Use Linux to build a router-general Linux technology-Linux technology and application information. The following is a detailed description. 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.

  

(400) {this. resized = true; this. width = 400; this. alt = 'click here to open new window';} "onmouseover =" if (this. resized) this. style. cursor = 'hand'; "onclick =" window. open ('HTTP: // myarticle.enet.com.cn/images/200404/4102094546972.gif'); ">

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 restarted,

Edit the/etc/sysconfig/network-scripts/ifcfg-eth0 file in 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:

# 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

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

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.