Linux static route settings

Source: Internet
Author: User

Now there are five devices: pC1 connected to rout1, rout1 connected to rout2, rout2 connected to rout3, and rout3 connected to PC2. The topology is shown below:

□---- ○ ---- □

PC1 rout1 rout2 rout3 PC2

The static IP addresses of the five devices are:

PC1 192.168.1.88/24

Rout1 192.168.1.128/24 192.168.2.128/24

Rout2 192.168.2.66/24 192.168.3.66/24

Rout3 192.168.3.100/24 192.168.4.33/24

PC2 192.168.4.66/24

The pC1 configuration is as follows:

# Ifconfig eth0 192.168.1.88 netmask 255.255.255.0

# Route add default GW 192.168.1.128

Configure rout1 as follows:

# Ifconfig eth0 192.168.1.128 netmask 255.255.255.0

# Ifconfig eth0: 1 192.168.2.128 netmask 255.255.255.0

# Route add-net 192.168.4.0/24 GW 192.168.2.66

Configure rout2 as follows:

# Ifconfig eth0 192.168.2.66 netmask 255.255.255.0

# Ifconfig eth0: 1 192.168.3.66 netmask 255.255.255.0

# Route add-net 192.168.1.0/24 GW 192.168.2.128

# Route add-net 192.168.4.0/24 GW 192.168.3.100

Configure rout3 as follows:

# Ifconfig eth0 192.168.3.100 netmask 255.255.255.0

# Ifconfig eth0: 1 192.168.4.33 netmask 255.255.255.0

# Route add-net 192.168.1.0/24 GW 192.168.3.66

The PC2 configuration is as follows:

# Ifconfig eth0 192.168.4.66 netmask 255.255.255.0

# Route add default GW 192.168.4.33

In this way, pC1 can ping pc2.

Note:

The above three routers are replaced by three PCs. To replace a router with a computer, you must enable the IP forwarding function of the computer. Change the content in/proc/sys/NET/IPv4/ip_forward to 1 (the default value is 0 ), run the following command to complete

# E Cho 1>/proc/sys/NET/IPv4/ip_forward

After the network is restarted, the above file is automatically changed to 0

Add several commands:

1. Delete the default route

# Route del default

2. View routes

# Route-n

3. Set a route entry for a specified CIDR Block

# Route add-net 192.168.3.0 netmask 255.255.255.0 GW 192.168.6.66

Or

# Route add-net 192.168.3.0/24 GW 192.168.6.66

4. delete a route entry

# Route del-net 192.168.3.0 netmask 255.255.255.0

Or

# Route del-net 192.168.3.0/24

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.