iT邦幫忙

1

Ubuntu雙網卡Default Gateway問題

各位大神好,這個問題一直困擾我很久,網路上爬文也找不到解決辦法,因此來這邊詢問,還請各位幫幫忙,謝謝。

環境:

OS: ubuntu-20.04.1-live-server-amd64

機器為VirtualBox,總共有2張網卡,enp0s3對內 (Host-Only),enp0s8對外 (NAT),下圖是目前network interface的資訊
https://ithelp.ithome.com.tw/upload/images/20201115/20108478LOoBImlnUJ.png

問題發生在開機時,不管我網卡的順序如何變化,Default Gateway總是將192.168.0.1排在最上面,但我需要的是10.0.2.1,因為192.168.0.1無法連上internet,目前總是人工下指令 sudo route del default gw 192.168.0.1

請問有方法可以讓我開機時,網卡都啟用時,強制不將192.168.0.1設為Default Gateway嗎?

看更多先前的討論...收起先前的討論...
/etc /network /interfaces 設定開機網卡選項
使用:sudo nano /etc/network/interfaces
調整設定:
auto enp0s8
iface enp0s8 inet static
address 10.0.2.44
netmask 255.255.255.0
gateway 10.0.2.4
dns-nameservers 不知道你用的是什麼
tsunejui iT邦新手 5 級 ‧ 2020-11-15 22:13:15 檢舉
非常感謝您的回覆,但ubuntu 17後,似乎將 NetPlan 替換 /etc/network/interfaces了
雷夢卡爾 iT邦研究生 5 級 ‧ 2020-11-16 10:46:26 檢舉
可以將 192.168.0.1 Gateway 設定值 拿掉嗎?
tsunejui iT邦新手 5 級 ‧ 2020-11-19 01:53:19 檢舉
可以。拿掉後便能通訊了
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

0
edison02
iT邦新手 4 級 ‧ 2020-11-16 10:52:23
最佳解答

1.先搞清楚你需不需要兩個gateway
2.依你現在的環境,調整10.0.2.1 的metric 高於192.168.0即可.請自行搜尋如何調整metric,
你應該會有進一步了解對於作業系統route的設定.
https://ithelp.ithome.com.tw/upload/images/20201116/20120091lVZBxKPyb6.jpg

tsunejui iT邦新手 5 級 ‧ 2020-11-19 01:52:49 檢舉
  1. 經過重新檢視架構,目前的服務確實不需要兩個gateway,拿掉後便沒有問題。
  2. 後來在Document上的確有找到如何修改metric,也補充了一些網路的知識,謝謝您。
1
japhenchen
iT邦超人 1 級 ‧ 2020-11-16 08:00:52

這裡有詳細的說明
https://netplan.io/examples/

tsunejui iT邦新手 5 級 ‧ 2020-11-16 11:21:05 檢舉

非常感謝您,我來試試看,可能文件漏看了

tsunejui iT邦新手 5 級 ‧ 2020-11-19 01:51:36 檢舉

謝謝您,文件上有提到如何修改metric

我要發表回答

立即登入回答