There is a good deep dive but not too difficult to understand tutorial on iptables here. The mangle table is used to alter the IP headers of the packet in various ways. For instance, you can adjust the TTL (Time to Live) value of a packet, either lengthening or shortening the number of valid network hops the packet can sustain.
iptables -t mangle -A PREROUTING -i eth0 -j TTL --ttl-dec 1: Explanation: The --ttl-dec option tells the TTL target to decrement the Time To Live value by the amount specified after the --ttl-dec option. In other words, if the TTL for an incoming packet was 53 and we had set --ttl-dec 3, the packet would leave our host with a TTL value of 49. iptables Policies and Rules. Policies are the default actions applied to packets that do not match any rules. There are three built-in tables: filter, NAT, and mangle. You will use the filter table the most, the NAT table a little, and the mangle table perhaps not at all (it is for advanced packet manipulation). Feb 14, 2011 · [SOLVED] iptables mangle + specific route works for icmp but not for service: Neck: Linux - Networking: 6: 03-29-2010 07:59 AM: Mangle ip source with iptables: spank: Linux - Networking: 1: 02-02-2008 12:34 AM: Mangle Table: santhosh23: Linux - General: 2: 06-24-2007 08:52 PM: iptables mangle problem: posixjunkie: Linux - Networking: 1: 04-25 May 22, 2018 · sudo iptables -I chain [rule-number] firewall-rule To view rules: sudo iptables -t filter -L chain --line-numbers -n -v Where,-I: Insert rule at given rule number-t: Specifies the packet matching table such as nat, filter, security, mangle, and raw.-L: List info for specific chain (such as INPUT/FORWARD/OUTPUT) of given packet matching table Running iptables -vL confirms that the packets are getting matched by the marking rule, but they don't appear to be following the routing rule. EDIT: I've spent a long time on this, and although it still doesn't work, I think I'm a bit closer. The iptables rule has to be in the mangle table's OUTPUT chain.
-j MARK: Only valid in mangle table. Note that the mark value is not set within the actual package, but is a value that is associated within the kernel with the packet. In other words does not make it out of the machine iptables -t mangle -A PREROUTING -p tcp --dport 22 -j MARK --set-mark 2
Mangle: It is related with router flags of special packets. The simple version of flow chart of iptables: (It has been simplified by eliminating the mangle table.) The complete version of the flow chart of the iptables.
Jul 21, 2020 · iptables is used to set up, maintain, and inspect the tables of IP packet filter rules in the Linux kernel. This module does not handle the saving and/or loading of rules, but rather only manipulates the current rules that are present in memory. This is the same as the behaviour of the iptables and ip6tables command which this module uses
The following targets are only valid in the mangle table. They can not be used outside the mangle table. TOS. TTL. MARK. The TOS target is used to set and/or change the Type of Service field in the packet. This could be used for setting up policies on the network regarding how a packet should be routed and so on.