/etc/sysconfig/network 在 CENTOS7 上被忽略

/etc/sysconfig/network 在 CENTOS7 上被忽略

我有一台有两个网卡的服务器。默认网关必须位于特定网关上,因此我通过 /etc/sysconfig/network 配置了网关。但显然,NetworkManager 完全忽略了这一点

[root@node1 ~]# cat /etc/sysconfig/network
GATEWAY="10.100.20.1"
[root@node1 ~]# systemctl restart network
[root@node1 ~]# ip r s
default via 10.100.7.1 dev ens160  proto static  metric 1024
10.100.7.0/24 dev ens160  proto kernel  scope link  src 10.100.7.31
10.100.20.0/22 dev ens192  proto kernel  scope link  src 10.100.20.204

有什么提示吗?

编辑:以下是接口配置:

[root@node1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens192
DEVICE="ens192"
ONBOOT=yes
NETBOOT=yes
UUID="e634ce78-f5ea-4b3c-b3ea-1e40ef0b11ac"
BOOTPROTO=none
IPADDR="10.100.20.204"
NETMASK="255.255.252.0"
GATEWAY="10.100.20.1"
HWADDR="XXX"
TYPE=Ethernet
NAME="ens192"
DNS1="193.12.103.2"

[root@node1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens160
DEVICE="ens160"
ONBOOT=yes
NETBOOT=yes
UUID="bee8e636-80b4-45f3-9b74-eb9eb0fed38d"
BOOTPROTO=none
IPADDR="10.100.7.31"
NETMASK="255.255.255.0"
GATEWAY="10.100.7.1"
HWADDR="XXX"
TYPE=Ethernet
NAME="ens160"
DNS1="193.12.103.2"

以下是可能导致该问题的部分消息:

[root@node1 ~]# cat /var/log/messages | grep NetworkManager | grep "Nov  9" | grep "as default for IPv4" -A5 -B5
Nov  9 12:24:36 logging-02 NetworkManager[631]: <info> (ens192): device state change: ip-config -> ip-check (reason 'none') [70 80 0]
Nov  9 12:24:36 logging-02 NetworkManager[631]: <info> Activation (ens192) Stage 5 of 5 (IPv4 Commit) complete.
Nov  9 12:24:36 logging-02 NetworkManager[631]: <info> (ens160): device state change: ip-check -> secondaries (reason 'none') [80 90 0]
Nov  9 12:24:36 logging-02 NetworkManager[631]: <info> (ens192): device state change: ip-check -> secondaries (reason 'none') [80 90 0]
Nov  9 12:24:36 logging-02 NetworkManager[631]: <info> (ens160): device state change: secondaries -> activated (reason 'none') [90 100 0]
Nov  9 12:24:36 logging-02 NetworkManager[631]: <info> Policy set 'ens160' (ens160) as default for IPv4 routing and DNS.
Nov  9 12:24:36 logging-02 NetworkManager[631]: <info> Activation (ens160) successful, device activated.
Nov  9 12:24:36 logging-02 NetworkManager[631]: <info> (ens192): device state change: secondaries -> activated (reason 'none') [90 100 0]
Nov  9 12:24:36 logging-02 NetworkManager[631]: <info> NetworkManager state is now CONNECTED_GLOBAL
Nov  9 12:24:36 logging-02 NetworkManager[631]: <info> Activation (ens192) successful, device activated.
Nov  9 12:24:41 logging-02 NetworkManager[631]: <info> startup complete

知道那里提到的是什么样的“政策”吗?

答案1

这有效:

[root@node1 ~]# cat /usr/share/doc/initscripts-9.49.17/sysconfig.txt | grep DEFROUTE
DEFROUTE=yes|no (set this interface as default route? yes is default)

我仍然相信忽略/etc/sysconfig/network是一个错误CentOS Linux release 7.0.1406 (Core)

答案2

我做过的最好方法是添加一个静态路由文件,就像我有两个接口一样

eth0 = private on 10.10.11.10
eth1 = public on 1.2.3.4 (also the default route)

因此,如果我希望 10.0.0.0/8 子网上的所有内部流量都流出 eth0,我只需添加以下文件

/etc/sysconfig/network-scripts/route-eth0

内容如下

default 10.102.51.129 dev eth0
10.0.0.0/8 via 10.102.51.129 dev eth0

10.102.51.129 是我的 eth0 网关

相关内容