IDC双网卡(一个有线,一个无线)访问内外网

电脑里的路由区分:

Persistent Routes:静态路由(永久路由);

Active Routes: 激活路由

 

Metric:metric后面的数字20为优先级。

 

1 route add 0.0.0.0 mask 0.0.0.0 192.168.250.1 metric 20  #增加Active Routes
2 
3 route -p add 192.168.0.0 mask 255.255.0.0 192.168.250.120 metric 1  #增加Persistent Routes

route print  #打印现有路由表

route -f 0.0.0.0 #删除所有路由表

route delete 192.168.0.0  #删除指定路由

修改后的路由表:

 1 C:\Documents and Settings\Administrator>route print
 2 ===========================================================================
 3 Interface List
 4 0x1 ........................... MS TCP Loopback interface
 5 0x2 ...20 6a 8a 69 00 bc ...... Broadcom NetLink (TM) Gigabit Ethernet - 数据包
 6 计划程序微型端口
 7 0x20004 ...e4 d5 3d b5 12 f2 ...... Atheros AR5B97 Wireless Network Adapter -
 8 据包计划程序微型端口
 9 ===========================================================================
10 ===========================================================================
11 Active Routes:
12 Network Destination        Netmask          Gateway       Interface  Metric
13           0.0.0.0          0.0.0.0    192.168.250.1  192.168.250.120      20
14         127.0.0.0        255.0.0.0        127.0.0.1       127.0.0.1       1
15         172.0.0.0        255.0.0.0  192.168.250.120  192.168.250.120      1
16       192.168.0.0      255.255.0.0  192.168.250.120  192.168.250.120      1
17      192.168.11.0    255.255.255.0   192.168.11.141  192.168.11.141       20
18    192.168.11.141  255.255.255.255        127.0.0.1       127.0.0.1       20
19    192.168.11.255  255.255.255.255   192.168.11.141  192.168.11.141       20
20     192.168.250.0  255.255.255.128  192.168.250.120  192.168.250.120      20
21   192.168.250.120  255.255.255.255        127.0.0.1       127.0.0.1       20
22   192.168.250.255  255.255.255.255  192.168.250.120  192.168.250.120      20
23         224.0.0.0        240.0.0.0   192.168.11.141  192.168.11.141       20
24         224.0.0.0        240.0.0.0  192.168.250.120  192.168.250.120      20
25   255.255.255.255  255.255.255.255   192.168.11.141  192.168.11.141       1
26   255.255.255.255  255.255.255.255  192.168.250.120  192.168.250.120      1
27 Default Gateway:     192.168.250.1
28 ===========================================================================
29 Persistent Routes:
30   Network Address          Netmask  Gateway Address  Metric
31         172.0.0.0        255.0.0.0  192.168.250.120       1
32       192.168.0.0      255.255.0.0  192.168.250.120       1

 192.168.11.141是我的内网IP,掩码:255.255.255.0,网关:192.168.11.1

 192.168.250.120为我的外网IP,掩码:255.255.255.128,网关:192.168.250.1,DNS:202.96.209.133

 我要访问一个内网IP,不能让此IP转到外网去。方法如下:

1 route add 192.168.22.26 mask 255.255.255.255 192.168.11.1 metric 30

 修改后的路由表:

C:\Documents and Settings\Administrator>route print
===========================================================================
Interface List
0x1 ........................... MS TCP Loopback interface
0x2 ...20 6a 8a 69 00 bc ...... Broadcom NetLink (TM) Gigabit Ethernet - 数据
计划程序微型端口
0x20004 ...e4 d5 3d b5 12 f2 ...... Atheros AR5B97 Wireless Network Adapter
据包计划程序微型端口
===========================================================================
===========================================================================
Active Routes:
Network Destination        Netmask          Gateway       Interface  Metric
          0.0.0.0          0.0.0.0    192.168.250.1  192.168.250.120      20
        127.0.0.0        255.0.0.0        127.0.0.1       127.0.0.1       1
        172.0.0.0        255.0.0.0  192.168.250.120  192.168.250.120      1
      192.168.0.0      255.255.0.0  192.168.250.120  192.168.250.120      1
     192.168.11.0    255.255.255.0   192.168.11.141  192.168.11.141       20
   192.168.11.141  255.255.255.255        127.0.0.1       127.0.0.1       20
   192.168.11.255  255.255.255.255   192.168.11.141  192.168.11.141       20
    192.168.22.26  255.255.255.255     192.168.11.1  192.168.11.141       30
    192.168.250.0  255.255.255.128  192.168.250.120  192.168.250.120      20
  192.168.250.120  255.255.255.255        127.0.0.1       127.0.0.1       20
  192.168.250.255  255.255.255.255  192.168.250.120  192.168.250.120      20
        224.0.0.0        240.0.0.0   192.168.11.141  192.168.11.141       20
        224.0.0.0        240.0.0.0  192.168.250.120  192.168.250.120      20
  255.255.255.255  255.255.255.255   192.168.11.141  192.168.11.141       1
  255.255.255.255  255.255.255.255  192.168.250.120  192.168.250.120      1
