CentOS 7 持久路由问题?

nmr*_*mra 4 centos route

我在谷歌上搜索了很多,但仍然找不到如何在 centOS 7 上创建一些持久路由的工作方法。

[root@asd network-scripts]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.23.40.1     0.0.0.0         UG    1024   0        0 enp10s0f1
172.23.40.0     0.0.0.0         255.255.255.0   U     0      0        0 enp10s0f1


enp10s0f0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
inet6 fe80::226:55ff:fed1:9123  prefixlen 64  scopeid 0x20<link>
ether 00:26:55:d1:91:23  txqueuelen 1000  (Ethernet)
RX packets 1096  bytes 291485 (284.6 KiB)
RX errors 0  dropped 0  overruns 0  frame 0
TX packets 12  bytes 2040 (1.9 KiB)
TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
device interrupt 34  memory 0xfbfe0000-fc000000

enp10s0f1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
inet 172.23.40.77  netmask 255.255.255.0  broadcast 172.23.40.255
inet6 fe80::226:55ff:fed1:9122  prefixlen 64  scopeid 0x20<link>
ether 00:26:55:d1:91:22  txqueuelen 1000  (Ethernet)
RX packets 2865  bytes 457736 (447.0 KiB)
RX errors 0  dropped 0  overruns 0  frame 0
TX packets 1995  bytes 345793 (337.6 KiB)
TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
device interrupt 24  memory 0xfbee0000-fbf00000
Run Code Online (Sandbox Code Playgroud)

我在谷歌上搜索过的任何地方都说要在文件route-eth0. 但是我的文件不是那样的,它们是“ifcfg-enp10s0f0”。我这里有这个文件/etc/sysconfig/network-scripts::

-rw-r--r--. 1 root root   321 Sep 15 13:34 ifcfg-enp10s0f1
-rw-r--r--. 1 root root   440 Sep 15 14:44 ifcfg-enp10s0f0
[root@asd network-scripts]#
Run Code Online (Sandbox Code Playgroud)

我试图添加一个像route-enp10s0f0. 我在/etc/sysconfig/network文件中添加了路线,但没有任何效果。每次我做的service network restart都消失了!

我添加了ifcfg-enp10s0f0

GATEWAY0=0.0.0.0
NETMASK0=255.255.255.0
ADDRESS0=192.168.0.0
GATEWAY1=0.0.0.0
NETMASK1=255.255.0.0
ADDRESS1=169.254.0.0
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

Raf*_*ger 8

您在 Google 上找到的内容是正确的。您需要创建一个路由(ifname)文件。

内容需要像“ip”命令一样,但只是最后一部分。像这样:

192.168.1.0/24 via 192.168.2.1
Run Code Online (Sandbox Code Playgroud)

更多信息可以在RHEL 7 网络指南 中找到