在各种系统内添加静态路由

Windows
route add -p 10.0.0.0 mask 255.0.0.0 10.10.16.1
route add -p 10.10.11.0 mask 255.255.255.0 10.10.12.1
route add -p 10.10.13.0 mask 255.255.255.0 10.10.12.1
route add -p 10.10.14.0 mask 255.255.255.0 10.10.12.1
Cisco IOS、IOS-XE
ip route 10.0.0.0 255.0.0.0 10.10.200.2254
ip route 10.10.11.0 255.255.255.0 10.10.12.1
Cisco NX-OS
N7K(config)#vrf context management
N7K(config-vrf)# ip route 0.0.0.0/0 <下一跳IP>
Linux(通用,临时)
1 route add -net 10.10.11.0/20 gw 10.10.12.1
CentOS(永久)
推荐方式:

echo ’
10.10.12.0/24 via 10.10.15.1
10.10.13.0/24 via 10.10.15.1
10.10.14.0/24 via 10.10.15.1
10.10.15.0/24 via 10.10.15.1
10.10.16.0/24 via 10.10.15.1
’ > /etc/sysconfig/network-scripts/route-eth0
另外一种方法:使用network.service(CentOS7默认,CentOS8需要yum install network-scripts)
echo ’
any net 10.10.13.0/24 gw 10.10.15.1
any net 10.10.14.0/24 gw 10.10.15.1
any net 10.10.15.0/24 gw 10.10.15.1
any net 10.10.16.0/24 gw 10.10.15.1
’ > /etc/sysconfig/static-routes
验证
ip route
Ubuntu(永久)
16.04
#添加
cat >> /etc/network/interfaces << EOF

static routes

up route add -net 10.10.12.0/24 gw 10.10.15.1 dev eth0
up route add -net 10.10.13.0/24 gw 10.10.15.1 dev eth0
up route add -net 10.10.14.0/24 gw 10.10.15.1 dev eth0
up route add -net 10.10.15.0/24 gw 10.10.15.1 dev eth0
up route add -net 10.10.16.0/24 gw 10.10.15.1 dev eth0
EOF

#重启网络
service networking restart

#验证
ip route
NetPlan
Ubuntu 18.04、20.04及以上
18.04: /etc/netplan/50-cloud-init.yaml
20.04:/etc/netplan/00-installer-config.yaml
network:
version: 2
ethernets:
eth0:
addresses:
- 10.10.15.5/24
gateway4: 10.10.15.1
nameservers:
addresses:
- 10.10.15.11
- 10.10.15.12
search:
- sysin.org
//注释gateway4
sed -i ‘s/gateway4.*/#&/’ /etc/netplan/00-installer-config.yaml
//追加静态路由
cat >> /etc/netplan/00-installer-config.yaml << EOF
routes:
- to: 0.0.0.0/0
via: 10.10.15.254
metric: 100
- to: 10.10.12.0/24
via: 10.10.15.1
metric: 100
- to: 10.10.13.0/24
via: 10.10.15.1
metric: 100
- to: 10.10.14.0/24
via: 10.10.15.1
metric: 100
- to: 10.10.15.0/24
via: 10.10.15.1
metric: 100
- to: 10.10.16.0/24
via: 10.10.15.1
metric: 100
EOF
metric:为路由指定所需跃点数的整数值(范围是 1 ~ 9999),Metric的值越小,优先级越高。
完整配置示例(>覆盖)
cat > /etc/netplan/00-installer-config.yaml << EOF
network:
version: 2
ethernets:
eth0:
addresses:
- 10.10.15.57/24
#gateway4: 10.10.15.254
nameservers:
addresses:
- 10.10.15.11
- 10.10.15.12
search:
- sysin.org
routes:
- to: 0.0.0.0/0
via: 10.10.15.254
metric: 100
- to: 10.10.12.0/24
via: 10.10.15.1
metric: 100
- to: 10.10.13.0/24
via: 10.10.15.1
metric: 100
- to: 10.10.14.0/24
via: 10.10.15.1
metric: 100
- to: 10.10.15.0/24
via: 10.10.15.1
metric: 100
- to: 10.10.16.0/24
via: 10.10.15.1
metric: 100
EOF
多网关
network:
version: 2
renderer: networkd
ethernets:
eth0:
addresses:
- 9.0.0.9/24
- 10.0.0.10/24
- 11.0.0.11/24
#gateway4: # unset, since we configure routes below
routes:
- to: 0.0.0.0/0
via: 9.0.0.1
metric: 100
- to: 0.0.0.0/0
via: 10.0.0.1
metric: 100
- to: 0.0.0.0/0
via: 11.0.0.1
metric: 100
1 netplan apply
补充:yaml 基础
大小写敏感
使用缩进表示层级关系
缩进时不允许使用Tab键,只允许使用空格
缩进的空格数目不重要,只要相同层级的元素左侧对齐即可
缩进建议使用2个空格,使用短横线“-”表示列表时,”- “后面的条目需要对齐,如果使用超过2个空格缩进,格式将有误。
VMware ESXi
#查看路由
esxcfg-route -l
#添加
esxcli network ip route ipv4 add --gateway 10.10.15.1 --network 10.10.12.0/24
esxcli network ip route ipv4 add --gateway 10.10.15.1 --network 10.10.13.0/24
esxcli network ip route ipv4 add --gateway 10.10.15.1 --network 10.10.14.0/24
esxcli network ip route ipv4 add --gateway 10.10.15.1 --network 10.10.15.0/24
esxcli network ip route ipv4 add --gateway 10.10.15.1 --network 10.10.16.0/24
#删除默认路由
esxcli network ip route ipv4 remove -n 0.0.0.0/0 -g 10.10.15.1
#恢复默认路由
esxcli network ip route ipv4 add --gateway 10.10.15.254 --network 0.0.0.0/0
#查看路由
esxcfg-route -l
esxcfg-route -l

