Linux operating system static routing setup skills introduction

  

There are now five devices, PC1 is connected to ROUT1, ROUT1 is connected to ROUT2, ROUT2 is connected to ROUT3, and ROUT3 is connected to PC2. The topology is as follows:


□—— ——○————○————○————□

PC1 ROUT1 ROUT2 ROUT3 PC2

< Br>

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


PC1 is configured as follows:

#ifconfig eth0 192.168.1.88 netmask 255.255.255.0

#route add default gw 192.168.1.128


ROUT1 is configured 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


ROUT2 is configured as follows:

#ifconfig eth0 192.168.2.66 netmask 255.255.255.0

#i Fconfig 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


ROUT3 is configured 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


PC2 is configured as follows:

#ifconfig eth0 192.168.4.66 netmask 255.255.255.0

#route add default gw 192.168.4.33


This way PC1 can ping PC2.


Note:

The above three routers are replaced by three PCs. To replace the 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 (default is 0), complete with the following command

#e cho 1 > /proc/sys/net/ipv4/ip_forward

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


Add a few commands:

1, delete the default route

#route del default


2, view the route

#route -n


3, set the specified network segment routing

#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 the specified network segment route

#route del -net 192.168.3.0 netmask 255.255.255.0< Br>

or

#route del -net 192.168.3.0/24

Copyright © Windows knowledge All Rights Reserved