
我有一台帶有 2 個乙太網路連接埠的伺服器,我想為其配置多個網關。
我希望連接埠 1 成為預設網關,並且希望來自連接埠 2 的流量透過連接埠 2 流出。
我遵循了許多關於如何執行此操作的指南,但我無法使其發揮作用。
這是我在介面文件上使用的腳本。
# The primary network interface
allow-hotplug eno2
iface eno2 inet dhcp
gateway 192.168.3.1
post-up ip route add 192.168.3.0/24 dev eno2 table ethvpn
post-up ip route add default via 192.168.3.1 dev eno2 table ethvpn
post-up ip rule add from 192.168.3.101/102 table ethvpn
post-up ip rule add to 192.168.3.101/102 table ethvpn
# Secondary network interface
allow-hotplug eno3
iface eno3 inet dhcp
post-up ip route add 192.168.0.0/24 dev eno3 table ethwan
post-up ip route add default via 192.168.0.1 dev eno3 table ethwan
post-up ip rule add from 192.168.0.101/102 table ethwan
post-up ip rule add to 192.168.0.101/102 table ethwan
如果我輸入: ip Rule show ,我的表格(ethwan、ethvpn)不會顯示。如果我嘗試手動輸入此命令: ip Rule add from 192.168.3.101/102 table ethwan 我收到錯誤:
Error: inet prefix is expected rather than "192.168.3.101/102".
當使用保留 IP 的 DHCP 時是否可以這樣做?我怎樣才能做到這一點?
答案1
192.168.0.101/102 不是有效的子網路。 /後面的數字是子網路遮罩的位數。如果您希望規則涵蓋 101 和 102 。為 192.168.101/32 和 192.168.0.102/32 執行 2 條單獨的規則