1.查看路由
route -n
2.修改路由表,重启后失效
(1)添加静态路由
route add -net 192.168.0.0/24 gw 192.168.0.1
route add -host 192.168.1.1 dev 192.168.0.1
(2)删除路由
route del -net 192.168.0.0/24 gw 192.168.0.1
参数说明:
add 增加路由
del 删除路由
-net 设置到某个网段的路由
-host 设置到某台主机的路由
gw 出口网关 IP地址
dev 出口网关 物理设备名
3.增加默认路由
route add default gw 192.168.0.1
4.添加永久静态路由
方法1:
(1)在/etc/sysconfig/network-script/目录下创建名为route- eth0的文件
vi /etc/sysconfig/network-script/route-eth0
(2)在此文件添加如下格式的内容
192.168.1.0/24 via 192.168.0.1
保存路由设置
(3)重启网络验证
systemctl restart network
方法2:
(1)查看/etc/rc.d/init.d/network,是否有以下几行内容:
# Add non interface-specific static-routes.
if [ -f /etc/sysconfig/static-routes ]; then
grep "^any" /etc/sysconfig/static-routes | while read ignore args ; do
/sbin/route add -$args
done
fi
(2)如够有,则将静态路由加到/etc/sysconfig/static-routes 文件中就行了,如果没有怎添加进去。
(3)在/etc/sysconfig/static-routes添加路由
any net 11.1.1.0 netmask 255.255.255.0 gw 11.1.1.1