Dual network adapters configure in Linux via nmcli

当在Linux系统中使用两个网络适配器时,可能会遇到只能使用其中一个的情况。这通常由路由表引起,通过分裂路由表可以解决。本文提供bash脚本,用于配置双网卡的路由规则,确保两个网络适配器都能正常工作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

In Linux, if you use two network cards, you will encounter a situation that you can only use one of the network cards to access. This problem is caused by the routing table, so you need to use split-table routing to deal with it. Following bash scripts will help

##################################################

#for DMZ zone
if_wan=ens18
#for Local zone    
if_lan=ens19    

if_wan_ip1=`ip route|grep kernel|grep $if_wan|awk '{print $9}'`
if_lan_ip1=`ip route|grep kernel|grep $if_lan|awk '{print $9}'`
if_wan_ip2=`ip add list $if_wan|grep brd|grep $if_wan|awk -F '[ :/]+' '{print $3}'`
if_lan_ip2=`ip add list $if_lan|grep brd|grep $if_lan|awk -F '[ :/]+' '{print $3}'`
if [ "$if_wan_ip1" = "$if_wan_ip2" ];then if_wan_ip=$if

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值