Linux – How Do I enable port forwarding but only for some IPs and block others

iplinuxnetworkingport-forwarding

I have a device running linux and currently all of my network traffic is going through it before going to my Wifi router. I used arp spoofing to get between my devices and my router and used the following command to enable port forwarding:

echo 1 > /proc/sys/net/ipv4/ip_forward

As an example, how could I allow packets from 192.168.0.2 and block packets from 192.168.0.3?

Best Answer

Netfilter can do that, e.g

iptables -P FORWARD DROP
iptables -I FORWARD -p tcp -s 192.168.0.2 -j ACCEPT
service iptables save
Related Question