linux 添加静态路由
2015-06-15 00:00
411 查看
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 查看路由表
方法二:
添加路由
ip route add 192.168.0.0/24 via 192.168.0.1
ip route add 192.168.1.1 dev 192.168.0.1
删除路由
ip route del 192.168.0.0/24 via 192.168.0.1
add 增加路由
del 删除路由
via 网关出口 IP地址
dev 网关出口 物理设备名
增加默认路由
ip route add default via 192.168.0.1 dev eth0
via 192.168.0.1 是我的默认路由器
查看路由信息
ip route
保存路由设置,使其在网络重启后任然有效
在/etc/sysconfig/network-script/目录下创建名为route- eth0的文件
vi /etc/sysconfig/network-script/route-eth0
在此文件添加如下格式的内容
192.168.1.0/24 via 192.168.0.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
也就是说,将静态路由加到/etc/sysconfig/static-routes 文件中就行了。
二:在linux下设置永久路由的方法:
1.在/etc/rc.local里添加
方法:
route add -net 192.168.3.0/24 dev eth0
route add -net 192.168.2.0/24 gw 192.168.3.254
2.在/etc/sysconfig/network里添加到末尾
方法:GATEWAY=gw-ip 或者 GATEWAY=gw-dev
3./etc/sysconfig/static-router :
any net x.x.x.x/24 gw y.y.y.y
如加入:
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
方法一:
添加路由
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 查看路由表
方法二:
添加路由
ip route add 192.168.0.0/24 via 192.168.0.1
ip route add 192.168.1.1 dev 192.168.0.1
删除路由
ip route del 192.168.0.0/24 via 192.168.0.1
add 增加路由
del 删除路由
via 网关出口 IP地址
dev 网关出口 物理设备名
增加默认路由
ip route add default via 192.168.0.1 dev eth0
via 192.168.0.1 是我的默认路由器
查看路由信息
ip route
保存路由设置,使其在网络重启后任然有效
在/etc/sysconfig/network-script/目录下创建名为route- eth0的文件
vi /etc/sysconfig/network-script/route-eth0
在此文件添加如下格式的内容
192.168.1.0/24 via 192.168.0.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
也就是说,将静态路由加到/etc/sysconfig/static-routes 文件中就行了。
二:在linux下设置永久路由的方法:
1.在/etc/rc.local里添加
方法:
route add -net 192.168.3.0/24 dev eth0
route add -net 192.168.2.0/24 gw 192.168.3.254
2.在/etc/sysconfig/network里添加到末尾
方法:GATEWAY=gw-ip 或者 GATEWAY=gw-dev
3./etc/sysconfig/static-router :
any net x.x.x.x/24 gw y.y.y.y
如加入:
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
相关文章推荐
- linux 打包
- Centos7 编译 android4.4
- <二> Linux如何学习
- linux 补充
- <一> Linux是什么
- Linux添加 用户
- linux目录结构
- Linux命令行用SpiderMonkey执行javascript脚本
- 查看linux是32还是64位
- 在CentOS7或RHEL7防火墙上开启端口
- cv:显示Linux命令运行进度
- cv:显示Linux命令运行进度
- Linux系统编程——线程同步与互斥:互斥锁
- 每天多学一个Linux命令--man
- Linux内核中常见内存分配函数
- Linux文件系统管理(2)
- linux小知识二
- linux文件系统操作
- CentOS配置bond ip冗余
- linux系统rsync服务器的管理与配置