Generally, in order to accomplish this, you will need to do this:
Make sure that host C
will receive the packet, for example by capturing it at the interface using tcpdump or other pcap procedure on the interface.
You have to make sure that the packet will be delivered to host C
. This depends on the link layer used. Assuming you have ethernet and 1 NIC interface per host:
- If you are using Ethernet with a hub or a properly configured switch, then the packed can just be broadcasted to both ports.
- If you are using ethernet switch with MAC table you will have to change the destination MAC address at host
B
or otherwise the switch will not route the packet to C
- in case of Wi-Fi, for example, as it acts as a hub you can just have same MAC addresses and IP addresses on both PCs
- Then, there are two choices: either
- host
B
should receive the packet, and create a duplicate of it, or
- host
B
should just forward the packet to host C
(in this case host C
acting as a default gateway for packet forwarding for host B
, where host B
acting like a router)
As your original question does not assume that the packet would be actually received by host B
but just forwarded to host C
I would do the following on host B
:
- allow packet forwarding
sysctl -w net.ipv4.ip_forward=1
- create a rule to route this packet in a separate table with id 100 for example
ip rule add to 192.168.0.2 lookup 100
- in table with id 100 add the default gateway where the packet should go:
ip route add default via 192.168.0.3 dev ethXXX
where ethXXX
is the interface name of the link to C
this, however, will generate a loop at host B
that will be resolved only by TTL
running out, and will generate excess load on network. This is the simplest way how I would accomplish this.
It would be better to have a properly configured switch, or a separate link to host B->C
to send these packets. In single-interface and non configured switch case you will always result in a loop unless you write a specialized software for this using pcap and you will have to trick the switch anyway by pretending to have the IP address configured.