linux routing configuration details

insert image description here
Add the network segmentation. If you want to display only the U
Route ADD -NET 192.168.1.0 netmask 255.255.255.0 DEV ENS192
[root@ht23 k8sNode]# Route -N
Kernel IP ROUTING TATINATINATION
Gateway Genmask Flags Metric Ref USE Ifce
192.168.1.0 0.0. 0.0 255.255.255.0 U 0 0 0 ens192
indicates that the 192.168.1.0/24 network segment can pass

Add host route, display UH
route add -host 192.168.1.1 dev ens192 //Add successfully, no need to specify a mask Note
[root@ht23 k8snode]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168. 1.1 0.0.0.0 255.255.255.255 UH 0 0 0 ens192
//Display UH, indicating that the host 192.168.1.1 can be forwarded by the ens192 network card.

Add gateway routing, display UG
[root@etcd2 system]#route add default gw 10.129.55.1 is equivalent to
[root@etcd2 system]#route add -net 0.0.0.0 netmask 0.0.0.0 gw 10.129.55.1
[root@etcd2 system] #route del default gw 10.129.55.1

[root@etcd2 system]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.129.55.1 0.0.0.0 UG 0 0 0 ens192
//Indicates that packets destined for any network segment are all destinations The local data packet is forwarded by the gateway 10.129.55.1 through the network card ens192
//Added a gateway, Flags: UG

Routing configuration:

1. Route forwarding configuration
net.ipv4.ip_forward = 1 (route forwarding needs to be configured for routing to take effect)
2. Add a temporary route
route add -host 192.168.1.2 dev eth0
route add -host 10.20.30.148 gw 10.20.30.40
route add - net 10.20.30.48 netmask 255.255.255.248 gw 10.20.30.41
route add default gw 192.168.1.1 add default route
route del -host 192.168.1.2 dev eth0 delete a route

2. Add permanent route
vim /etc/sysconfig/network-scripts/route-em1
172.30.149.176/28 via 10.119.33.97 dev em1
10.1.93.231/32 via 10.122.165.254 dev em1 metric 501

Guess you like

Origin blog.csdn.net/qq_39412605/article/details/127984217