"JJMMPP" <(E-Mail Removed)> said:
>Hello,
>
>Recently I have been trying to set up my firewall to block attempts to
>access apache (running on the same machine listening on port 8080,
>virtual-hosting a few domains) from a specific machine (or machines) on the
>internet.
Ok.
>I've tried the following unsuccessfully, attempting to block just one IP,
>remember my server listens on 8080:
>
>$IPTABLES -A INPUT -i $EXTIF -p TCP -s $BLOCKEDIP \
>-d $EXTIP -m state --state NEW,ESTABLISHED,RELATED --dport 8080 -j REJECT
First, what do you have before this, and what do you have after this,
in your active configuration. Check that with "iptables -vL INPUT".
Then, you're much too fancy here; just do
$IPTABLES -A INPUT -p tcp -s $BLOCKEDIP --dport 8080 -j REJECT
(or, the same with "-j DROP").
>I have to put a:
>$IPTABLES -A INPUT -i $EXTIF -p TCP -s $UNIVERSE-d $EXTIP --dport 8080 -j ACCEPT
>in the script or nothing can access the server, but then access to the
>server is still granted to the BLOCKEDIP address. This seems to make sense
>as it overrides.. but...
This depends on the default policy for the INPUT chain, and also on the
other rules in the INPUT chain.
Overall, you seem to have some misunderstandings on how the iptables
rules work, so I'll try to clarify that here. ACCEPT, DROP and REJECT
are considered "terminal" rules. the conditions on an iptables rule
match, and the action (-j XXX) on the iptables rule is one of these
three, the action is taken, and processing of the packet ends there.
If a packet doesn't match any of the rules in an iptables rule list,
then either the processing continues in the calling rule list (if
the rule list that just ended was a user-defined one), or the default
policy of the rule list is applied (for INPUT, OUTPUT and FORWARD lists).
So, if you have an INPUT rule list with:
- policy ACCEPT
- -p tcp -s some-addr --dport port -j DROP
.... then all packets, except those that are coming from some-addr, and
targeted to TCP port "port" are accepted. Packets from that one source
address, targeted to the one TCP port, are silently dropped. The sending
site will at some point time out the connection.
If the rule list was:
- policy DROP
- -p tcp --dport port -j ACCEPT
- -p tcp -s some-addr --dport port -j DROP
.... then all traffic to TCP port "port" would be accepted (even from
"some-addr", because the first rule matches also that source address),
but all other traffic would be dropped. So, here one could guess that
the order of the two rules (policy isn't a rule as such) should be the
opposite.
>I was beginning to think Apache might bypass this, but that cannot
>be possible since iptables is what controls the kernel routing. No
>applications or daemons running on the system should be able to
>override the rules set in iptables.
Pretty much so. However, applications opening RAW network sockets work
"outside" iptables. But typically applications don't do this (..hmm;
dhcp client could be the only one that I know of, and then the various
network traffic loggers).
>So back to the problem at hand-- Besides configuring apache to deny access
>by certain IPs in htaccess- which I don't want to do, what *can* I do to
>have IPTABLES make the web server not to be there when one or more blocked
>IP's attempt to access it.
I hope you found your answer above -- my best guess is that you're somewhere
before dropping the offending traffic, accepting it via some other rule.
If you still don't find what is wrong, please post output of
"iptables -nvL INPUT" on your machine. Mask out the actual IP numbers,
though.
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)
|