Iptables MARK during traffic control by linux Bridge

Source: Internet
Author: User
The MARK of iptables used for traffic control by linux bridge-Linux Enterprise Application-Linux server application information. For details, refer to the following section. Environment:
MagicLinux2.0 kernel: 2.6.15.3
Iptables version: iptables v1.3.7
Bridge: bridge-utils-1.2
Route-V: route 1.98
Patch layer7 for Kernel

Eth1: Internet eth2: Intranet

Configure the bridge:

Brctl addbr br0
Brctl addif br0 eth1
Brctl addif br0 eth2
Ifconfig eth1 0.0.0.0
Ifconfig eth2 0.0.0.0
Ifconfig br0 0.0.0.0

Queue to the Internet:


Tc qdisc add dev eth1 root handle 1: htb default 20

Tc class add dev eth1 parent 1: classid htb rate 100 mbit burst 1 k

Tc class add dev eth1 parent classid htb rate 100 kbit burst 1 k

Tc class add dev eth1 parent classid htb rate 100 mbit burst 1 k

Tc qdisc add dev eth1 parent :10 handle 10: sfq perturb 10
Tc qdisc add dev eth1 parent :20 handle 20: sfq perturb 10
Tc filter add dev eth1 protocol ip parent 1:0 prio 8 handle 11 fw flowid

Queue to the Intranet:

Tc qdisc add dev eth2 root handle 1: htb default 40

Tc class add dev eth2 parent 1: classid htb rate 100 mbit burst 100 m

Tc class add dev eth2 parent classid htb rate 100 kbit burst 1 k

Tc class add dev eth2 parent classid htb rate 100 mbit burst 1 k

Tc qdisc add dev eth2 parent :30 handle 30: sfq perturb 10
Tc qdisc add dev eth2 parent :40 handle 40: sfq perturb 10
Tc filter add dev eth2 protocol ip parent 1:0 prio 8 handle 22 fw flowid

Iptables configuration:

Iptables-t mangle-F
Iptables-t mangle-a prerouting-I eth2-s 90.0.11.66/32-j MARK -- set-mark 11
Iptables-t mangle-a prerouting-I eth2-s 90.0.11.66/32-j RETURN

Iptables-t mangle-a prerouting-I eth1-d 90.0.11.66/32-j MARK -- set-mark 22
Iptables-t mangle-a prerouting-I eth1-d 90.0.11.66/32-j RETURN

(For the address 90.0.11.66, the speed limit is 100 kbit. Here we test the effect. It is intended to use layer7 for p2p Traffic Control .)

The test showed that the speed was not changed. To find the problem, I tried it with u32:


Tc qdisc add dev eth1 root handle 1: htb default 20

Tc class add dev eth1 parent 1: classid htb rate 100 mbit burst 1 k

Tc class add dev eth1 parent classid htb rate 100 kbit burst 1 k

Tc class add dev eth1 parent classid htb rate 100 mbit burst 1 k

Tc qdisc add dev eth1 parent :10 handle 10: sfq perturb 10
Tc qdisc add dev eth1 parent :20 handle 20: sfq perturb 10
Tc filter add dev eth1 protocol ip parent 1:0 prio 8 u32 match ip src 90.0.11.66/32 flowid :10



Tc qdisc add dev eth2 root handle 1: htb default 40

Tc class add dev eth2 parent 1: classid htb rate 100 mbit burst 100 m

Tc class add dev eth2 parent classid htb rate 100 kbit burst 1 k

Tc class add dev eth2 parent classid htb rate 100 mbit burst 99 m

Tc qdisc add dev eth2 parent :30 handle 30: sfq perturb 10
Tc qdisc add dev eth2 parent :40 handle 40: sfq perturb 10

Tc filter add dev eth2 protocol ip parent 1:0 prio 8 u32 match ip dst 90.0.11.66/32 flowid :30

