免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: skyajlm
打印 上一主题 下一主题

[网络管理] 急 求教根据端口选路 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2008-06-19 12:45 |只看该作者
原帖由 7717060 于 2008-6-19 12:43 发表
iptables 打标记在用iproute


能不能说详细点

是不是打了标记
在ip route
我是这样做的啊

论坛徽章:
0
12 [报告]
发表于 2008-06-19 13:18 |只看该作者
有没有人有这种的解决方案 不吝赐教啊  急急

论坛徽章:
0
13 [报告]
发表于 2008-06-19 15:12 |只看该作者
用iptables -vnL看过到底有多少被打过签的没?

论坛徽章:
0
14 [报告]
发表于 2008-06-19 15:29 |只看该作者
原帖由 iamshiyu 于 2008-6-19 15:12 发表
用iptables -vnL看过到底有多少被打过签的没?

root$ iptables -t mangle -vnL
Chain FORWARD (policy ACCEPT 171K packets, 104M bytes)
pkts bytes target     prot opt in     out     source               destination         

Chain INPUT (policy ACCEPT 4340 packets, 496K bytes)
pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 2973 packets, 257K bytes)
pkts bytes target     prot opt in     out     source               destination         

Chain POSTROUTING (policy ACCEPT 174K packets, 104M bytes)
pkts bytes target     prot opt in     out     source               destination         

Chain PREROUTING (policy ACCEPT 175K packets, 104M bytes)
pkts bytes target     prot opt in     out     source               destination         
   67 10803 MARK       tcp  --  218.30.60.101        anywhere            tcp dpt:www MARK set 0x1

有打标记的包

论坛徽章:
0
15 [报告]
发表于 2008-06-19 17:56 |只看该作者
特别需要帮助啊 大虾门

论坛徽章:
5
IT运维版块每日发帖之星
日期:2015-08-06 06:20:00IT运维版块每日发帖之星
日期:2015-08-10 06:20:00IT运维版块每日发帖之星
日期:2015-08-23 06:20:00IT运维版块每日发帖之星
日期:2015-08-24 06:20:00IT运维版块每日发帖之星
日期:2015-11-12 06:20:00
16 [报告]
发表于 2008-06-19 18:53 |只看该作者
1、我不知道你测试的结果如何。

2、我需要你的ifconfig -a 我感觉你的IP搞的好混乱。

3、iptables-save

论坛徽章:
0
17 [报告]
发表于 2008-06-20 10:38 |只看该作者
原帖由 ssffzz1 于 2008-6-19 18:53 发表
1、我不知道你测试的结果如何。

2、我需要你的ifconfig -a 我感觉你的IP搞的好混乱。

3、iptables-save



恕我表达不清

再描述一下我的目的  做法   以及测试

有两个外网接口 eth1    222.210.175.228    网关 222.210.175.1
                      eth2     172.160.23.46       网关 172.160.23.1
一个内网接口  eth0  192.168.1.0/24

实现访问特定的ip 特定的端口 比如 218.30.60.101    端口 80走 eth2  其余的访问都通过eth1

ifconfig
eth0      Link encap:Ethernet  HWaddr 00:1B:2A:40:01:27  
          inet addr:192.168.1.1  Bcast:192.168.1.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:129487 errors:0 dropped:0 overruns:0 frame:0
          TX packets:107765 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:256
          RX bytes:117113863 (111.6 MiB)  TX bytes:16527177 (15.7 MiB)


eth1     Link encap:Ethernet  HWaddr 00:1B:2A:40:01:28  
          inet addr:222.210.175.228   Bcast:222.210.175.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:416797 errors:0 dropped:0 overruns:0 frame:0
          TX packets:75171 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100
          RX bytes:25161710 (23.9 MiB)  TX bytes:4520888 (4.3 MiB)
          Interrupt:7 Base address:0xaf00

