I want to update my firewall, so I want to create my own chain that block the access of the internet but keep accessing the LAN network.
How can I do that?
I want to update my firewall, so I want to create my own chain that block the access of the internet but keep accessing the LAN network.
How can I do that?
Assuming doesn't matter how many interfaces do you have, you can block all except traffic to and from your LAN network address subnet by using:
iptables -A INPUT -s $NETWORK_ADDRESS/$MASK -j ACCEPT
iptables -A INPUT -s $ANOTHER_NETWORK_ADDRESS/$MASK -j ACCEPT
iptables -A INPUT -j DROP</code>
iptables -A OUTPUT -d $NETWORK_ADDRESS/$MASK -j ACCEPT
iptables -A OUTPUT -d $ANOTHER_NETWORK_ADDRESS/$MASK -j ACCEPT
iptables -A OUTPUT -j DROP
You can find the network addresses and the network mask directly connected to your interfaces by typing:
ip r l | grep -v "default" | grep "proto kernel" | awk '{print $1}'
Replace $NETWORK_ADDRESS/$MASK
from the iptables
commands with those provided by the ip r l
command.
Assuming that you may have a DHCP Server on the LAN, you may want to allow this specific traffic in order to obtain an IP Address from the server.
In order to accomplish that you need to add more rules to IPTABLES:
iptables -I INPUT 1 -p udp --dport 67:68 --sport 67:68 -j ACCEPT
Explanation:
You need to accept incoming and outgoing traffic from your network address space and after that, you can DROP everything else.
The rule for DHCP Client will be inserted above all even if it is executed at the end because of the -I
(insert) INPUT "1"
. In this way, you make sure that you will get an IP Address from your DHCP Server.
ifconfig
by issuing in the firewall (assuming you use linux pc for firewall) and let us know, which is WAN and which is LAN interface. – fugitive Jan 17 '17 at 10:27