Ubuntu: Restricting Internet traffic through Wifi Router only



Question:

I want to allow Internet traffic only through my default gateway i.e. the wifi router. And no other local IP should be able to communicate with my laptop. How can I achieve this?


Solution:1

no other local IP should be able to communicate with my laptop

You could write an iptables script for that.

  #!/bin/bash  IPTABLES="/sbin/iptables"    LOCALNET="192.168.1.0/24"  # Your local / home network that you want to exclude from your machine    $IPTABLES -A INPUT -s $LOCALNET -j DROP   

This script is just a snippet

I want to allow Internet traffic only through my default gateway

This should be done by the route table. I am not familiar with it. You should find the solution here: How to set static routes in Ubuntu Server?

  auto eth0  iface eth0 inet static        address 192.168.1.2        netmask 255.255.255.0        up route add -net 192.168.0.0 netmask 255.255.0.0 gw 192.168.1.1        up route add -net 172.16.0.0 netmask 255.240.0.0 gw 192.168.1.1  

eth0 is your ethernet device gw is your gateway

To check your routes just type route in terminal. The IP 0.0.0.0 is the internet.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »