
這是來自 wg-quick 手冊頁的範例部分:
A combination of the `Table', `PostUp', and `PreDown'
fields may be used for policy routing as well. For example,
the following may be used to send SSH traffic (TCP port 22)
traffic through the tunnel:
[Interface]
Address = 10.192.122.1/24
PrivateKey = yAnz5TF+lXXJte14tji3zlMNq+hd2rYUIgJBgB3fBmk=
ListenPort = 51820
Table = 1234
PostUp = ip rule add ipproto tcp dport 22 table 1234
PreDown = ip rule delete ipproto tcp dport 22 table 1234
[Peer]
PublicKey = xTIBA5rboUvnH4htodjb6e697QjLERt1NAB4mZqp8Dg=
AllowedIPs = 0.0.0.0/0
這個例子對我來說似乎不完整。難道不應該有一個ip route
指定table 1234
來完成透過隧道發送 SSH 流量嗎?我遠非 Wireguard 和路由方面的專家,所以也許我錯過了幕後發生的事情。
答案1
預設情況下,wg-quick 會自動新增通過 wg0 的路由,該路由與該介面上所有對等方的AllowedIP 相對應。這就是範例中 Table= 參數的全部目的。
(儘管即使未指定 Table= 也會發生這種情況 - 然後路由將添加到主表中。可以使用 Table=off 來選擇退出此行為。)
systemd-networkd 的 WireGuard 支援中也存在類似的功能,但是是可選的(即即使對於主表也必須指定 Table=)。