設定雙網絡卡 - 內網網絡卡
阿新 • • 發佈:2020-09-08
設定雙網絡卡 - 內網網絡卡
背景
因專案環境需求需要設定兩塊網絡卡進行訪問192走內網(自身連線硬體及基礎服務) 172走外網(區域網辦公人員連線)
操作實現
1.檢視伺服器接入網絡卡數和接入的網絡卡裝置資訊
1)伺服器上網絡卡數
[root@test ~]# lspci | grep -i Ethernet 02:00.0 Ethernet controller: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) (rev 01) 02:01.0 Ethernet controller: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) (rev 01)
2)裝置對應資訊
[root@test ~]# nmcli con show
NAME UUID TYPE DEVICE
em1 1b521a6d-933c-4fa3-8b67-cd50560bbcd7 ethernet em1
em4 7fa2f659-8709-4ba9-bd19-a2eb9f05b6d8 ethernet em4
virbr0 dbe9c632-d1b7-42d2-172f8-dec29131d675 bridge virbr0
3)刪除內網網絡卡閘道器(我的內網網絡卡名稱:ifcfg-em1)
#編輯/etc/sysconfig/network-scripts/ifcfg-em1
註釋或刪除GATEWAY
#GATEWAY=192.168.43.1
4)配置策略路由
#編輯/etc/iproute2/rt_tables echo "192 net_192 " >> /etc/iproute2/rt_tables echo "172 net_172 " >> /etc/iproute2/rt_tables #清空net_192路由表(內網訪問配置) ip route flush table net_192 # 新增一個路由規則到 net_192 表,這條規則是 net_192 這個路由表中資料包預設使用源 IP 192.168.43.150 通過 em1 走閘道器 192.168.43.1 ip route add default via 192.168.43.1 dev em1 src 192.168.43.150 table net_192 #來自 192.168.43.150 的資料包,使用 net_192 路由表的路由規則 ip rule add from 192.168.43.150 table net_192 #清空net_172路由表(訪問外網配置) ip route flush table net_172 #新增一個路由規則到 net_172 表,這條規則是 net_172 這個路由表中資料包預設使用源 IP 172.22.78.35 通過 em4 走閘道器 172.22.78.233 ip route add default via 172.22.78.233 dev em4 src 172.22.78.35 table net_172 #來自 172.22.78.35 的資料包,使用 net_172 路由表的路由規則 ip rule add from 172.22.78.35 table net_172 #新增預設閘道器 route add default gw 172.22.78.233 ip route flush table net_192 ip route add default via 192.168.43.1 dev em1 src 192.168.43.150 table net_192 ip rule add from 192.168.43.150 table net_192 ip route flush table net_172 ip route add default via 172.22.78.233 dev em4 src 172.22.78.35 table net_172 ip rule add from 172.22.78.35 table net_172 route del default gw 192.168.43.1 route add default gw 172.22.78.233
參考部落格:https://blog.csdn.net/qq_15735767/article/details/100578692
補充
負責的該專案是vue配合cas實現登入的 如果192網路改為172網路訪問還要改 vue前端配置檔案以及各個後端元件配置cas的部分把192改為172(專案還有設定子系統的地方也要修改)