Blocking an IP address

Dear all,

I am new to this forum.I need some assistant from you people.

I have a server in which Linux 5 is installed and it is in the network. How i block any user to access my server.. Upto how many users i can block.. send me the procedure....

Thank you in advance......

i didn't understand the purpose of this...can u elaborate more on your requirement....if you dont want ur server to be accessed dont create the user account :slight_smile:

the server is in network to which many computers are connected. All the users on the systems are accessing it. I just want to block a perticular IP or the user using that ip who is not able to access that server...

How to do that..

plz reply.

Please give as much information as possible when asking such questions. No one here knows your network, and no 2 networks are the same. No one here knows your machine, and what services are running there. No one here knows your users, or why they have to be blocked.

So: what services are running on your machine? Which one do you want to block for a user? If it's a webservice, do you want to completely block that user, or just for certain applications in that service? Is the user always connecting with the same IP, or do they switch workstations/get new IPs (DHCP)?

Also,

Please refrain from calling it "Linux 5." The Linux kernel is on version 2.6.3x. Red Hat puts out a distribution called "Red Hat Enterprise Linux" and you are likely on version 5 of that software. Calling it "Linux 5" can cause confusion, even if it is under the Red Hat forums.

That being said,

You may want to look into hosts.deny and perhaps iptables. Hosts.deny will disallow logins from certain areas and iptables can simply drop packets from a particular rule base, which can contain an IP address or range.

If you have iptables configured and running:

iptables -I INPUT -s <IP_ADDRESS_TO_BLOCK> -j DROP
service iptables reload

Replace <IP_ADDRESS_TO_BLOCK> with the ip address you want to block.

You can check the status of your iptables service with:

service iptables status

Sorry but this is not going to work as you have stated here. Once you have given the first line there is no reason to execute the second as it will only reload the saved rules and thus remove the rule you just added. The command to save the running rules is:

service iptables save

You need to save the running rules first so that you will have them when you reboot.

Once you perform a iptables save, you should be able to take a look at /etc/sysconfig/iptables to see what was written there.

Another really good thing to do (as I have locked myself out of a system by adding a firewall rule) is to start the firewall, test it then stop it in a few seconds just in case.

To do this perform the below

/sbin/service iptables restart && sleep 90 && /sbin/service/iptables stop

If 90 seconds is not long enough to test, increase it.

While the suggested ip address rule should not cause problems, it could if you typed in the wrong ip address or added a more complex rule.

I've tried that sometimes, and found that any command that tries to print to stdout when your connection is firewalled out may hang until the ssh session quits. So I'd go a bit farther and put that in a script so you can nohup it.

Yes, you are right. Thanks for the correction. I normally just edit /etc/sysconfig/iptables directly.

Same here, I find it easier.