Default Gateway:     192.168.250.1
===========================================================================
Persistent Routes:
  Network Address          Netmask  Gateway Address  Metric
        172.0.0.0        255.0.0.0  192.168.250.120       1
      192.168.0.0      255.255.0.0  192.168.250.120       1

 

以上注释是我按照我的理解写的,可能不对。

 

附带:windows下route命令用法:

1.在windows中, 可以使用route 命令来更改默认网关

route add [-p] 0.0.0.0. mask 0.0.0.0 10.112.76.232

  2.介绍route语法,及其使用实例:

 语法:
route [-f] [-p] [Command[Destination] [mask Network] [Gateway] [metric Metric]] [if Interface]]

-p : persistent  持久稳固的

例子:

显示IP路由:

route print

显示路由表中10开头的:

route print 10.* 

添加192.168.12.1为默认网关的路由:

route add 0.0.0.0 mask 0.0.0.0 192.168.12.1 

添加路由: 目的为:10.41.0.0  子网:255.255.0.0  下一跳为:10.27.0.1

route add 10.41.0.0 mask 255.255.0.0 10.27.0.1 

添加永久路由

route -p add 10.41.0.0 mask 255.255.0.0 10.27.0.1 

route add 10.41.0.0 mask 255.255.0.0 10.27.0.1 metric 7 

route add 10.41.0.0 mask 255.255.0.0 10.27.0.1 if 0×3 

删除路由:

route delete 10.41.0.0 mask 255.255.0.0

删除所有以10开头的路由

route delete 10.* 

将(10.41.0.0 mask 255.255.0.0)的路由改为10.27.0.25:

route change 10.41.0.0 mask 255.255.0.0 10.27.0.25

 linux下route的用法(http://linux008.blog.51cto.com/2837805/550596):

 

说明:route命令是打印和操作ip路由表
描述:route操作基于内核ip路由表,它的主要作用是创建一个静态路由让指定一个主 机或者一个网络通过一个网络接口,如eth0。当使用"add"或者"del"参数时,路由表被修改,如果没有参数,则显示路由表当前的内容。
参数说明:add:添加一条新路由。
          del:删除一条路由。
          -net:目标地址是一个网络。
          -host:目标地址是一个主机。
          netmask:当添加一个网络路由时,需要使用网络掩码。
          gw:路由数据包通过网关。注意,你指定的网关必须能够达到。
          metric:设置路由跳数。
实例:
      1、route add -net 192.168.2.0 netmask 255.255.255.0 dev eth0
         添加一条到达192.168.2.0网络的路由,指定网络掩码为255.255.255.0,数据包通过网络接口eth0。
      2、route add -net 192.57.66.0 netmask 255.255.255.0 gw 192.168.2.1
         添加一条到达192.57.66.0网络的路由,指定网络掩码为255.255.255.0,数据包通过网关地址192.168.2.1。
      3、route add -host 192.57.66.200 gw 192.168.2.1
         所有去往192.57.66.200主机的数据包发往网关地址192.168.2.1。
      4、route add default gw 192.168.1.1
         添加一条默认网关,所有的数据包将被转发到192.168.1.1。
路由表内容说明:
查看路由
# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.57.66.200   192.168.1.1     255.255.255.255 UGH   0      0        0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0
169.254.0.0     0.0.0.0         255.255.0.0     U     0      0        0 eth0
0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 eth0
Destination:目标网络或主机。
Gateway:网关地址。
Genmask:目标网络的网络掩码。"255.255.255.255"表示一个主机。"0.0.0.0"表示网关。
Flags:标记。
       U、路由被启用。
       H、目标是一个主机
       G、使用网关。

转载于:https://www.cnblogs.com/jevan/archive/2012/10/26/2740871.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值