I am trying to make a C program that will create a tun device interface for my pc physical interface. The entire idea in doing is that when I write any raw packets on my tunnel device, it will put that in my actual physical interface. My question is how do I map the tun device with the actual physical interface?
For example, my eth1 has ip address - 10.16.1.152. How can I create a tun device so that I can read/write on the eth1 interface? Do I need to give the same ip address or a different ip address? Is route only way that I will write packets on tun device and will create a route that will have a default gateway of tun device as a phy device.
I am following this example, but I am unclear on the concept yet.
I have create a tunnel device by the following commands. My PC has got one real ethernet interface. This ethernet interface ip address 10.16.1.152 connected to bunch of PCs and then to the gateway server to access internet.
I am trying to make a C program that will write OSPF hello packets on to the interface.
In order to do so, I am creating a tunnel device so that I can write OSPF hello packets on it. But before I am doing that, I am checking the tunnel device. Here my tunnel device is 126.96.36.199/24 and I am setting the route get 10.16.1.152. My understanding is that all the packets received or sent on the actual interface i.e. 10.16.1.152 will be received by this tunnel device interface, whose IP address is 188.8.131.52. But, when I did a ping to 10.16.1.152, the RX / Tx packets received are still zero. So, I think my tunnel isn't receiving any packets.
ip tuntap add mode tun dev tun0 ip addr add 184.108.40.206/24 dev tun0 ip link set dev tun0 up ip route get 10.16.1.152
Am I missing any concept here? How can I do so? I am still struggling in getting my tunnel device concepts clear.