我正在关注我在 Serverfault 上找到的答案https://serverfault.com/a/487911/141509
我在 rt_table 中创建了以下路由表
10 wlx74da388c32c7
以下是我的完整 rt_table
#
# reserved values
#
255 local
254 main
253 default
0 unspec
#
# local
#
#1 inr.ruhep
10 wlx74da388c32c7
我正在尝试将我的ip route add
和ip rule add
命令转换为我的 netplan。以下是两个命令。
ip route add default via 172.16.11.254 table wlx74da388c32c7
ip rule add from 172.16.11.107 lookup wlx74da388c32c7
172.16.11.107 是 IP 地址,172.16.11.254 是网关地址。下面是我现在得到的,但我知道它是错误的
network:
ethernets:
enp1s0:
addresses:
- 192.168.1.212/24
gateway4: 192.168.1.1
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
search: []
optional: true
wifis:
wlx74da388c32c7:
dhcp4: true
access-points:
"home":
password: "mypassword"
routes:
- to: 172.16.11.0/24
via: 172.16.11.254
table: 10
routing-policy:
- from: 172.16.11.0/24
table: 10
version: 2
编辑
以下是我最新的 yaml 文件
network:
ethernets:
enp1s0:
addresses:
- 192.168.1.212/24
gateway4: 192.168.1.1
nameservers:
addresses:
- 8.8.8.8
- 8.8.4.4
search: []
optional: true
wifis:
wlx74da388c32c7:
dhcp4: true
access-points:
"home":
password: "mypassword"
routes:
- to: 0.0.0.0/0
via: 172.16.11.254
metric: 100
table: 10
routing-policy:
- from: 172.16.11.0/24
table: 10
version: 2
下面是ip addr show
命令
root@poweredge:~# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 00:1e:4f:cd:c1:5f brd ff:ff:ff:ff:ff:ff
inet 192.168.1.212/24 brd 192.168.1.255 scope global enp1s0
valid_lft forever preferred_lft forever
inet6 fe80::21e:4fff:fecd:c15f/64 scope link
valid_lft forever preferred_lft forever
3: wlx74da388c32d0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 74:da:38:8c:32:d0 brd ff:ff:ff:ff:ff:ff
4: wlx74da388c32c7: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 74:da:38:8c:32:c7 brd ff:ff:ff:ff:ff:ff
inet 172.16.11.107/24 brd 172.16.11.255 scope global dynamic wlx74da388c32c7
valid_lft 2997sec preferred_lft 2997sec
inet6 fe80::76da:38ff:fe8c:32c7/64 scope link
valid_lft forever preferred_lft forever
ip rule show
结果
root@poweredge:~# ip rule show
0: from all lookup local
0: from 172.16.11.0/24 lookup 10
32766: from all lookup main
32767: from all lookup default
ip route show
结果
root@poweredge:~# ip route show
default via 192.168.1.1 dev enp1s0 proto static
default via 172.16.11.254 dev wlx74da388c32c7 proto dhcp src 172.16.11.107 metric 600
172.16.11.0/24 dev wlx74da388c32c7 proto kernel scope link src 172.16.11.107
172.16.11.254 dev wlx74da388c32c7 proto dhcp scope link src 172.16.11.107 metric 600
192.168.1.0/24 dev enp1s0 proto kernel scope link src 192.168.1.212
答案1
你为什么不看看我的维基百科?
为了有所帮助,您需要显示 ip 规则和 ip 路由内容...我们不关心 rt_table 或除配置文件之外的任何文件内容。如果工具使用 yaml,则无需事后查看系统文件。
你应该用这个做什么:
路线: - 至:172.16.11.0/24 经由:172.16.11.254 表:10
只访问子网 172.16.11.0?因为如果只是这样,那么您就不需要网关,如果设备直接连接,那么它将默认响应来自此子网的所有请求。这是网络 101,基本上是“连接”和“静态”之间的区别。如果目标是拥有一个真正的网关,那么您的路由肯定不好,应该是 0.0.0.0/0,这是网络和网络掩码,意味着来自任何地方的所有网络。再次是网络 101。这样更清楚吗?
答案2
尝试将on-link
属性设置为真的在routes
:
routes:
- to: 0.0.0.0/0
via: 172.16.11.254
on-link: true
metric: 100
table: 10