Ubuntu 雙網卡配置優先級
Ubuntu的網卡配置跟CentOS不太一樣,
更多請參考:Linux 雙網卡配置優先級
根據業務需要,有時候服務器需要兩張網卡,一張用于訪問外網,另一種用于連接內網,
如果在安裝系統是就對兩張網卡進行配置了的話,就比較方便,這里不再討論,
下面是后期添加的一張網卡
ens37,其中ens33用于連接內網,ens37用于連接外網,話不多說,直入正題,
啟用網卡
查看所有網卡資訊:
ifconfig -a
啟用網卡,ens37是我用于連接外網的網卡,
sudo ifconfig ens37 up
此時網卡已啟用,但是可能會由于網卡路由優先級的問題,還不能訪問外網,
查看路由資訊:ip route show
可以看到兩張網卡的metric (躍點數),ens33的躍點數默認值是100,比ens37的值小,所以會通過ens33連接外網(但是業務需求是ens33連接的是內網而不是外網),因此不能訪問外網,
修改網卡路由優先級
這里為了讓ens37的路由優先級高于ens33,需要將ens37的躍點數改成小于ens33的躍點數(默認100),我們這里將ens37的躍點數改成90,
注:Ubuntu使用netplan配置網卡
sudo vim /etc/netplan/50-cloud-init.yaml
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
ethernets:
ens33:
dhcp4: true
ens37:
dhcp4: true
dhcp4-overrides:
route-metric: 90
version: 2
這個組態檔看起來很清楚,ens37是要訪問外網的網卡,躍點數設定成了90,而ens33默認躍點數100,
然后執行命令:
sudo netplan apply
查看路由資訊:ip route show

這時就可以通過ens37來訪問外網了,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/179297.html
標籤:其他
上一篇:揭開 gcc 編輯器的面貌
