Verificar paquetes MARCADOS por iptables

Verificar paquetes MARCADOS por iptables

Estoy marcando paquetes TCP y UDP para enviarlos a dos interfaces diferentes (digamos wlan0 y eth0), lo hice siguiendoesta respuesta.

Asumiendo esta configuración:

eth0 address:  192.168.0.84 

wlan0 address: 192.168.1.22 

Estoy estableciendo las siguientes reglas/rutas:

#!/bin/bash
iptables -A PREROUTING -t mangle -p tcp -j MARK --set-mark 1
echo 201 routeTcp >> /etc/iproute2/rt_tables
ip rule add fwmark 1 table routeTcp
ip route add default via 192.168.0.0 dev eth0 table routeTcp

iptables -A PREROUTING -t mangle -p udp -j MARK --set-mark 2
echo 202 routeUdp >> /etc/iproute2/rt_tables
ip rule add fwmark 2 table routeUdp
ip route add default via 192.168.1.0 dev wlan0 table routeUdp

route -nproducción:

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.0.1     0.0.0.0         UG    0      0        0 eth0
192.168.0.0     0.0.0.0         255.255.255.0   U     1      0        0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U     9      0        0 wlan0

ip route showproducción:

default via 192.168.0.1 dev eth0  proto static 
192.168.0.0/24 dev eth0  proto kernel  scope link  src 192.168.0.84  metric 1 
192.168.1.0/24 dev wlan0  proto kernel  scope link  src 192.168.1.22  metric 9 

ip route show table routeUdp:

default via 192.168.1.1 dev wlan0 

ip route show table routeTcp:

default via 192.168.0.1 dev eth0 

iptables -nL -v --line-numbers -t mangleproducción:

Chain PREROUTING (policy ACCEPT 388K packets, 474M bytes)
num   pkts bytes target     prot opt in     out     source               destination         
1     360K  464M MARK       tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            MARK set 0x1
2    27269   11M MARK       udp  --  *      *       0.0.0.0/0            0.0.0.0/0            MARK set 0x2

Chain INPUT (policy ACCEPT 385K packets, 474M bytes)
num   pkts bytes target     prot opt in     out     source               destination         

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
num   pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 290K packets, 33M bytes)
num   pkts bytes target     prot opt in     out     source               destination         

Chain POSTROUTING (policy ACCEPT 290K packets, 33M bytes)
num   pkts bytes target     prot opt in     out     source               destination  

¿Cómo puedo comprobar que los paquetes se envían realmente a través de la interfaz correcta?

He estado luchando con tcpdump sin éxito.

Gracias chicos.

Respuesta1

Probablemente no lo sean: sus comandos de enrutamiento son incorrectos: usa

   ip route add default via 192.168.0.0 dev eth0 table routeTcp
   ip route add default via 192.168.1.0 dev wlan0 table routeUdp

mientras deberían ser

   ip route add default via 192.168.0.1 dev eth0 table routeTcp
   ip route add default via 192.168.1.1 dev wlan0 table routeUdp

sisus puertas de enlace son 192.168.0.1 y 192.168.1.1, respectivamente; De lo contrario, ajústelo en consecuencia.

En cuanto a comprobar,

     tcpdump -i eth0 -n udp

en una terminal y

     tcpdump -i wlan0 -n tcp

en otra terminal; Ellos deberíanambosdevolverNopaquetes cruzados.

EDITAR:

Lo siento, olvidé que debemos distinguir entre paquetes entrantes y salientes, solo los salientes están segregados. Por favor use

       tcpdump -i wlan0 -n tcp and src host The_IP_ADDRESS_of_Wlan0
       tcpdump -i eth0 -n udp and src host The_IP_ADDRESS_of_eth00

información relacionada