I have an IP range and I want to listen on all IP addresses, assume that is 10.0.0.0/8
Using TPROXY and packet mark I can respond to TCP traffic. This range should be in local table, but I don't want outbound traffic responded locally, so I created another table (say table 10) and added local route in that table.
ip route add local 10.0.0.0/8 dev lo table 10
ip rule add fwmark 1 lookup 10
iptables -t mangle -A PREROUTING -p tcp --dport 80 -d 10.0.0.0/8 -j TPROXY --on-port 80 --on-ip 127.0.0.1 --tproxy-mark 0x1/0x1
Now I need to respond ICMP messages for this range, so I added this iptables rule:
iptables -t mangle -A PREROUTING -p icmp -d 10.0.0.0/8 -j MARK --set-mark 0x1
But after adding this rule machine gets ICMP packets but responds nothing, acting as blackhole
What am I doing wrong?
Update:
I tried sending outbound traffic to this table, but I got connect: Network is unreachable when I ping it and I believe these are related.
Try these commands to reproduce it
ip route add local 10.0.0.0/8 dev lo table 10
ip rule add to 10.0.0.0/8 lookup 10
ping 10.0.0.1