Article title: Introduction to static route settings in 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.
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
(T002)