What's new

Using iptables to control network access

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

leon

Regular Contributor
Hello,

I am thinking of preventing my wireless printer from accessing the internet but allow assess to my local home network. Can this be done via iptables? I tried the below, but it does not work...

Code:
iptables -A OUTPUT -s 192.168.1.157 -d 192.168.1.1/255.255.255.0 -j ACCEPT
iptables -A OUTPUT -s 192.168.1.157  -j DROP

192.168.1.157 is the ip of a computer which I used for testing. After I SSH to the router and issued the above two commands, the computer can still ping site such as google.com...

My next step is to allow some devices to assess the internet only, and via port 80 and 443. These devices cannot assess the local home network.

Any guidance is much appreciated. Thanks!
 
I think you need to add your rules to the beginning of the chain (-I) rather than the end (-A). Also, you need to use the FORWARD chain not the OUTPUT.
 
I think you need to add your rules to the beginning of the chain (-I) rather than the end (-A). Also, you need to use the FORWARD chain not the OUTPUT.
Thank you! Indeed by issue the command
Code:
iptables -I FORWARD -s 192.168.1.157  -j DROP

it stops the computer from assessing external network. However, if I issue this command, it does not stop the computer from assessing local internet...

Code:
iptables -I FORWARD  -s 192.168.1.157 -d 192.168.1.1/255.255.255.0 -j DROP

I read the iptables man page... and still cannot figure it out. :(
 
However, if I issue this command, it does not stop the computer from assessing local internet...

Code:
iptables -I FORWARD  -s 192.168.1.157 -d 192.168.1.1/255.255.255.0 -j DROP
I think it's because all the LAN traffic is bridged on interface br0, so it never hits the iptables rules because it doesn't need to be forwarded anywhere.

From what I've read on here (but I've never tried this) the trick is to drop the packets from the bridge so that they are then able to be manipulated by iptables. So you would have something like this:
Code:
ebtables -I FORWARD -p IPv4 --ip-src 192.168.1.157 -j DROP
iptables -I FORWARD -s 192.168.1.157 -d 192.168.1.1/255.255.255.0 -j DROP

But this is just a wild guess!
 
I think it's because all the LAN traffic is bridged on interface br0, so it never hits the iptables rules because it doesn't need to be forwarded anywhere.

From what I've read on here (but I've never tried this) the trick is to drop the packets from the bridge so that they are then able to be manipulated by iptables. So you would have something like this:
Code:
ebtables -I FORWARD -p IPv4 --ip-src 192.168.1.157 -j DROP
iptables -I FORWARD -s 192.168.1.157 -d 192.168.1.1/255.255.255.0 -j DROP

But this is just a wild guess!
Thanks... It does not work... I will need to dive deeper to know if iptables can control local-to-local assess.
 
2. if you want to block LAN to LAN, it's impossible due to switch packets can't reach CPU, and you can't control it.
But it is possible to block WLAN to LAN using ebtables and iptables (that's how guest networks do it). It's also possible to block WLAN to WLAN using "Set AP Isolated".
 

Similar threads

Latest threads

Support SNBForums w/ Amazon

If you'd like to support SNBForums, just use this link and buy anything on Amazon. Thanks!

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!

Staff online

Top