Linux static route Configuration

Source: Internet
Author: User

When you are studying linux, you may encounter the problem of configuring static routes. Here we will introduce the solution to the problem of configuring linux static routes. Here we will share with you. 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 linux static Route 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 three above are replaced by three PCs. Use the following command to enable the IP forwarding function of the computer, and set/proc/sys/net/ipv4/ip_forward to 1 by default.
# 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 linux static 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
The above describes how to configure linux static routes.

  1. In-depth introduction to linux Ext3 File System
  2. Sunflower collection in linux vi Editor
  3. Happy Learning Linux Virtual Machine VMware
  4. Linux: linux Nautilus
  5. How to kill a process in linux

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.