iptables in a file ?

Post new topic   Reply to topic    DD-WRT Forum Index -> Advanced Networking
Author Message
lebphi
DD-WRT Novice


Joined: 27 Jun 2019
Posts: 4

PostPosted: Thu Jun 27, 2019 12:19    Post subject: iptables in a file ? Reply with quote
hi,

i'm a beginner with dd-wrt. I'd like to add a lot of iptables rules. It is possible to put them in a file rather than entering them by the web interface ?

thanks you
Sponsor
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12877
Location: Netherlands

PostPosted: Thu Jun 27, 2019 12:30    Post subject: Reply with quote
Just copy them in Administration/commands and save firewall.

But if you have external storage you can set the rules in a script and execute this script from the same spot as described above.

DDWRT normally takes care of necessary firewall rules. The most common mistake is over configuration Smile

_________________
Routers:Netgear R7000, R6400v1, R6400v2, EA6900 (XvortexCFE), E2000, E1200v1, WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
lebphi
DD-WRT Novice


Joined: 27 Jun 2019
Posts: 4

PostPosted: Thu Jun 27, 2019 14:10    Post subject: Reply with quote
thanks you

i want to add rules for bloking all port except a few ones (80, 443, ..) for every one except for my personnal computer (specific mac).

so i've used the admin/commands as you said and it works fine.

i've added :

iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
iptables -I FORWARD -p udp --dport 53 -j ACCEPT
iptables -I FORWARD -p tcp --dport 53 -j ACCEPT
iptables -I FORWARD -p tcp --dport 80 -j ACCEPT
iptables -I FORWARD -p tcp --dport 443 -j ACCEPT
iptables -I FORWARD -p tcp --dport 993 -j ACCEPT
iptables -I FORWARD -p tcp --dport 587 -j ACCEPT
iptables -I FORWARD -p tcp --dport 465 -j ACCEPT
iptables -I FORWARD -m mac --mac-source 28:F1:xx:1E:42:xx-j ACCEPT

now i would like to block the acces at my box local network 192.168.1.0/24 for every one except for me (mac address) but it doesn't work, i block all even for myself.

i've added :
iptables -I FORWARD -s 192.168.1.0/24 -j DROP

is the problem come from my wan address is in the blocked range .

my wan status is ip=192.168.1.69 - gateway = 192.168.1.1

my lan status is ip=192.168.77.1 with dhcp server
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12877
Location: Netherlands

PostPosted: Thu Jun 27, 2019 16:23    Post subject: Reply with quote
To block all access to a router higher up try:

Code:
iptables -I FORWARD -i br0 -d $(nvram get wan_ipaddr)/$(nvram get wan_netmask) -m state --state NEW -j REJECT


Using MAC addresses is not always working depending if the MAC module is present or not

But if it works make sure that entry is the last so that it is executed first

_________________
Routers:Netgear R7000, R6400v1, R6400v2, EA6900 (XvortexCFE), E2000, E1200v1, WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
lebphi
DD-WRT Novice


Joined: 27 Jun 2019
Posts: 4

PostPosted: Thu Jun 27, 2019 17:44    Post subject: Reply with quote
the rules are executed in reverse from down to top ?
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12877
Location: Netherlands

PostPosted: Thu Jun 27, 2019 18:05    Post subject: Reply with quote
lebphi wrote:
the rules are executed in reverse from down to top ?


If you are using -I yes

_________________
Routers:Netgear R7000, R6400v1, R6400v2, EA6900 (XvortexCFE), E2000, E1200v1, WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
Alozaros
DD-WRT Guru


Joined: 16 Nov 2015
Posts: 6435
Location: UK, London, just across the river..

PostPosted: Thu Jun 27, 2019 23:09    Post subject: Reply with quote
iptables -I FORWARD ! -s 192.168.1.0/24 -j REJECT

try it, if this is in the correct format

! - mean's all reject, but not -s 192.168.1.0/24

if this is the correct spelling, i cant test it right now but you can try

_________________
Atheros
TP-Link WR740Nv1 ---DD-WRT 55630 WAP
TP-Link WR1043NDv2 -DD-WRT 55723 Gateway/DoT,Forced DNS,Ad-Block,Firewall,x4VLAN,VPN
TP-Link WR1043NDv2 -Gargoyle OS 1.15.x AP,DNS,QoS,Quotas
Qualcomm-Atheros
Netgear XR500 --DD-WRT 55779 Gateway/DoH,Forced DNS,AP Isolation,4VLAN,Ad-Block,Firewall,Vanilla
Netgear R7800 --DD-WRT 55779 Gateway/DoT,AD-Block,Forced DNS,AP&Net Isolation,x3VLAN,Firewall,Vanilla
Netgear R9000 --DD-WRT 55779 Gateway/DoT,AD-Block,AP Isolation,Firewall,Forced DNS,x2VLAN,Vanilla
Broadcom
Netgear R7000 --DD-WRT 55460 Gateway/SmartDNS/DoH,AD-Block,Firewall,Forced DNS,x3VLAN,VPN
NOT USING 5Ghz ANYWHERE
------------------------------------------------------
Stubby DNS over TLS I DNSCrypt v2 by mac913
lebphi
DD-WRT Novice


Joined: 27 Jun 2019
Posts: 4

PostPosted: Sat Jun 29, 2019 7:21    Post subject: Reply with quote
i've tried a lot of combination.
I've no problem for blocking ports but but i can't block local address 192.168.1.0/24

my last rules are :
iptables -A FORWARD -m mac --mac-source D0:16:B4:16:2A:xx -j ACCEPT
iptables -A FORWARD -s 192.168.1.0/24 -j DROP
iptables -A FORWARD -p udp --dport 53 -j ACCEPT
iptables -A FORWARD -p tcp --dport 53 -j ACCEPT
iptables -A FORWARD -p tcp --dport 80 -j ACCEPT
iptables -A FORWARD -p tcp --dport 443 -j ACCEPT
iptables -A FORWARD -p tcp --dport 993 -j ACCEPT
iptables -A FORWARD -p tcp --dport 587 -j ACCEPT
iptables -A FORWARD -p tcp --dport 465 -j ACCEPT

what i've doing wrong ?
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12877
Location: Netherlands

PostPosted: Sat Jun 29, 2019 10:12    Post subject: Reply with quote
It always helps if you state your router and build(number).
Furhtermore and more important state your problem.

Now you are presenting a solution and tell us it does not work, but for what problem? Smile

From your earlier post I was under the impression you have an ISP router on 192.168.1.0/24 subnet and you connected a DDWRT router with its WAN port to the ISP router, the DDWRT router has subnet 192.168.77.0/24.

So you actually double NATted (not a problem).

From your secondary router you want to block access to your ISP router on subnet 192.168.1.0/24 (with the exception of your own client)

In that case you have to block forwarding to a destination address on 192.168.1.0/24

As a general rule you block access to the subnet of the WAN interface, and that is what the rule I mentioned in my earlier post is supposed to do.

so if you want this try it Smile

If it works then under that rule set the rule to accept traffic from your own client and as it is inserted this rule will be executed first so that traffic from your own client is passed/accepted.

But maybe I am totally wrong and it is an entirely different problem in that case enlighten us Smile

_________________
Routers:Netgear R7000, R6400v1, R6400v2, EA6900 (XvortexCFE), E2000, E1200v1, WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> Advanced Networking All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum