添加臨時路由
查看路由:
# route -n
添加路由:
# route add [-net|-host] target [netmask Nm] [gw Gw] [[dev If]
例如:
添加ip路由,目標:192.168.4.10 網關:172.16.2.2(必須與本地地址在同一網絡)
\# route add -host 192.168.4.10 gw 172.16.2.2 dev eth0(經由本地哪個網卡)
添加網絡路由,目標:192.168.20.0 網關:172.16.2.2
# route add -net 192.168.20.0 netmask 255.255.255.0 gw 172.16.2.2 ens33
# route add -net 192.168.20.0/24 gw 172.16.2.2 ens33
默認路由,網關:172.16.2.2
# route add -net 0.0.0.0 netmask 0.0.0.0 gw 172.16.2.2
# route add default gw 172.16.2.2
添加永久路由(需要重啓網絡)
編輯文件或者添加/etc/sysconfig/network-scripts/route-<interface-name>
,在最尾處添加對應的路由信息
10.0.0.0/16 via 192.168.4.2 dev ens33
這裏的
10.0.0.0/16
指需要配置路由的網段,192.168.4.2
指下一跳地址,ens33
指CentOS虛擬機所對應使用的網卡名。