在 CentOS 系統中,您可以使用 route
命令來添加和刪除路由
route -n
這將顯示類似于以下內容的輸出:
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 100 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
確定要刪除的路由。例如,如果您要刪除目標為 192.168.1.0
的路由,請記下其目標地址、子網掩碼和下一跳網關(在本例中為 192.168.1.1
)。
使用 route del
命令刪除路由。將 <destination>
、<subnet_mask>
和 <gateway>
替換為您在上一步中找到的值:
route del <destination> netmask <subnet_mask> gateway <gateway>
例如:
route del 192.168.1.0 netmask 255.255.255.0 gateway 192.168.1.1
route -n
命令,檢查輸出中是否不再包含您剛剛刪除的路由。請注意,這些命令適用于基于 IPv4 的系統。如果您的 CentOS 系統同時支持 IPv4 和 IPv6,您可能需要使用 ip
命令代替 route
命令。