Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am trying to block 80/443 on my server using iptables (prevent anyone from attempting to access the ports on the outside). The first rule I have for input is this:
Code:
-A INPUT -i eth0 (this is my wan interface) -p tcp -m tcp --dport 80:443 -j DROP
I go to do a scan, and it returns, showing that ports 80 and 443 are open (TCP). Why are they still showing as open?
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
That is good. Then I am not sure IPTables will show the port as open while still denying a TCP connection. To be sure you can telnet into the port and see if you get "connection refused". Then you know the connection is denied.
And if you can connect, you should create that log entry to see if your rule matches.
Quote:
-A INPUT -i eth0 (this is my wan interface) -p tcp -m tcp --dport 80:443 -j DROP
You have a type here: -m tcp. In your second post it was corrected.
Since multiport is a module which is not installed by default (depending on your installation) try to skip the multiport and try a single port first. You can also create 2 rules. It is only 2 ports. Depending on how you enter the IPTables commands you might or might not see an error message on the multiport module.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
Quote:
Originally Posted by sniper8752
I added this rule: -A INPUT -i eth0 -p tcp -m tcp --dport 80 -j DROP, but nmap still shows 80/tcp http.
-m tcp is not really needed. Although I believe it is correct, it is hardly specified explicitly.
You really should try this and see if something is logged:
Code:
iptables -A INPUT -p tcp --dport 80 -j LOG --log-prefix "dropped access to port 80"
iptables -A INPUT -p tcp --dport 80 -j DROP
Did you try the telnet connection as I suggested?
If the log does not show anything and telnet does connect, you make wrong assumptions somewhere. So install tcpdump and run:
Code:
tcpdump -i eth0 port 80
while you telnet into your host.
It is plain impossible you see traffic on port 80 in tcpdump and you don't see anything in the log of IPTables.
So I've been thinking it might be better to just go to the root cause of the issue, and prevent apache2 from listening on the wan interface. I've modified ports.conf and sites-available/000-default.conf and default-ssl.conf, but a scan still shows the two ports. I'd rather not have to block them, and just have the product configured properly. Is there a configuration I'm missing somewhere, where the listening interface needs to be updated?
Have you changed the apache listen address to just your LAN?
Rules operate in order so while you just posted the one for port 80 you could have a something misplaced. In addition I prefer to set the default polices to drop then add rules to allow incoming traffic.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
Quote:
Originally Posted by sniper8752
So I've been thinking it might be better to just go to the root cause of the issue, and prevent apache2 from listening on the wan interface. I've modified ports.conf and sites-available/000-default.conf and default-ssl.conf, but a scan still shows the two ports. I'd rather not have to block them, and just have the product configured properly. Is there a configuration I'm missing somewhere, where the listening interface needs to be updated?
Now I asked you 3 times to add a log target to IPtables and to try a telnet connection from the outside to your box. And run tcpdump dependent on the previous outcome.
See, if you don't ever issue a test command you can keep trying things until you see blue in the face.
Now I asked you 3 times to add a log target to IPtables and to try a telnet connection from the outside to your box. And run tcpdump dependent on the previous outcome.
See, if you don't ever issue a test command you can keep trying things until you see blue in the face.
-m tcp is not really needed. Although I believe it is correct, it is hardly specified explicitly.
You really should try this and see if something is logged:
Code:
iptables -A INPUT -p tcp --dport 80 -j LOG --log-prefix "dropped access to port 80"
iptables -A INPUT -p tcp --dport 80 -j DROP
Did you try the telnet connection as I suggested?
If the log does not show anything and telnet does connect, you make wrong assumptions somewhere. So install tcpdump and run:
Code:
tcpdump -i eth0 port 80
while you telnet into your host.
It is plain impossible you see traffic on port 80 in tcpdump and you don't see anything in the log of IPTables.
jlinkels
Added rules. It says it connected, and I saw a few results while running tcpdump.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.