Linux adds a method for permanent static routing
- 2020-05-24 06:41:17
- OfStack
1/5
First let's look at the routing table for the current machine and execute the following command: route-n
[root@vnode33 network-scripts]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 135.252.214.1 0.0.0.0 UG 100 0 0 eth0
135.252.214.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
172.86.40.0 0.0.0.0 255.255.255.0 U 100 0 0 eth1
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
2/5
Then we confirm the current working network card. Here we use eth1.
Addition: if there are multiple network CARDS in the machine, we can specify different static routes for different network CARDS.
eth0, eht2; So the method is like 1, we create 1 corresponding routing configuration file for each network card in turn. route - eth0; route - eth1; route - eth2
[root@vnode33 network-scripts]# ls
ifcfg-eth0 ifcfg-eth1:enodeb2 ifcfg-eth1:mme2 ifdown ifdown-ib ifdown-isdn ifdown-routes ifdown-TeamPort ifup-aliases ifup-ib ifup-isdn ifup-post ifup-sit ifup-tunnel network-functions
ifcfg-eth1 ifcfg-eth1:gx ifcfg-eth1:sgi ifdown-bnep ifdown-ippp ifdown-post ifdown-sit ifdown-tunnel ifup-bnep ifup-ippp ifup-plip ifup-ppp ifup-Team ifup-wireless network-functions-ipv6
ifcfg-eth1:enodeb1 ifcfg-eth1:mme1 ifcfg-lo ifdown-eth ifdown-ipv6 ifdown-ppp ifdown-Team ifup ifup-eth ifup-ipv6 ifup-plusb ifup-routes ifup-TeamPort init.ipv6-global route-eth1
3/5
Next, let's add a static route through 172.86.40.254 for 172.0.0.0/8
Execute the following command:
vi /etc/sysconfig/network-scripts/route-eth1
Add the following information:
172.0.0.0/8 via 172.86.40.254
Save and exit.
4/5
Then we need to restart the network service for 1 time:
service network restart
5/5
Finally, let's verify 1: route-n; It is found that the routing information has been added to the routing table, and the routing information will not be lost when either the host or the network service is restarted.
[root@vnode33 network-scripts]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 135.252.214.1 0.0.0.0 UG 100 0 0 eth0
135.252.214.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
172.0.0.0 172.86.40.254 255.0.0.0 UG 100 0 0 eth1
172.86.40.0 0.0.0.0 255.255.255.0 U 100 0 0 eth1
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0