路由增删改

原来:
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.250.0.0 0.0.0.0 255.255.255.0 U 1 0 0 eth1
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
10.0.0.0 10.250.0.1 255.0.0.0 UG 0 0 0 eth1
0.0.0.0 10.250.0.1 0.0.0.0 UG 0 0 0 eth1

需求:服务器10.250.0.31的默认网关指向10.250.0.252,同时新增路由访问内网10.0.0.0/8的下一跳为10.250.0.1

操作:
route add default gw 10.250.0.252
route add -net 10.0.0.0/8 gw 10.250.0.1
route del -net 0.0.0.0 gw 10.250.0.1

现在:
$ route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
10.250.0.0 0.0.0.0 255.255.255.0 U 1 0 0 eth1
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
10.0.0.0 10.250.0.1 255.0.0.0 UG 0 0 0 eth1
0.0.0.0 10.250.0.252 0.0.0.0 UG 0 0 0 eth1

==========================================================

目标:虚拟机可以访问172.16.100、101、102。。。等网段

1、虚拟机增加网卡,vlan选择为ipmi(ip段为172.16.3.*)

2、上述虚拟机的新网卡配置ip为172.16.3.*,netmask为255.255.252.0(不需要配网关),并确定能ping通172.16.0.1

3、上述虚拟机增加以下路由:
route add -net 172.16.100.0 netmask 255.255.255.0 gw 172.16.0.1
route add -net 172.16.101.0 netmask 255.255.255.0 gw 172.16.0.1
route add -net 172.16.102.0 netmask 255.255.255.0 gw 172.16.0.1
route add -net 172.16.103.0 netmask 255.255.255.0 gw 172.16.0.1
route add -net 172.16.104.0 netmask 255.255.255.0 gw 172.16.0.1
route add -net 172.16.105.0 netmask 255.255.255.0 gw 172.16.0.1

删除路由
route del -net 172.16.100.0 netmask 255.255.255.0 gw 172.16.0.1

 

 

其中Windows命令如下:
route -p add 172.16.100.0 mask 255.255.255.0 172.16.0.1
route -p add 172.16.105.0 mask 255.255.255.0 172.16.0.1