Article Title: how to implement access between different CIDR blocks 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.
In this example, the IP address range 10.0.0.0/24 and the IP address range 192.168.2.0/24 are used to access each other.
Step 1: view the local IP address
[Root @ localhost root] # ifconfig
Eth0 Link encap: Ethernet HWaddr 00: 0C: 29: A7: 6E: 77
Inet addr: 10.0.0.120 Bcast: 10.0.0.255 Mask: 255.255.255.0
Up broadcast running multicast mtu: 1500 Metric: 1
RX packets: 2418 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 1293 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 fig: 100
RX bytes: 1000347 (976.9 Kb) TX bytes: 192592 (188.0 Kb)
Interrupt: 10 Base address: 0x2024
Step 2: Add routing rules
[Root @ localhost root] # route add-net 192.168.2.0/24 eth0
Step 3: View routing rules
[Root @ localhost root] # route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.0.0.0*255.255.255.0 U 0 0 0 eth0
192.168.2.0*255.255.255.0 U 0 0 0 eth0
169.254.0.0*255.255.0.0 U 0 0 0 eth0
Note: in a route rule, two CIDR blocks must exist at the same time. Otherwise, the IP address of one CIDR block cannot access the IP address of another CIDR block.
Step 4: Check whether mutual access is allowed between the local machine (IP: 10.0.0.120) and remote machine (IP: 192.168.2.80.
[Root @ localhost root] # ping 192.168.2.80
PING 192.168.2.80 (192.168.2.80) 56 (84) bytes of data.
64 bytes from 192.168.2.80: icmp_seq = 1 ttl = 127 time = 5.51 MS
64 bytes from 192.168.2.80: icmp_seq = 2 ttl = 127 time = 3.17 MS
Step 5: Delete a routing rule
[Root @ localhost root] # route del-net 192.168.2.0/24 eth0