nmap, I discovered that there are 3 open ports on my server. I want to deny any access to these ports from any machine, regardless of whether it is on the same LAN or via WAN. How do I write an
iptables rule for this?
Are you trying to block all open ports on a specific interface? If so, you can use the following command
where eth0 is usually for LAN interface
usually for WAN
If you want to deny access to all the machines ("any machine from LAN and WAN") it is better to either stop those services or bind them to the localhost. This way there will be no chance of messing up iptable rules.
Still, you can use IPTABLES to block access to specific ports as well.
Repeat the above rule for all the ports you want to block access to.
To close an individual port, you can do the following.
Note that this solves the individual problem, but in a general sense you should explicitly allow which ports you wish to have open and then deny the rest. Particularly since you probably still want to access these ports from your the local machine, that adds a lot more convenience in rule writing as well.