eth2     Link encap:Ethernet  HWaddr 00:1B:2A:40:01:26  
          inet addr:172.160.23.46  Bcast:172.160.23.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:161946 errors:0 dropped:0 overruns:0 frame:0
          TX packets:339862 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:256
          RX bytes:20811346 (19.8 MiB)  TX bytes:127706208 (121.7 MiB)

lo        Link encap:Local Loopback  
          inet addr:127.0.0.1  Mask:255.0.0.0
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:65 errors:0 dropped:0 overruns:0 frame:0
          TX packets:65 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:5884 (5.7 KiB)  TX bytes:5884 (5.7 KiB)

我的做法是

    建立适合大多数的默认路由
    route add default gw 222.210.175.1 dev eth1

      针对特殊的访问
    iptables 打标记
    iptables -t mangle -A PREROUTING -p tcp --dport 80 -s 218.30.60.101 -j MARK --set-mark 1
      建立特殊规则访问的路由表1
    ip route add table 1 192.168.1.0/24 dev eth0  proto kernel  scope link  src 192.168.1.1
      ip route add table 1 172.160.23.0/24 dev eth2  proto kernel  scope link  src 172.160.23.46  
    ip route add table 1 default gw 172.160.23.1 dev eth2
      ip rule 里设定标记走路由表1
      ip rule add fwmark 1 table 1


      相应的
    ip route list table 1
192.168.1.0/24 dev eth0  proto kernel  scope link  src 192.168.1.1
172.160.23.0/24 dev eth2  proto kernel  scope link  src 172.160.23.46  
default via 172.160.23.1 dev eth2

       ip route
       192.168.1.0/24 dev eth0  proto kernel  scope link  src 192.168.1.1
222.210.175.0/24 dev eth1  proto kernel  scope link  src 222.210.175.228
default via 222.210.175.1 dev eth1

      ip rule
0:      from all lookup local
32765:  from all fwmark       1 lookup 1
32766:  from all lookup main
32767:  from all lookup 253

filter表
      iptables -L
Chain FORWARD (policy DROP)
target     prot opt source               destination              
sysfw      all  --  anywhere             anywhere            state NEW
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED
ACCEPT     all  --  192.168.1.0/24     anywhere            state NEW

Chain INPUT (policy DROP)
target     prot opt source               destination         
sysfw      all  --  anywhere             anywhere            state NEW
re-admin   all  --  anywhere             anywhere            
lo-admin   all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            state RELATED,ESTABLISHED

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain lo-admin (1 references)
target     prot opt source               destination         
ACCEPT     all  --  192.168.1.0/24     anywhere            

Chain p2pfw (0 references)
target     prot opt source               destination         

Chain re-admin (1 references)
target     prot opt source               destination         
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:ssh

Chain sysfw (2 references)
target     prot opt source               destination         
DROP       udp  --  anywhere             anywhere            udp dpts:135:netbios-ssn
DROP       tcp  --  anywhere             anywhere            tcp dpts:135:netbios-ssn
DROP       tcp  --  anywhere             anywhere            tcp dpt:445

nat表
iptables -t nat -L
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination         
MASQUERADE  all  --  192.168.1.0/24     anywhere            

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination

mangle表
iptables -t mangle -L
Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination         

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination               
MARK       tcp  --  218.30.60.101        anywhere            tcp dpt:www MARK set 0x1


以上是三张表的信息


我的测试方法很简单  也没去抓包看从哪个口走的

我直接去访问 218.30.60.101里的网站

我把eth1接外网的线拔掉  根本不能访问   接上就能   也就说根本就没按照我的思想把访问这个网站的包走eth2    而从我上次贴的图看是有包在被打标记的
iptables -t mangle -vnL
Chain FORWARD (policy ACCEPT 171K packets, 104M bytes)
pkts bytes target     prot opt in     out     source               destination         

Chain INPUT (policy ACCEPT 4340 packets, 496K bytes)
pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 2973 packets, 257K bytes)
pkts bytes target     prot opt in     out     source               destination         

Chain POSTROUTING (policy ACCEPT 174K packets, 104M bytes)
pkts bytes target     prot opt in     out     source               destination         