esxcli network ip route ipv4 add --gateway 10.10.14.1 --network 10.10.12.0/24
esxcli network ip route ipv4 add --gateway 10.10.14.1 --network 10.10.13.0/24
esxcli network ip route ipv4 add --gateway 10.10.14.1 --network 10.10.14.0/24
esxcli network ip route ipv4 add --gateway 10.10.14.1 --network 10.10.15.0/24
esxcli network ip route ipv4 add --gateway 10.10.14.1 --network 10.10.16.0/24

esxcli network ip route ipv4 remove -n 0.0.0.0/0 -g 10.10.14.1

esxcli network ip route ipv4 add --gateway 10.10.14.254 --network 0.0.0.0/0

esxcfg-route -l
NSX-T
基于Ubuntu,但不可手动编辑,以下为 nsxcli (使用admin账号登录)
set route prefix 0.0.0.0/0 gateway 10.10.15.254 interface eth0

set route prefix 10.10.12.0/24 gateway 10.10.15.1 interface eth0
set route prefix 10.10.13.0/24 gateway 10.10.15.1 interface eth0
set route prefix 10.10.14.0/24 gateway 10.10.15.1 interface eth0
set route prefix 10.10.15.0/24 gateway 10.10.15.1 interface eth0
set route prefix 10.10.16.0/24 gateway 10.10.15.1 interface eth0

get route
VMware vRealize Network Insight
基于Ubunt 16.04,与Ubuntu相同
使用support账号登录
#添加
cat >> /etc/network/interfaces << EOF

static routes

up route add -net 10.10.12.0/24 gw 10.10.15.1 dev eth0
up route add -net 10.10.13.0/24 gw 10.10.15.1 dev eth0
up route add -net 10.10.14.0/24 gw 10.10.15.1 dev eth0
up route add -net 10.10.15.0/24 gw 10.10.15.1 dev eth0
up route add -net 10.10.16.0/24 gw 10.10.15.1 dev eth0
EOF

#重启网络
service networking restart

#验证
ip route
VMware Photon OS
vCenter Server 6.x/7.0
用于vRealize 8.x 系列产品(3.0),vSphere_Replication(2.0),SRM(2.0)
编辑/etc/systemd/network/10-eth0.network 添加 [Route] Destination=10.1.0.0/16 Gateway=10.5.0.1 GatewayOnlink=true #可选
cat >> /etc/systemd/network/10-eth0.network << EOF

[Route]
Destination=10.10.12.0/24
Gateway=10.10.15.1
GatewayOnlink=true

[Route]
Destination=10.10.13.0/24
Gateway=10.10.15.1
GatewayOnlink=true

[Route]
Destination=10.10.14.0/24
Gateway=10.10.15.1
GatewayOnlink=true

[Route]
Destination=10.10.15.0/24
Gateway=10.10.15.1
GatewayOnlink=true

[Route]
Destination=10.10.16.0/24
Gateway=10.10.15.1
GatewayOnlink=true
EOF
重启网络
1 systemctl restart systemd-networkd
验证
1 ip route
VMware Cloud Director Availability 4.0
注意:手动修改网络配置后,WebUI中显示错误无法直接配置。
基于 Photon OS,但是网卡名称不一样。
cat >> /etc/systemd/network/ens160.network << EOF

[Route]
Destination=10.10.12.0/24
Gateway=10.10.15.1
GatewayOnlink=true

[Route]
Destination=10.10.13.0/24
Gateway=10.10.15.1
GatewayOnlink=true

[Route]
Destination=10.10.14.0/24
Gateway=10.10.15.1
GatewayOnlink=true

[Route]
Destination=10.10.15.0/24
Gateway=10.10.15.1
GatewayOnlink=true

[Route]
Destination=10.10.16.0/24
Gateway=10.10.15.1
GatewayOnlink=true
EOF
重启网络
systemctl restart systemd-networkd
感谢关注收藏留着备用

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

优质网络系统领域创作者

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值