会飞的鱼

2019
技术学习交流--用心学习--用心记录!
首页 » ▇ ESXI » ESXI添加静态路由

ESXI添加静态路由

打开esxi主机的ssh,通过ssh登陆到命令行界面下

添加静态路由如下:

添加静态路由命令
esxcli network ip route ipv4 add --gateway 10.195.1.254 --network 10.0.0.0/8
esxcli network ip route ipv4 add --gateway 10.195.1.254 --network 172.27.0.0/24
查看当前路由
[root@ESXI043:~] esxcfg-route -l
VMkernel Routes:
Network          Netmask          Gateway          Interface      
172.27.0.0       255.255.255.0    10.195.1.254     vmk0           
10.195.0.0       255.255.254.0    Local Subnet     vmk0           
172.27.0.0       255.255.0.0      10.195.1.254     vmk0           
10.0.0.0         255.0.0.0        10.195.1.254     vmk0           
default          0.0.0.0          10.195.0.25      vmk0     
该路由添加后重启机器会失效,添加到启动脚本开机自动运行
[root@ESXI043:~] vi  /etc/rc.local.d/local.sh 
#!/bin/sh

# local configuration options

# Note: modify at your own risk!  If you do/use anything in this
# script that is not part of a stable API (relying on files to be in
# specific places, specific tools, specific output, etc) there is a
# possibility you will end up with a broken system after patching or
# upgrading.  Changes are not supported unless under direction of
# VMware support.
esxcli network ip route ipv4 add --gateway 10.195.1.254 --network 10.0.0.0/8
esxcli network ip route ipv4 add --gateway 10.195.1.254 --network 172.27.0.0/24

重启后也能生效


官方文档步骤:
1. To add a static route, run the command:

esxcli network ip route ipv4/ipv6 add --gateway IPv4_address_of_router --network IPv4_address

For example, to add a route to 192.168.100.0 network with a /24 bit subnet mask (255.255.255.0) through a router with an IP address of 192.168.0.1, run this command:

esxcli network ip route ipv4 add --gateway 192.168.0.1 --network 192.168.100.0/24
2. To list the route, run the command:

esxcli network ip route ipv4 list
3. To remove a static route, run the command:

esxcli network ip route ipv4 remove -n network_ip/mask -g gateway_ip

For example, to remove a route from 192.168.100.0 network with a /24 bit subnet mask (255.255.255.0) through a router with an IP address of 192.168.0.1, run this command:

esxcli network ip route ipv4 remove -n 192.168.100.0/24 -g 192.168.0.1
4. When finished, check the host’s current routing table with the esxcfg-route -l command. Any static routes display in the output.
实例:

#查看路由
esxcfg-route -l
#添加
esxcli network ip route ipv4 add --gateway 10.10.190.1 --network 10.10.177.0/24
esxcli network ip route ipv4 add --gateway 10.10.190.1 --network 10.10.179.0/24
esxcli network ip route ipv4 add --gateway 10.10.190.1 --network 10.10.180.0/24
esxcli network ip route ipv4 add --gateway 10.10.190.1 --network 10.10.190.0/24
esxcli network ip route ipv4 add --gateway 10.10.190.1 --network 10.10.191.0/24
#删除默认路由
esxcli network ip route ipv4 remove -n 0.0.0.0/0 -g 10.10.190.1
#恢复默认路由
esxcli network ip route ipv4 add --gateway 10.10.190.1 --network 0.0.0.0/0
#查看路由
esxcfg-route -l


文章如无特别注明均为原创! 作者: Eagle, 转载或复制请以 超链接形式 并注明出处 枫叶落
原文地址《 ESXI添加静态路由》发布于2019-7-8

分享到:
打赏

评论

切换注册

登录

您也可以使用第三方帐号快捷登录

切换登录

注册