edit: I'm a newbie in networking and discovering new things :)
I created a TUN interface programmatically and able to interact with.
I set it up and running by
ifconfig myTun 10.10.1.1/24 up
and its up and running as I can see it in ifconfig
and pinging 10.10.1.1
and to make 100% sure if my TUN interface is up and running with my written problem I did following:
I pinged 10.10.1.2
and the packet is received in my program, I wrote it back to tun then received it again in a loop.
now I am sure all packets FROM or TO 10.10.1.x
are being received by and written to TUN without any problem.
when I write a packet with any destination IP outside the 10.10.1.x
it successfully written to TUN but no answered received to TUN.
after searching and reading lots of article I figured its silently being dropped by the kernel.
I read lots of Q/A about TUN interfaces in serverfault.com and I found out that I've missed a serious part in my Logic which is ROUTING.
my final understanding is:
the packet is OK and received by the network stack in linux, but the kernel doesn't know what to do with the packet because of its weird destination. then I discovered I must specify some routing for the kernel in iptables and enabling net.ipv4.ip_forward
but doesn't know how to.
my final goal is:
when I send any packet with any destination outside 10.10.1.x
to the TUN, it must be routed to my main interface (which has access to internet, and is wlps020f3
) and any result of that packet receive back to my TUN interface
how to configure NAT in iptables to workaround?
thanks in advanced