2
I am using a Ubuntu 14.04 server machine as my primary home router and firewall. It has DNS, DHCP and uses iptables to secure everything up. Iptables also acts as a nat.
On eth0 I have my incoming internet connection, and on eth1 I have my LAN for serving DNS and DHCP. All clients (connected to eth1) should be able to do anything outbound as normal. And on the lan I have a few machines which I want to connect to from the outside using PREROUTING.
However, lately I discovered that my ruleset was defined with ACCEPT on the *filter of INPUT without any DROP defined on the end. Therefore i have now defined DROP on incoming. After discovering this I have gotten a bit concerned and want to double check the whole ruleset if I have missed something more.
Is this set of iptables sufficient for securing everything up? As I have understood from reading up a bit is that PREROUTING and FORWARD can be set to ACCEPT since it will hit INPUT if nothing matches there, and i turn get DROPped by the default rule. Is this correct?
*filter
:INPUT DROP
-A INPUT -i eth1 -j ACCEPT
-A INPUT -i eth0 -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -i eth0 -p tcp -m tcp --dport 80 -m state --state NEW -j ACCEPT
-A INPUT -i eth0 -p udp -m udp --dport 53 --sport 53 -m state --state NEW -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
:FORWARD ACCEPT
-A FORWARD -i eth0 -j ACCEPT
:OUTPUT ACCEPT
COMMIT
*nat
:PREROUTING ACCEPT
-A PREROUTING -i eth0 -p tcp -m tcp -s x.x.x.x --dport 8466 -j DNAT --to-destination 192.168.0.149:8465
-A PREROUTING -i eth0 -p tcp -m tcp -s x.x.x.x --dport 5667 -j DNAT --to-destination 192.168.0.111:5666
-A PREROUTING -i eth0 -p tcp -m tcp -s x.x.x.x --dport 5666 -j DNAT --to-destination 192.168.0.201:5666
-A PREROUTING -i eth0 -p tcp -m tcp -s x.x.x.x --dport 2548 -j DNAT --to-destination 192.168.0.201:548
-A PREROUTING -i eth0 -p tcp -m multiport --dports 32400,32469 -j DNAT --to-destination 192.168.0.201
:INPUT ACCEPT
:OUTPUT ACCEPT
:POSTROUTING ACCEPT
-A POSTROUTING -o eth0 -j MASQUERADE
COMMIT
Yes, you are correct. I will remove the outside entry for my DNS.
So, what you are saying is that other than my public DNS-entry this is all fine and should be secure even though FORWARD and PREROUTING is set to ACCEPT on everything? – hrdy – 2015-06-11T20:23:24.057
And why does the PREROUTING stop working if I set is to DROP instead of ACCEPT? The NAT functions works fine when set to accept. – hrdy – 2015-06-11T20:34:57.043
@hrdy Yes, I am saying this is secure: the gateway only accepts ssh and http ports, it only forwards the ports you selected to those machines, everything else is dropped. – MariusMatutiae – 2015-06-12T05:28:59.547
@hrdy As for the change of behavior when you set the default PREROUTING policy, this has to do with Reverse Packet filtering. You may ask another question, or read this: http://www.slashroot.in/linux-kernel-rpfilter-settings-reverse-path-filtering
– MariusMatutiae – 2015-06-12T06:55:20.293