Score:0

How to mark all the packets coming from a device?

ru flag

I create a tun device using ip tuntap add dev tun0 mode tun, then I want to set mark to all the packets coming from tun0 using iptables -t mangle -A OUTPUT -o tun0 -j MARK --set-mark 1. But when I check matched rules using iptables -t mangle -nvL, zero packets were matched. Can somebody help me with this?

Actually I have tried other filters and got nothing. Does this have something to do with tun0 configuration?

Nikita Kipriyanov avatar
za flag
Are you sure any packets were egress to this `tun0` interface?
Score:1
za flag

-o tun0 is an output device filter, so your mangle rule matches packets that leave the system via tun0. To mark packets that are coming in from tun0, use -i tun0, and probably better do it in the PREROUTING chain.

Also notice packet marks don't automatically apply to reply packets; this rule will only ever mark packets of one unidirectional flow (a bidirectional connection has two flows). To mark reply packets use a connection mark module. If you need packet marks, for instance, for policy routing, you can copy connection mark to a packet mark, there is a specific action for that.

Hoping White avatar
ru flag
Thanks a lot. Your answer cleared all my confusion. All the direction-related concepts like INPUT, OUTPUT, PREROUTING, POSTROUTING, are based on the system, not interfaces.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.