In daily life, or in the server, there are multiple network cards to configure multiple addresses, access to different network segments, this is a very common phenomenon, this time we need to add multiple routes to achieve multi-network segment traffic.
First, set the current terminal routing (again The power is not effective)
1. Show existing routes
Route[root@localhost Network-scripts]#RouteKernel IP routing table Destination Gateway genmask Flags Metric Ref use Iface 5.5.5.0 2.2.2.252 255.255.255.0 UG 0 0 0Eth32.2.2.0 * 255.255.255.0 U 1 0 0Eth3192.168.248.0 * 255.255.255.0 U 1 0 0eth16.6.6.0 2.2.2.252 255.255.255.0 UG 0 0 0Eth31.1.1.0 * 255.255.255.0 U 1 0 0eth24.4.4.0 2.2.2.252 255.255.255.0 UG 0 0 0Eth33.3.3.0 2.2.2.252 255.255.255.0 UG 0 0 0 Eth3
2. Add route
- Routes added to the network
Route add-net destination/genmask GW gateway[root@localhost network-scripts]# Route add-net 3.3.3.0/24 GW 2.2.2.252[[email protected] network-scripts]# Route add-net 4.4.4.0/24 GW 2.2.2.252 [[email protected] network-scripts]# Route add-net 5.5.5.0/24 GW 2.2.2.252
Routes added to the host
Route add–host destination/192.168.168.119 GW 192.168.168.1
Add a default gateway
default GW Ip[root@localhost network-scripts] # route add default GW 6.6.6.250
3. Delete a route
Default
To delete a specified route
Route del–net destination/genmask[root@localhost network-scripts]# Route add-net 6.6.6.0/ GW 5.5.5.250
Routing-related operations are quite simple, but the router-related configuration is more complex, the router needs to set up the network card and related configuration before setting up, this process is more painful.
Two: The method of setting the permanent route under Linux:
1. Add in/etc/rc.local
Method:
Route add-net 192.168.3.0/24-net 192.168.2.0/24 GW 192.168.2.254180.200.0.0 netmask 255.255.0.0 GW 10.200.6.201 Dev eth0 Metric 1
-host/-net: Indicates whether the routing target is a host or a network segment;
Netmask: Indicates that the route target is a network segment and is used to represent the subnet mask of the route target network segment;
GW: Command keyword, followed by the next hop gateway;
Dev: the command keyword, followed by a specific device name, indicates that the route is out of the device.
metric: Specify the required for the route hop Count integer value (range 1 to 9999) that is used to routing Table Select the route that most closely matches the destination address in the forwarding packet in the multiple routes in the The selected route has a minimum number of hops. The metric can reflect the number of hops, the speed of the path, path reliability, path throughput, and management
2. Add to end in/etc/sysconfig/network (equivalent to add default gateway)
Method: Gateway=gw-ip or Gateway=gw-dev
3. Write to the/etc/sysconig/static-routes file, but the default in the/etc/sysconfig directory does not require that we create and then add the file manually
Method:
/etc/sysconfig/static-192.168.3.0/24 GW 192.168.3.25410.250.228.128 netmask 255.255.255.192 GW 10.250.228.129
Third, router-related experiments
Router-related experiments, most of which are adding or adding routing tables, can make multiple network segments between each other ping can be interlinked, next I will show two PC (PC1,PC2) and five routers (R1, R2,R3,R4,R5) Ping each other experiment.
1. Add virtual network (2-7) in virtual machine edit mode to add network card later
2. Plan 5 routes and 2 PC URLs
PC1 set to 1.1.1.1/24 PC2 set to 6.6.6.6/24
Route1 left for 1.1.1.251 route1 right for 2.2.2.251
Route2 left for 2.2.2.252 route2 right for 3.3.3.252
Route3 left for 3.3.3.253 route3 right for 4.4.4.253
Route4 left for 4.4.4.254 route4 right for 5.5.5.254
Route5 left for 5.5.5.250 route5 right for 6.6.6.250
PC1 on the left, then the router is aligned in 1-5 from left to right, PC2 on the far right. In the/etc/sysconfig/network-scripts directory, modify the default configuration of the new NIC, delete DHCP and add the above URLs.
3. Plan the routing table after planning the relevant address
Opened seven virtual machines, respectively, modify the relevant hostname for the corresponding machine name, on two PCs set the silent gateway to the computer,
PC1 [[email protected] ~]#route add default GW 1.1.1.251PC2 [[email protected] ~]#route add default GW 6.6.6.250route1 [Root@route1 ~]#Route add-net 3.3.3.0/24 GW 2.2.2.252[[Email protected] ~]#Route add-net 4.4.4.0/24 GW 2.2.2.252[[Email protected] ~]#Route add-net 5.5.5.0/24 GW 2.2.2.252[[Email protected] ~]#Route add-net 6.6.6.0/24 GW 2.2.2.252
route2,3 4,5 are selected in accordance with the above-mentioned way of their recent exports to connect with other network segments, I do not do too much display.
4, or take route1 as an example for firewalls and other settings
[[Email protected] ~] # net.ipv4.ip_forward = 1[root@route1 ~]# sysctl-p[[email protected] ~]# iptables–f
5, complete the above steps the network has been through, you can ping.
Add, modify, and delete routes under Linux