Necesita ayuda con este objetivo:
Internet
<-- TP_LINK Router(192.168.0.1)
<-- PC1(eth0:192.168.0.8)
<-- PC2(eth0:192.168.0.81)
Cuando uso un cable para conectar PC2 eth1 a PC3 eth0 y configuro los ajustes IPV4 de PC2 eth1 para "compartir con otras computadoras", entonces PC2 y PC3 obtienen las siguientes IP:
PC2(eth1:10.42.0.1)
<-- PC3(eth0: 10.42.0.169)
Ahora quiero hacer algo en ruta o iptables para poder hacer "ping a 10.42.0.169" en la PC1.
es posible? A continuación se muestra lo que he probado:
- Configure la tabla de rutas estáticas del enrutador TP_LINK: 10.42.0.0 (destino) - 255.255.255.0 (máscara de red) - 192.168.0.81 (puerta de enlace).
Ahora obtengo el resultado en la PC1:
$ traceroute 10.42.0.169
traceroute to 10.42.0.169 (10.42.0.169), 64 hops max, 52 byte packets
1 192.168.0.1 (192.168.0.1) 4.018 ms 0.905 ms 0.768 ms
2 ay11 (192.168.0.81) 1.140 ms 1.273 ms 1.482 ms
3 ay11 (192.168.0.81) 1.104 ms 1.041 ms 1.127 ms
Podemos ver que si la PC2 puede reenviar paquetes a 10.42.0.0/24, ¿tal vez todo será perfecto?
Aquí están las configuraciones en PC2:
$ route
default 192.168.0.1 0.0.0.0 UG 100 0 0 eth1
10.42.0.0 * 255.255.255.0 U 100 0 0 eth0
link-local * 255.255.0.0 U 1000 0 0 eth1
192.168.0.1 * 255.255.255.255 UH 100 0 0 eth1
$ sudo iptables -L
[sudo] password for mlhch:
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT udp -- anywhere anywhere udp dpt:bootps
ACCEPT tcp -- anywhere anywhere tcp dpt:bootps
ACCEPT udp -- anywhere anywhere udp dpt:domain
ACCEPT tcp -- anywhere anywhere tcp dpt:domain
Chain FORWARD (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere 10.42.0.0/24 state RELATED,ESTABLISHED
ACCEPT all -- 10.42.0.0/24 anywhere
ACCEPT all -- anywhere anywhere
REJECT all -- anywhere anywhere reject-with icmp-port-unreachable
REJECT all -- anywhere anywhere reject-with icmp-port-unreachable
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
¿Qué debo hacer con route o iptables?
¡Gracias!
Respuesta1
Pruebe esto para configurarlo. PC2
Lo primero que debe hacer es habilitar el reenvío de IP. Esto se hace ya sea usando
echo "1" > /proc/sys/net/ipv4/ip_forward
Luego, agregaremos una regla que indique reenviar el tráfico.
sudo iptables -A FORWARD -i eth1 -o eth0 -j ACCEPT
sudo iptables -A FORWARD -i eth0 -o eth1 -m state --state ESTABLISHED,RELATED -j ACCEPT
Respuesta2
Gracias por tus esfuerzos.
Para /proc/sys/net/ipv4/ip_forward, ya era "1" y había configurado net.ipv4.ip_forward=1 en /etc/sysctl.conf
Ejecuté sus comandos de iptables, simplemente agregan debajo de 2 líneas en la sección Cadena ADELANTE:
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
Entonces no ocurre ningún milagro. Pero eso me hace notar las 2 líneas de RECHAZO
REJECT all -- anywhere anywhere reject-with icmp-port-unreachable
REJECT all -- anywhere anywhere reject-with icmp-port-unreachable
¡Los elimino y todo funciona perfectamente! De hecho, también elimino las líneas recién agregadas y solo conservo 1 línea "ACEPTAR todo, en cualquier lugar".