The test results are very good. Later, I suspected it was a bridge problem. I removed the bridge and implemented nat. The internal network was 192.168.1.0 and the external network was 90.0.11.0. The test is still the same. You can use u32, but the mark with iptables won't work. You can't explain it.

Later, I tried using the cbq queue, but I still cannot.

Tc qdisc add dev eth1 root handle 1: cbq bandwidth 100 mbit avpkt 1000 cell 8

Tc class add dev eth1 parent 1: classid 1:1 cbq bandwidth 100 mbit rate 100 mbit maxburst 20 allot 1514 avpkt 1000 cell 8 weight 1 mbit

Tc class add dev eth1 parent 1: classid cbq bandwidth 100 mbit rate 100 kbit maxburst 20 allot 1514 avpkt 1000 cell 8 weight 1 mbit

Tc class add dev eth1 parent 1: classid cbq bandwidth 100 mbit rate 100 mbit maxburst 20 allot 1514 avpkt 1000 cell 8 weight 1 mbit


Tc filter add dev eth1 protocol ip parent 1:0 prio 8 handle 11 fw flowid
Tc filter add dev eth1 protocol ip parent 1:0 prio 4 handle 22 fw flowid

Iptables-t mangle-F
Iptables-t mangle-a prerouting-I eth2-s 192.168.1.6/32-j MARK -- set-mark 11
Iptables-t mangle-a prerouting-I eth2-s 192.168.1.6/32-j RETURN
Iptables-t mangle-a prerouting-I eth2-j MARK -- set-mark 22


Tc qdisc add dev eth2 root handle 1: cbq bandwidth 100 mbit avpkt 1000 cell 8

Tc class add dev eth2 parent 1: classid 1:1 cbq bandwidth 100 mbit rate 100 mbit maxburst 20 allot 1514 avpkt 1000 cell 8 weight 1 mbit

Tc class add dev eth2 parent classid cbq bandwidth 100 mbit rate 100 kbit maxburst 20 allot 1514 avpkt 1000 cell 8 weight 1 mbit

Tc class add dev eth2 parent classid cbq bandwidth 100 mbit rate 100 mbit maxburst 20 allot 1514 avpkt 1000 cell 8 weight 1 mbit


Tc filter add dev eth2 protocol ip parent 1:0 prio 8 handle 33 fw flowid
Tc filter add dev eth2 protocol ip parent 1:0 prio 4 handle 44 fw flowid

Iptables-t mangle-a prerouting-I eth1-d 192.168.1.6/32-j MARK -- set-mark 33
Iptables-t mangle-a prerouting-I eth1-d 192.168.1.6/32-j RETURN
Iptables-t mangle-a prerouting-I eth1-j MARK -- set-mark 44

In this case, the problem should be on mark. Module I loaded: lsmod | grep ip
Ipt_layer7 10668 0
Ipt_MARK 1536 4
Ipt_MASQUERADE 2048 1
Iptable_nat 5764 1
Ipt_ippeer-to-Peer 6784 0
Ip_nat_ftp 2176 0
Ip_nat 12460 3 ipt_MASQUERADE, iptable_nat, ip_nat_ftp
Ip_conntrack_ftp 5616 1 ip_nat_ftp
Ip_conntrack 34508 5 ipt_MASQUERADE, iptable_nat, ip_nat_ftp, ip_nat, ip_conntrack_ftp
Nfnetlink 3864 2 ip_nat, ip_conntrack
Iptable_filter 1664 0
Iptable_mangle 1792 1
Ip_tables 16000 7 ipt_layer7, ipt_MARK, ipt_MASQUERADE, iptable_nat, ipt_ipp2p, iptable_filter, iptable_mangle

I don't know whether the patch is missing or iptables. The iptables version of MagicLinux2.0 is 1.3.6, which is compiled by myself.

What are you saying, brothers and sisters ?? : Time: 1: time: 1: time: 1: time: 1: time: 1: time: 1

[ This post was last edited by dreamever]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.