下一页 上一页 目录

4. 测试你的新桥接环境!

4.1 测试场地

我们设想以下或类似场景

                                                          /\
          Ethernet           Ethernet           ATM    /-/  \
---------          ---------          ---------     /-/      |
|  Box  |----------|Bridge |----------|Router |-----| Inter-  \
---------          ---------          ---------     \  net  ---|
         ^        ^         ^        ^               \     /
         |        |         |        |                \---/
        eth0     eth0      eth1     if0                 ^
         |        |         |        |                  |
      10.0.3.2   none/10.0.3.1      195.137.15.7    anything else
                  \         /
                   \       /
   ^                \-br0-/
   |                                      ^             ^
   |                   ^                  |             |
   |                   |                  |             |
  own                 own              foreign        hostile
        
我们的管理权限仅包括标记为 own 的机器,路由器完全禁止访问,当然互联网也是如此。
这意味着,如果我们想控制以太网线上的飞速比特流,我们可以选择集成一个通用的防火墙或文件到桥接中。
标准方法的缺点是,你必须更改网络中每个主机的默认网关路由。这真是一个严重的缺点,没有人愿意在 5 个不同的主机上更改超过 5 个默认路由,而且不止一次。记住时间成本,这也会消耗时间!别忘了,这是一种容易出错的安全处理方式。
另一种方法更简洁、更省时、更安全且不易出错。更安全是因为我们不需要分配任何 IP 地址。没有 IP,就没有危险。到目前为止,这是理论,我们希望我们的协议栈是安全的。(尽管这种希望最好不要依赖...)总的优势是,这种桥接设置是完全透明的,根本不需要更改 IP、MAC 等。
所以这取决于你选择你喜欢的方法。但我们将只处理这里这个更高级的方法 ;-)

4.2 Ping 它,吉姆!

我们将像往常一样配置 Box 的 eth0。桥接器的接口配置在设置中描述。
如果我们要使用转发,我们也许可以这样做:;-)

root@bridge:~> echo "1" > /proc/sys/net/ipv4/ip_forward
        
可选地,我们设置一个默认路由
root@bridge:~> route add default gw 10.0.3.129
        
然后我们在主机 bridge 上设置一些 iptables 规则:
root@bridge:~> iptables -P FORWARD DROP
root@bridge:~> iptables -F FORWARD
root@bridge:~> iptables -I FORWARD -j ACCEPT
root@bridge:~> iptables -I FORWARD -j LOG
root@bridge:~> iptables -I FORWARD -j DROP
root@bridge:~> iptables -A FORWARD -j DROP
root@bridge:~> iptables -x -v --line-numbers -L FORWARD
        
最后一行给我们以下输出
Chain FORWARD (policy DROP 0 packets, 0 bytes)
num      pkts      bytes target   prot opt in     out     source   destination
1           0        0 DROP       all  --  any    any     anywhere anywhere
2           0        0 LOG        all  --  any    any     anywhere anywhere      LOG level warning
3           0        0 ACCEPT     all  --  any    any     anywhere anywhere
4           0        0 DROP       all  --  any    any     anywhere anywhere
        
LOG 目标通过 syslogd 记录每个数据包。注意,这仅用于测试目的,在生产环境中移除。否则,最终你会用你自己的日志或任何其他人对你进行拒绝服务攻击来填满日志和硬盘分区。你已被警告。
现在测试这个规则集。在主机 box 上 ping 路由器接口的 IP (195.137.15.7)
root@box:~> ping -c 3 195.137.15.7
PING router.provider.net (195.137.15.7) from 10.0.3.2 : 56(84) bytes of data.
--- router.provider.net ping statistics ---
3 packets transmitted, 0 received, 100% loss, time 2020ms
^C
root@box:~> 
        
默认情况下,我们 DROP 所有东西。没有响应,没有记录的数据包。此 netfilter 设置旨在 DROP 所有数据包,除非我们在 LOG 目标匹配之前删除丢弃每个数据包的规则(上面的规则 1)
root@bridge:~> iptables -D FORWARD 1
root@bridge:~> iptables -x -v --line-numbers -L FORWARD
        
现在,规则是
Chain FORWARD (policy DROP 0 packets, 0 bytes)
num      pkts      bytes target   prot opt in     out     source   destination
2           0        0 LOG        all  --  any    any     anywhere anywhere      LOG level warning
3           0        0 ACCEPT     all  --  any    any     anywhere anywhere
4           0        0 DROP       all  --  any    any     anywhere anywhere
        
任何数据包都可能通过。在主机 box 上用 ping 测试它
root@box:~> ping -c 3 195.137.15.7
PING router.provider.net (195.137.15.7) from 10.0.3.2 : 56(84) bytes of data.
64 bytes from router.provider.net (195.137.15.7): icmp_seq=1 ttl=255 time=0.103 ms
64 bytes from router.provider.net (195.137.15.7): icmp_seq=2 ttl=255 time=0.082 ms
64 bytes from router.provider.net (195.137.15.7): icmp_seq=3 ttl=255 time=0.083 ms

