Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux use interface for raw socket only

I'm having a OpenWrt Linux distribution for my embedded system. The device has 3 network interfaces: eth0, eth1 and wlan0.

One of the network interface (eth0) should be used for raw socket programming only. I'm able to create a socket with the parameters AF_PACKET, SOCK_RAW, ETH_P_ALL. The socket receives all network traffic, I can send packets and everything is OK.

But my problem is, that the OS is also using the interface for sending an reciving (e. g. ARP and ICMP requests/responses).

Is there any option that the interface is only used by my program and not by the OS itself?

like image 760
Benjamin J. Avatar asked Oct 30 '22 05:10

Benjamin J.


1 Answers

This is not possible to achieve with a vanilla kernel. But this can come close:

First, ignore all arp requests on that interface:

echo 8 > /proc/sys/net/ipv4/conf/eth0/arp_ignore

Then, disable IPv6:

echo 1 > /proc/sys/net/ipv6/conf/eth0/disable_ipv6

Finally, filter all IPv4 packets coming on that interface

iptables -I INPUT -i eth0 -j DROP

And do not set an IP-address or routes on that interface. This is of course not perfect, certain packets will still be processed by the kernel, but I don't think there is a much better solution.

like image 104
Ctx Avatar answered Nov 15 '22 05:11

Ctx