Friday, December 19, 2008

How to filter network traffic by MAC address using ipfw

Using ipfw you can filter network traffic by MAC address. For example if you want to block traffic from/to some MAC address you can use the following commands:

ipfw add deny ip from any to any MAC 00:07:E9:AD:E8:26 any
ipfw add deny ip from any to any MAC any 00:07:E9:AD:E8:26

Using these commands we block all traffic for the computer with MAC address 00:07:E9:AD:E8:26.

But this blocking will not work if net.link.ether.ipfw variable is set to 0. So you should also do the following command:

sysctl net.link.ether.ipfw=1