linuxwin7添加静态路由命令令

相关文章推荐:
linux下添加静态路由
linux下添加路由的方法:
一:使用 route 命令添加
使用route 命令添加的路由,机器重启或者网卡重启后路由就失效了,方法:
//添加到主机的路由
# route add Chost 192.168.168.110 dev eth0
# route add Chost 192.168.168.119 gw 192.168.168.1
//添加到网络的路由
# route add Cnet IP netmask MASK eth0
# route add Cnet IP netmask MASK gw IP
# route add Cnet IP/24 eth1
//添加默认网关
# route add default gw IP...
阅读(647) 回复(0)
其他文章推荐
linux下添加路由的方法:
一:使用 route 命令添加
使用route 命令添加的路由,机器重启或者网卡重启后路由就失效了,方法:
//添加到主机的路由
# route add Chost 192.168.168.110 dev eth0
# route add Chost 192.168.168.119 gw 192.168.168.1
//添加到网络的路由
# route add Cnet IP netmask MASK eth0
# route add Cnet IP netmask MASK gw IP
# route add Cnet IP/24 eth1
//添加默认网关
# route add default gw IP
阅读(400) 回复(0)
linux下添加路由的方法:
一:使用 route 命令添加
使用route 命令添加的路由,机器重启或者网卡重启后路由就失效了,方法:
//添加到主机的路由
# route add Chost 192.168.168.110 dev eth0
# route add Chost 192.168.168.119 gw 192.168.168.1
//添加到网络的路由
# route add Cnet IP netmask MASK eth0
# route add Cnet IP netmask MASK gw IP
# route add Cnet IP/24 eth1
//添加默认网关
# route add default gw IP...
阅读(469) 回复(0)
linux下添加IP地址和静态路由:
ifconfig eth0 192.168.0.23 netmask 255.255.255.0
route add -net 0.0.0.0/0 dev eth0
route add -net 0.0.0.0/0 gw 192.168.0.254
freebsd下添加IP地址和静态路由:
ifconfig rl0 192.168.0.23 255.255.255.0
route add -net 0.0.0.0/0 192.168.0.254
2. 通过rc.conf永久配置
# Add static route
static_routes="net1 net2"
route_net1="-net 192.168.0.0/24 192.168.0.1"
route_net2="-net 192....
阅读(1414) 回复(0)
用Openvpn使用tun方式对接公司二分部网络后,每次都需手动增加静态路由才能使双方互访,请教大家能不能在Openvpn连接后自动增加静态路由,或是等tun接口启动以后自动增加?
阅读(2196) 回复(2)
linux下添加IP地址和静态路由:
ifconfig eth0 192.168.0.23 netmask 255.255.255.0
route add -net 0.0.0.0/0 dev eth0
route add -net 0.0.0.0/0 gw 192.168.0.254
freebsd下添加IP地址和静态路由:
ifconfig rl0 192.168.0.23 255.255.255.0
route add -net 0.0.0.0/0 192.168.0.254
2. 通过rc.conf永久配置
# Add static route
static_routes="net1 net2"
route_net1="-net 192.168.0.0/24 192.168.0.1"
route_net2="-ne...
阅读(1744) 回复(0)
用Openvpn使用tun方式对接公司二分部网络后,每次都需手动增加静态路由才能使双方互访,请教大家能不能在Openvpn连接后自动增加静态路由,或是等tun接口启动以后自动增加?
阅读(2231) 回复(2)
linux静态路由添加删除
route add -net 192.168.13.0/24 gw 192.168.28.1 dev eth0
route del -net 192.168.13.0/24
永久添加:
(1). 编辑文件:/etc/sysconfig/static-routes
添加内容:“eth0 net 192.168.13.0/24 gw 192.168.0.1”
(2). 把命令写入/etc/rc.local
ip route add 192.168.13.0/24 via 192.168.28.1 dev eth0
ip route del 192.168.13.0/24
永久添加:
(1). 编...
阅读(1336) 回复(0)
编辑/etc/sysconfig/static-routes
在RHEL4中测试通过
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/77512/showart_1157204.html
阅读(883) 回复(0)
这段时间在研究linux平台下静态路由添加的问题,目前在我们平台上添加静态路由是通过route add命令来实现的,在使用route add时发现了一些问题,请大家帮忙一起看一下
环境如下:
假设PC1有一张网卡,IP为192.168.1.100,mask为255.255.255.0,gateway为192.168.1.1,dev为eth0
如果没有设定静态路由的话,对google(IP为203.208.39.104)做ping测试发现正常
使用route add -net 203.208.39.104 netmask 255.255.255.255 dev eth...
阅读(4211) 回复(12)
以下代码改自net-tools相关代码:
#include ;
#include ;
#include ;
#include ;
#include ;
#include ;
#include ;
#include ; /* realy broken */
#include ;
#include ;
#include ;
#include ;
#include ;
#include ;
#include ;
阅读(2317) 回复(0)
盛拓传媒:
北京皓辰网域网络信息技术有限公司. 版权所有
北京市公安局海淀分局网监中心备案编号:
广播电视节目制作经营许可证:编号(京)字第1149号
ITPUB推荐文章解答你所有技术难题Access denied | www.bkjia.com used Cloudflare to restrict access
Please enable cookies.
What happened?
The owner of this website (www.bkjia.com) has banned your access based on your browser's signature (76ca-ua98).Linux操作系统静态路由设置技巧介绍_老文章_赛迪网
Linux操作系统静态路由设置技巧介绍
Linux操作系统静态路由设置技巧介绍
Linux操作系统静态路由设置技巧介绍
发布时间: 15:05&&&&&&&&来源:&&&&&&&&作者:lynn
1.添加网卡
插入网卡,启动机器,修改/etc/modules.conf并加入
alias eth2 driver.o
2.配置adsl拨号
通过adsl-setup程序创建ppp0和ppp1的拨号配置文件,并保存配置。
修改/etc/sysconfig/network-script/ifcfg-ppp*文件,将其中的PIDFILE参数设为:
PIDFILE=/var/run/ppp-adsl*.pid
其中*对应0、1等
如果不修改此参数将无法启动第二个ppp接口。
3.启动ppp接口
因为adsl-start 命令缺省只能启动第一的ppp接口。所以要启动两个接口,必须指定配置文件。
adsl-start /etc/sysconfig/network-script/ifcfg-ppp0
adsl-start /etc/sysconfig/network-script/ifcfg-ppp1
4.添加路由表
缺省情况下,系统只有3个路由表,local、main、default,路由规则为所有进入的数据报都参照main、defaul来决策路由,这可以通过ip rule ls来查看。其输出如下:
# ip rule ls
0: from all lookup local
32766: from all lookup main
32767: from all lookup 253
要实现策略路由,添加额外的路由表是必须的。
下面两条命令分别添加名为ppp0和ppp1的路由表。
echo 201 ppp0 >> /etc/iproutes/rt_tables
echo 202 ppp1 >> /etc/iproutes/rt_tables
5.创建路由表项
上面创建的两个路由表都是空表,需要在其中注入路由表项。
本人编写了如下脚本用于注入路由表项:
#!/bin/bash
# Name: cprt
# This program copy the route from route table to route table,
# exclude the default route entry.
echo $&usage: cprt &source_table& &dest_table&&
# Clear the destination route table
echo $&Clearing route table $DEST ......&
/sbin/ip route flush table $DEST
# Inject routes from source to destination
echo $&Injecting route from $SOURCE to $DEST ......&
/sbin/ip route ls table $SOURCE | grep -v default & /tmp/route-tmp
/sbin/ip route add table $DEST $line
done & &/tmp/route-tmp&
把main表中的路由表项复制到ppp0和ppp1中。
将下面命令加入到/etc/rc.d/rc.local中。
cprt main ppp0
cprt main ppp1
此时,两个路由表中都有相同的路由表项了,除了default路由以外。缺省路由的添加要通过另外的途径添加。当ppp激活,或者掉线时,pppd守护进程会调用/etc/ppp/目录下的ip-up、ip-down脚本,这些教本又分别调用ip-up.local、ip-down.local。在此我们利用这两个脚本来对路由表和流量控制策略进行维护,此脚本需要人工创建。
下面时本例中的脚本:
#!/bin/bash
# Name: ip-up.local
# Created by lyking@CU
check_default_route ()
LC_ALL=C ip route list table match 0/0 | grep -q default
# Determin device here
# We should use IFNAME as the interface name.For some reason, the IFNAME maybe not
# same as the LINKNAME. And the route table should associate with the IFNAME. For
# some conveniency, I name the route table as &ppp0& and &ppp1&.
RT_TABLE=$IFNAME
# Add or change static route here
ip route change default dev $IFNAME table $RT_TABLE
ip route add default dev $IFNAME table $RT_TABLE
# Write some messages for later trubleshooting.
echo && /var/log/ifchang.log
echo &: $IFNAME going up at `date`.& && /var/log/ifchang.log
echo &: $IFNAME got address: $IPLOCAL, peer address is $IPREMOTE.& && /var/log/ifchang.log
echo &: Table $RT_TABLE default route change to `ip route ls table $RT_TABLE | grep
default`.& && /var/log/ifchang.log
# Refresh routing cache to activating the routing immediately.
ip route flush cache
#!/bin/bash
# Name: ip-down.local
# Created by lyking@CU
cd /etc/sysconfig/network-scripts
. network-functions
# Determin device here
# We should use IFNAME as the interface name.For some reason, the IFNAME maybe not
# same as the LINKNAME. And the route table should associate with the IFNAME. For
# some conveniency, I name the route table as &ppp0& and &ppp1&.
RT_TABLE=$IFNAME
PPPS=&ppp0 ppp1&
# Looking for a valide connection to Internet
DEFAULT_RT=&&
for i in $PPPS ; do
echo &Checking $i ...& && /tmp/if-down.log
echo &$i is available.& && /tmp/if-down.log
DEFAULT_RT=$i
# Update default route here
ip route add default dev $DEFAULT_RT table $RT_TABLE
ip route del default dev $IFNAME table $RT_TABLE
# Write some messages for later trubleshooting.
echo && /var/log/ifchang.log
echo &: $IFNAME going down at `date`.& && /var/log/ifchang.log
echo &: Connection lasted $CONNECT_TIME seconds.& && /var/log/ifchang.log
echo &: $BYTES_SENT bytes sent, $BYTES_RCVD bytes received.& && /var/log/ifchang.log
echo &: Table $RT_TABLE default route changed to `ip route ls table $RT_TABLE | grep
default`. & && /var/log/ifchang.log
# Refresh routing cache to activating the routing immediately.
ip route flush cache
注意,创建完脚本后必须将其属性改为可执行,否则不会被执行。
6.路由策略的选择
策略路由可以通过源地址、目标地址、ToS或者fwmark标记来进行选择。在此,为了利用iptables的强大的过滤功能采用fwmark标记来决策路由。
在/etc/rc.d/rc.local中添加如下命令:
/sbin/ip rule add fwmark 1 table ppp0
/sbin/ip rule add fwmark 2 table ppp1
7.防火墙规则的添加
这里利用的iptables的强大过滤功能来对流量进行标记。本例中仅根据ip地址的奇偶性来拆分流量,根据具体需求,你还可以根据第4层端口号、ToS等来拆分流量。防火墙需要添加如下命令:
# Divid traffic to different mark
iptables -t mangle -A PREROUTING -s 10.0.0.0/255.255.255.1 -j MARK --set-mark 0x1
iptables -t mangle -A PREROUTING -s 10.0.0.1/255.255.255.1 -j MARK --set-mark 0x2
/sbin/iptables -t nat -A POSTROUTING -o ppp0 -j MASQUERADE
/sbin/iptables -t nat -A POSTROUTING -o ppp1 -j MASQUERADE
至此,双adsl链路的热互备及负载分担基本完成。
关键词阅读:
1(共条评论)
2(共条评论)
3(共条评论)
4(共条评论)
5(共条评论)
降低上网资费迫在眉睫 企业应关注民心所向
日前,锐捷网络政府和交通行业部总经理肖广...
联系我们:
广告发布:
方案、案例展示:
京ICP000080号 网站-3
&&&&&&&&京公网安备45号查看:2373|回复:7
初级工程师
linux添加永久静态路由,需要添加多条永久静态路由指向内网的一个网关。
试过在/etc/sysconfig/network-scripts/route-eth0下添加,只有192.168.50.132/32 dev eth0这种格式能显示,网上说的其他格式都试过,服务器重启后都是没有显示在路由表中。
Linux版本信息如下:
LSB Version:
:base-4.0-ia32:base-4.0-noarch:core-4.0-ia32:core-4.0-noarch:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-ia32:printing-4.0-noarch
Distributor ID:
Description:
CentOS release 6.4 (Final)
求大神解答,谢谢!
vi&&/etc/sysconfig/static-routes
比如添加这个
any net 192.168.6.0/24 gw 192.168.10.2
初级工程师
引用:原帖由 bianlimit 于
10:23 发表
vi&&/etc/sysconfig/static-routes
比如添加这个
any net 192.168.6.0/24 gw 192.168.10.2 试过了,不行哦!
/etc/rc.local
在这里加上试了没。
Just For Fun
那个static-routes是可以的,我用的也是centos6.4,应该是你配置的内容没写对,你要用route命令临时配置试试看能不能配,能配写了才能用,
初级工程师
引用:原帖由 墨柳空铭 于
13:49 发表
那个static-routes是可以的,我用的也是centos6.4,应该是你配置的内容没写对,你要用route命令临时配置试试看能不能配,能配写了才能用, 我把配置贴上来吧,服务器我已经重启过了。
--------------------------------------------------------------------------
root@ha1:~ # route -n
Kernel IP routing table
Destination& &&&Gateway& && && &Genmask& && && &Flags Metric Ref& & Use Iface
172.28.128.0& & 0.0.0.0& && && &255.255.255.0& &U& &&&0& && &0& && &&&0 eth1
172.16.128.0& & 0.0.0.0& && && &255.255.255.0& &U& &&&0& && &0& && &&&0 eth1
10.15.0.0& && & 0.0.0.0& && && &255.255.255.0& &U& &&&0& && &0& && &&&0 eth0
192.168.0.0& &&&0.0.0.0& && && &255.255.252.0& &U& &&&0& && &0& && &&&0 eth0
169.254.0.0& &&&0.0.0.0& && && &255.255.0.0& &&&U& &&&0& && &0& && &&&0 eth1
0.0.0.0& && && &192.168.1.32& & 0.0.0.0& && && &UG& & 0& && &0& && &&&0 eth0
root@ha1:~ # cat /etc/sysconfig/static-routes
any net 192.168.50.0/24 gw 192.168.1.1.
192.168.60.0/24 via 192.168.1.1
root@ha1:~ # route add -net 192.168.50.0/24 gw 192.168.1.1
root@ha1:~ # route -n
Kernel IP routing table
Destination& &&&Gateway& && && &Genmask& && && &Flags Metric Ref& & Use Iface
172.28.128.0& & 0.0.0.0& && && &255.255.255.0& &U& &&&0& && &0& && &&&0 eth1
172.16.128.0& & 0.0.0.0& && && &255.255.255.0& &U& &&&0& && &0& && &&&0 eth1
192.168.50.0& & 192.168.1.1& &&&255.255.255.0& &UG& & 0& && &0& && &&&0 eth0
10.15.0.0& && & 0.0.0.0& && && &255.255.255.0& &U& &&&0& && &0& && &&&0 eth0
192.168.0.0& &&&0.0.0.0& && && &255.255.252.0& &U& &&&0& && &0& && &&&0 eth0
169.254.0.0& &&&0.0.0.0& && && &255.255.0.0& &&&U& &&&0& && &0& && &&&0 eth1
0.0.0.0& && && &192.168.1.32& & 0.0.0.0& && && &UG& & 0& && &0& && &&&0 eth0
中级工程师
引用:root@ha1:~ # cat /etc/sysconfig/static-routes
any net 192.168.50.0/24 gw 192.168.1.1.
192.168.60.0/24 via 192.168.1.1192.168.1.1 后面多了一个点
第二行要按照第一行的格式写
路由配置文件正常的路径为/etc/sysconfig/network-scripts/route-IFACE&&(iface表示你的接口名称)操作环系统:CentOS-6.4-X86_64
一:使用 route 命令添加使用route 命令添加的路由,机器重启或者网卡重启后路由就失效了,方法://添加到主机的路由# route add –host 192.168.1.2 dev eth0# route add –host 192.168.1.3 gw 192.168.1.1//添加到网络的路由# route add –net 192.168.1.2 netmask 255.255.255.0 eth0# route add –net 192.168.1.2 netmask 255.255.255.0 gw 192.168.1.1# route add –net 192.168.1.0/24 eth1//添加默认网关# route add default gw 192.168.2.1//删除路由# route del –host 192.168.1.2 dev eth0
二:在linux下设置永久路由的方法:1.在/etc/rc.local里添加方法: route add -net 192.168.1.0/24 dev eth0route add -net 192.168.2.0/24 gw 192.168.2.254
2.在/etc/sysconfig/network里添加到末尾方法:GATEWAY=gw-ip 或者 GATEWAY=gw-dev
3./etc/sysconfig/static-routes : any net 192.168.1.0/24 gw 192.168.1.254any net 192.168.2.2 netmask 255.255.255.0 gw 192.168.2.1
如果在rc.local中添加路由会造成NFS无法自动挂载问题,所以使用static-routes的方法是最好的。无论重启系统和service network restart 都会生效
阅读(...) 评论()

我要回帖

更多关于 添加静态路由命令 的文章

 

随机推荐