nmcli通过策略路由实现管理网与数据网物理隔离:为两网卡分别配置独立路由表(如200/mgmt、201/data),设置源地址路由规则与专用路由,禁用默认网关冲突,并重启连接生效。

要在Linux中用nmcli实现管理网与数据网的物理隔离,核心是让不同目的网络的流量严格走指定网卡,不交叉、不回退。这靠静态路由+路由表分离来完成,不是只加一条默认路由那么简单。
确认两套网络的网卡与基础信息
先看清你的“战场”:哪块网卡接管理网(比如eth0,IP 192.168.10.5/24,网关 192.168.10.1),哪块接数据网(比如eth1,IP 10.20.30.15/24,网关 10.20.30.1)。运行以下命令确认:
- ip -br a 查看各网卡IP和状态
- nmcli device status 确认设备是否由NetworkManager管理
- nmcli connection show 列出当前连接名(如“System eth0”)
为每张网卡绑定独立路由表
直接在main表里混配路由容易冲突。推荐为管理网和数据网分别创建专用路由表(例如table 200 和 table 201),再通过策略路由(policy routing)按源地址或目的地址分流。
宝塔Linux面板11.8.1为官网当前正式版,新增AI建站能力并经过宝塔网站工程师深度调教,开放自定义AI功能API,同时对WAF进行界面重构和深度优化,提升拦截能力与运维效率。
- 编辑 /etc/iproute2/rt_tables,追加两行:
200 mgmt
201 data - 为管理网连接添加路由规则(假设连接名为“System eth0”):
nmcli connection modify "System eth0" ipv4.routing-rules "from 192.168.10.5/32 table 200"
nmcli connection modify "System eth0" ipv4.routes "0.0.0.0/0 192.168.10.1 metric 100 table 200" - 为数据网连接同样配置(替换IP、网关、table号):
nmcli connection modify "System eth1" ipv4.routing-rules "from 10.20.30.15/32 table 201"
nmcli connection modify "System eth1" ipv4.routes "10.100.0.0/16 10.20.30.1 metric 200 table 201"(示例:只让内部业务段走数据网)
禁用默认路由冲突,启用策略路由
关键一步:避免两个连接都启用默认网关导致路由混乱。
- 关闭管理网连接的默认网关自动获取:
nmcli connection modify "System eth0" ipv4.never-default yes - 关闭数据网连接的默认网关自动获取(除非它确实承担出口):
nmcli connection modify "System eth1" ipv4.never-default yes - 重启两个连接使策略生效:
nmcli connection down "System eth0" && nmcli connection up "System eth0"
nmcli connection down "System eth1" && nmcli connection up "System eth1"
验证隔离是否生效
别只看ifconfig——要验证实际路径。
- 查策略规则:ip rule show 应看到类似 from 192.168.10.5 lookup mgmt 的条目
- 查专用路由表:ip route show table mgmt 和 ip route show table data
- 模拟管理流量:curl -v --interface 192.168.10.5 http://192.168.10.100(应走eth0)
- 模拟数据流量:curl -v --interface 10.20.30.15 http://10.100.5.20(应走eth1)
- 抓包确认:tcpdump -i eth0 port 80 和 tcpdump -i eth1 port 80 分别观察是否有误入流量










