问题
最近 VBox 虚拟机服务器双网卡(一个外网、一个内网)时不时出现网卡故障,每次恢复都需要断开、重连才可以恢复。尝试修改会报出一下警告
$ sudo netplan apply
** (generate:1060): WARNING **: 03:19:21.684: `gateway4` has been deprecated, use default routes instead.
See the 'Default routes' section of the documentation for more details.
尝试和解决
-
据说 ubuntu 22.04 的网关路由设置方式改变了,但是,查询他的安装文档
Network Configuration ,没有发现和 20.04 有什么差别 -
参考网上很多文章后,改成以下 (假设外网地址 12.34.56.78,内网 192.168.0.5)
$ cat 00-installer-config.yaml
# This is the network config written by 'subiquity' network: ethernets: enp0s8: addresses: - 12.34.56.78/28 # gateway4: 12.34.56.1 nameservers: addresses: - 223.5.5.5 - 114.114.114.114 search: [] optional: true routes: - to: default via: 12.34.56.1 metric: 10 enp0s3: addresses: - 192.168.0.5/24 # gateway4: 192.168.0.1 nameservers: addresses: - 223.5.5.5 - 114.114.114.114 search: [] optional: true routes: - to: 0.0.0.0/0 via: 192.168.0.1 metric: 100 version: 2
metric: 10 越小,优先级越高 ?
$ ip route list
default via 221.122.XXX.XXX dev eth0 proto static metric 10
default via 192.168.0.XX dev eth1 proto static metric 100
192.168.0.0/24 dev eth1 proto kernel scope link src 192.168.0.XX
221.122.XXX.XXX/28 dev eth0 proto kernel scope link src 221.122.XXX.XXX
-
但是 $ sudo netplan apply 出现警告和报错
** (generate:2624): WARNING **: 02:29:33.628: Problem encountered while validating default route consistency.Please set up multiple routing tables and use `routing-policy` instead. Error: Conflicting default route declarations for IPv4 (table: main, metric: 100), first declared in enp0s8 but also in enp0s3 ** (process:2622): WARNING **: 02:29:34.210: Problem encountered while validating default route consistency.Please set up multiple routing tables and use `routing-policy` instead. Error: Conflicting default route declarations for IPv4 (table: main, metric: 100), first declared in enp0s8 but also in enp0s3
$ ip route list
default via 192.168.0.1 dev enp0s8 proto static metric 100 default via 12.34.56.1 dev enp0s3 proto static metric 100 192.168.0.0/24 dev enp0s8 proto kernel scope link src 192.168.0.5 12.34.560/28 dev enp0s3 proto kernel scope link src 12.34.56.78
会发现确实出现 2 个 default
-
当时在实际环境,着急使用,所以,简单删除了内网的route,可以正常使用了
$ sudo ip route del 192.168.0.1
其实只是改变了 2 个 default 的次序 -
今天重新思考并测试:
既然外网已经有网关,那么,服务器访问外网不会有问题
内网访问其他资源,应该仅限于内网区域,所以,修改他的 to 就应该可以了!$ cat 00-installer-config.yaml
修改一下即可routes: - to: 192.168.0.0/24 # 0.0.0.0/0 via: 192.168.0.1 metric: 100
再次 $ sudo netplan apply 不再报错和警告
$ ip route list
default via 12.34.1 dev enp0s8 proto static metric 100 192.168.0.0/24 dev enp0s3 proto kernel scope link src 192.168.0.5 192.168.0.0/24 via 192.168.0.81 dev enp0s3 proto static metric 100 12.34.56.0/28 dev enp0s8 proto kernel scope link src 12.34.56.78
现在只有一个 default 了文章来源:https://www.toymoban.com/news/detail-457702.html
-
其他
安装设置虚拟机时,特意将外网卡放在前面,但是,不知道为什么,他竟然网卡名字对应反了,结果,apt update 时报错,ping 外网死活不通!
改正过来就好了!文章来源地址https://www.toymoban.com/news/detail-457702.html
到了这里,关于Ubuntu 22.04 双网卡网关设置报错:Conflicting default route declarations for IPv4的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!