I want to open a port on the router itself. I tried to port forward to 192.168.1.1 but that didn't work. Is it just a matter of executing some iptables commands?
Not, an iptables expert but would appreciate some help/tips
iptables -I INPUT xxxxxxxxxxxxxxxxxxxxxxxxxxxx
iptables -I INPUT -p udp -m udp --dport 54321 -j ACCEPT
iptables -nvL INPUT --line
iptables -I INPUT "$(iptables -nvL INPUT --line -t filter | grep -m 1 "state INVALID" | awk '{$1 = $1 + 1; print $1}')" xxxxxxxxxxxxxxxxxxxxxxxxxxx
However, if I may ask.. "What custom service are you hosting on the router that requires ports to be opened from the WAN?"
iptables -A INPUT -d 192.168.1.1/32 -p tcp -m conntrack --ctstate DNAT -m tcp --dport XYZ -j ACCEPT
iptables -I INPUT "$(iptables -nvL INPUT --line -t filter | grep -m 1 "state INVALID" | awk '{$1 = $1 + 1; print $1}')" xxxxxxxxxxxxxxxxxxxxxxxxxxx
YesWorked like a charm.
I suppose I need to put this into the firewall-start script file
In truth you could simply insert your rule at the top of the chain - but it may get pushed down the processing order.On router startup, would there be any use in that command though? Would iptables have already established rules with the most hits?
-A INPUT -i eth0 -p icmp -m icmp --icmp-type 8 -j logdrop
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -m state --state INVALID -j logdrop
In truth you could simply insert your rule at the top of the chain - but it may get pushed down the processing order.
Usually the first three rules are:
So inserting your rule as the fourth rule means that probably >90% of the packets are processed (by rules 2 & 3 ) without even hitting your custom rule.Code:-A INPUT -i eth0 -p icmp -m icmp --icmp-type 8 -j logdrop -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -m state --state INVALID -j logdrop
If your rule was the first rule, then every packet will be tested to see if it is for your custom port! - bit inefficient wouldn't you agree?
Welcome To SNBForums
SNBForums is a community for anyone who wants to learn about or discuss the latest in wireless routers, network storage and the ins and outs of building and maintaining a small network.
If you'd like to post a question, simply register and have at it!
While you're at it, please check out SmallNetBuilder for product reviews and our famous Router Charts, Ranker and plenty more!