Chain PREROUTING (policy ACCEPT 175K packets, 104M bytes)
pkts bytes target     prot opt in     out     source               destination         
   67 10803 MARK       tcp  --  218.30.60.101        anywhere            tcp dpt:www MARK set 0x1


是不是不能这样做  还是哪有不对的 希望指正

[ 本帖最后由 skyajlm 于 2008-6-20 10:48 编辑 ]

论坛徽章:
5
IT运维版块每日发帖之星
日期:2015-08-06 06:20:00IT运维版块每日发帖之星
日期:2015-08-10 06:20:00IT运维版块每日发帖之星
日期:2015-08-23 06:20:00IT运维版块每日发帖之星
日期:2015-08-24 06:20:00IT运维版块每日发帖之星
日期:2015-11-12 06:20:00
18 [报告]
发表于 2008-06-20 12:56 |只看该作者
你别拔网线。在出接口上抓包看看数据的走向。或者用tracer来追踪一下路由走向看看。

论坛徽章:
0
19 [报告]
发表于 2008-06-20 13:59 |只看该作者
我抓包看过  都是从eth1走的 没按我的要求走  我认真分析过 Linux的高级路由和流量控制HOWTO
其实我的应用应该是和第十一章那个应用差不多  就是不知道问题出在哪里啊

论坛徽章:
0
20 [报告]
发表于 2008-06-20 16:37 |只看该作者
自己在检查中发现了几个问题

我要做的是到目的地址的某个端口的包走eth2

所以我标记的包应该是
iptables -t mangle -A PREROUTING -p tcp --dport 80 -d 218.30.60.101 -j MARK --set-mark 1
而不是
iptables -t mangle -A PREROUTING -p tcp --dport 80 -s 218.30.60.101 -j MARK --set-mark 1

所以在mangle 表中相应的是

mangle表
iptables -t mangle -L
Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination         

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination               
MARK       tcp  --    anywhere        218.30.60.101         tcp dpt:www MARK set 0x1

但是不论源还是目的 只要访问218.30.60.101包都是在增加的

目的为218。30。60。101
iptables -t mangle -nvL
Chain FORWARD (policy ACCEPT 15620 packets, 9856K bytes)
pkts bytes target     prot opt in     out     source               destination         

Chain INPUT (policy ACCEPT 3417 packets, 223K bytes)
pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 3769 packets, 377K bytes)
pkts bytes target     prot opt in     out     source               destination         

Chain POSTROUTING (policy ACCEPT 19388 packets, 10M bytes)
pkts bytes target     prot opt in     out     source               destination         

Chain PREROUTING (policy ACCEPT 19040 packets, 10M bytes)
pkts bytes target     prot opt in     out     source               destination         
   29 7803 MARK       tcp  --                 218.30.60.101        anywhere            tcp dpt:www MARK set 0x1



源为218。

ptables -t mangle -nvL
Chain FORWARD (policy ACCEPT 15620 packets, 9856K bytes)
pkts bytes target     prot opt in     out     source               destination         

Chain INPUT (policy ACCEPT 3417 packets, 223K bytes)
pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 3769 packets, 377K bytes)
pkts bytes target     prot opt in     out     source               destination         

Chain POSTROUTING (policy ACCEPT 19388 packets, 10M bytes)
pkts bytes target     prot opt in     out     source               destination         

Chain PREROUTING (policy ACCEPT 19040 packets, 10M bytes)
pkts bytes target     prot opt in     out     source               destination         
   23 1803 MARK       tcp  --                   anywhere            218.30.60.101     tcp dpt:www MARK set 0x1

这是为什么啊
但不论是源地址 218.30.60.101 还是目的为218.30.60.101是至少是能表明那是我打过标记的包吧  但为什么又不走table 1中的路由

我用
ip rule add to  218.30.60.101     table 1能够使他走eth2走
但是我现在要他根据是不是对218。30。60。101的端口来判断得不是走eth2

一直怀疑是不是方法有问题
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP