Chinaunix首页 | 论坛 | 博客
  • 博客访问: 39734
  • 博文数量: 22
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 200
  • 用 户 组: 普通用户
  • 注册时间: 2014-03-17 11:27
文章分类

全部博文(22)

文章存档

2016年(3)

2015年(19)

我的朋友

分类: 系统运维

2016-03-23 17:19:29

linux下静态路由修改命令
方法一:
添加路由
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
删除路由
route del -net 192.168.0.0/24 gw 192.168.0.1

add 增加路由
del 删除路由
-net 设置到某个网段的路由
-host 设置到某台主机的路由
gw 出口网关 IP地址
dev 出口网关 物理设备名


增加默认路由

route add default gw 192.168.0.1


查看路由表
route -n /netstat -rn






保存路由设置,使其在网络重启后任然有效 
在/etc/sysconfig/network-script/目录下创建名为route-eth0的文件 
vi /etc/sysconfig/network-script/route-eth0 
在此文件添加如下格式的内容 
192.168.1.0/24 via 192.168.0.1 




接下来让我们添加两条静态路由,访问192.168.142.100时通过192.168.142.10;访问192.168.142.200时通过192.168.142.20
192.168.142.100/32 via 192.168.142.10
192.168.142.200/32 via 192.168.142.20



################################################################
重启网络验证
 
 /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 

也就是说,将静态路由加到/etc/sysconfig/static-routes 文件中就行了。
 
如加入:
route add -net 11.1.1.0 netmask 255.255.255.0 gw 11.1.1.1


则static-routes的格式为
any net 11.1.1.0 netmask 255.255.255.0 gw 11.1.1.1

################################################################
阅读(483) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~