--- router.provider.net ping statistics ---
3 packets transmitted, 3 received, 0% loss, time 2002ms
rtt min/avg/max/mdev = 0.082/0.089/0.103/0.012 ms
root@box:~> 
        
耶!路由器已启动、运行并正常工作。(好吧,它已经整天如此了... ;-))

重要提示

当我们刚刚启动桥接接口时,桥接器大约需要 30 秒才能完全运行。这是由于桥接接口的 30 秒学习阶段。在此阶段,桥接端口正在学习哪些 MAC 地址存在于哪个端口上。桥接器的作者 Lennert 在他的 TODO 文件中告诉我们,30 秒的学习阶段将在某个时候及时进行一些改进。
在测试阶段,不会转发任何数据包。没有 ping 会被应答。记住这一点!

4.3 实际配置

本节旨在为您,亲爱的读者,提供一些关于在成功处理完本 HOWTO 后,您的系统应该是什么样子和感觉的提示。

接口配置

你的 ifconfig 命令的输出可能看起来类似于这样

root@bridge:~> ifconfig
br0       Link encap:Ethernet  HWaddr 00:04:75:81:D2:1D
          inet addr:10.0.3.129  Bcast:195.30.198.255  Mask:255.255.255.128
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:826 errors:0 dropped:0 overruns:0 frame:0
          TX packets:737 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:161180 (157.4 Kb)  TX bytes:66708 (65.1 Kb)

eth0      Link encap:Ethernet  HWaddr 00:04:75:81:ED:B7
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:5729 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3115 errors:0 dropped:0 overruns:0 carrier:656
          collisions:0 txqueuelen:100
          RX bytes:1922290 (1.8 Mb)  TX bytes:298837 (291.8 Kb)
          Interrupt:11 Base address:0xe400

eth1      Link encap:Ethernet  HWaddr 00:04:75:81:D2:1D
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:1 frame:0
          TX packets:243 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:100
          RX bytes:342 (342.0 b)  TX bytes:48379 (47.2 Kb)
          Interrupt:7 Base address:0xe800

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:1034 errors:0 dropped:0 overruns:0 frame:0
          TX packets:1034 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:82068 (80.1 Kb)  TX bytes:82068 (80.1 Kb)
        

路由配置

你的 route 命令的输出可能看起来类似于这样

root@bridge:~> route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
10.0.3.129      0.0.0.0         255.255.255.128 U     0      0        0 br0
0.0.0.0         10.0.3.129      0.0.0.0         UG    0      0        0 br0
root@bridge:~>
        

Iptables 配置

请查看 Ping 它,吉姆! 部分。

4.4 最终说明(重要!)

我想听到你的声音! :-)
你享受这次旅程了吗?
你错过了什么吗?
需要帮助吗?(呼叫你当地的助手 ;-) 或 rtfm。)
你还在在线吗?然后通过电子邮件给我留言。我会非常高兴。
想给我寄支票吗?可惜,不接受这些...(开玩笑的 😉)
让它值得我付出时间,只需给我一些好评,那就足够了。
没有什么比快乐的参与者给你有价值的反馈更具激励性了。
所以,继续,花一分钟时间给我发邮件吧!
谢谢!

Nils
        

4.5 Bug 记录

显然,br-nf 代码中一定存在一个 bug

From: Bart De Schuymer <bart.de.schuymer_@_pandora.be>
Date: Sun, 1 Sep 2002 21:52:46 +0200
To: Nils Radtke <Nils.Radtke_@_Think-Future.de>
Subject: Re: Ethernet-Brigde-netfilter-HOWTO

Hello Nils,

[...]
Also, network packet filtering debugging is generally a bad idea with the
br-nf patch. It can gives a lot of false warnings (about bugs) in the logs.
[...]
        

就我个人而言,我的日志中从未出现过误报。也许,这个 bug 已经被修复了。这封邮件发给了 Bart,他写道

From: Bart De Schuymer <bart.de.schuymer_@_pandora.be>
Date: Mon, 2 Sep 2002 18:30:25 +0200
To: Nils Radtke <Nils.Radtke_@_Think-Future.de>
Subject: Re: Ethernet-Brigde-netfilter-HOWTO

On Monday 02 September 2002 00:39, Nils Radtke wrote:
> Will the revision of the nf-debug code in br-nf be subject of improvement?

I must admit I haven't been running any kernel with netfilter debugging
lately. It sure used to give false positives a few months ago (the bridge
mailing list has posts about that), I've been lacking time to see why and if
it is still the case. It's on my todo list.
[...]
        
但是(截至 2002-09-19 撰写本文时),我还没有找到关于这个特定 bug 已被关闭的官方公告。因此,如果您对其修复方法感兴趣,请持续关注 以太网桥邮件列表 上的这个主题。


下一页 上一页 目录