Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iptables - remove packet mark on certain packets

Tags:

iptables

I am using the following iptables script to redirect packets on port 443 to a proxy server:

iptables -t mangle -A PREROUTING -p tcp --dport 443 -j MARK --set-mark 2

I am redirecting it to my proxy server later on, which is working. For one host, however, I need to remove the iptables mark (i.e. the packets will not be redirected.) I tried the following:

iptables -t mangle -A PREROUTING -p tcp -s 192.168.0.47 --dport 443 -j ACCEPT

I have also tried (attempting to rewrite the mark to a different number):

iptables -t mangle -A PREROUTING -p tcp -s 192.168.0.47 --dport 443 -j MARK --set-mark 1

However none of them are working. Is there a --remove-mark? I couldn't find anything on Google.

Any help would be appreciated.

like image 903
Ethan H Avatar asked Jan 13 '23 04:01

Ethan H


1 Answers

When using the MARK target, the mark is a added as a bitmask. If you check in the documentation, there's an optional [/mask] for the mark.

So use "--set-mark 0/2" to remove 2.

like image 127
Preston Crow Avatar answered Apr 28 '23 20:04

Preston Crow