Linux - Netfilter & iproute - marking packets
Welcome to the tutorial guide. The tutorial guide will provide a user with guidance and instructions on marking packets for Netfilter & iproute.
Please note that Netfilter allows a user to filter packets, or mangle their headers. A special feature is that a user can mark a packet with a number. In order to do this a user can use the –set-mark facility.
A command is provided which can mark all the packets destined for port 25, outgoing mail:
# iptables -A PREROUTING -i eth0 -t mangle -p tcp –dport 25 \
-j MARK –set-mark 1
If a user has multiple connections, one that is fast (and expensive, per megabyte) and one that is slower, but flat fee. It is a good idea that the outgoing mail goes through the cheap route.
A user can see that the packets are marked with a ‘1′. It is now time to instruct the routing policy database to act on this:
# echo 201 mail.out >> /etc/iproute2/rt_tables
# ip rule add fwmark 1 table mail.out
# ip rule ls
0: from all lookup local
32764: from all fwmark 1 lookup mail.out
32766: from all lookup main
32767: from all lookup default
After this a user can generate a route to the slow but cheap link in the mail.out table by running following command:
# /sbin/ip route add default via 195.96.98.253 dev ppp0 table mail.out
Please note that a user can modify the netfilter statement to exclude certain hosts, or he/she can insert a rule with a lower priority that points to the main table for the excepted hosts.
A user can also use this feature to honour TOS bits by marking packets with a different type of service with different numbers, and creating rules to act on that. This way a user can even dedicate, say, an ISDN line to interactive sessions.
A user should be aware that MASQ and SNAT can collide with marking packets. In order to address this issue, it is best to turn off the reverse path filter so that it works properly. If a user wants to mark packets, then he/she should have some of the options enabled in his/her kernel. This is provided below:
IP: advanced router (CONFIG_IP_ADVANCED_ROUTER) [Y/n/?]
IP: policy routing (CONFIG_IP_MULTIPLE_TABLES) [Y/n/?]
IP: use netfilter MARK value as routing key (CONFIG_IP_ROUTE_FWMARK) [Y/n/?]
If you followed this tutorial guide then you would have learnt about marking packets for Netfilter & iproute .













