Q.Can you explain the meaning of following two firewall rules present in my /etc/sysconfig/iptables rules under CentOS Enterprise Linux version 5.2?
-A RH-Firewall-1-INPUT -p 50 -j ACCEPT
-A RH-Firewall-1-INPUT -p 51 -j ACCEPT
[continue reading…]
Q. I run both RHEL / CentOS Linux server and by default firewall blocked out everything including telnet / ssh access. How do I allow telnet – port 23 and ssh port 22 thought Linux iptables firewall ?
A.By default firewall rules stored at /etc/sysconfig/iptables location / file under CentOS / RHEL. All you have to do is modify this file to add rules to open port 22 or 23.
Login as the root user.
Open /etc/sysconfig/iptables file, enter:
# vi /etc/sysconfig/iptables
Find line that read as follows:
COMMIT
To open port 22 (ssh), enter (before COMMIT line):
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
To open port 23 (telnet), enter (before COMMIT line):
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 23 -j ACCEPT
Save and close the file. Restart the firewall:
# /etc/init.d/iptables restart
Q. How do I block ip address of spammers with iptables based firewall under CentOS Linux 5?
A. You can simply block IP address of spammers by editing /etc/sysconfig/iptables file under:
a) CentOS Linux
b) Fedora Linux
c) RHEL 4.x/5.x etc
Open file /etc/sysconfig/iptables:
# vi /etc/sysconfig/iptables
Append ip address of spammers as follows:
-A RH-Firewall-1-INPUT -s SPAMMER-IP -j DROP
-A RH-Firewall-1-INPUT -s SPAMMER-SUBNET-BLOCK -j DROP
Save and close the file. Just restart the firewall:
# /etc/init.d/iptables restart
You can also create a small shell script to block lots of IP address at a time.
I have Red Hat Enterprise Linux 5 server with Iptabeles firewall enabled. I have started all services but don’t know how to open port using iptables. By default it is only allowing port ssh tcp port # 22. How do I open port 80 / 143 / 110 on Linux?
[continue reading…]
I need to disable firewall in Linux for testing purpose. I’m using CentOS and RHEL version 4.4 / 5 / 6. How do I disable the firewall in Linux?
[continue reading…]
How do I block an IP address or subnet under Linux operating system?
[continue reading…]
Q. How do I stop or restrict access to my OpenSSH (SSHD) server using Linux iptables based firewall?
A. Linux iptables firewall can be use to block or restrict access to ssh server. Iptables command is used to set up, maintain, and inspect the tables of IP packet filter rules in the Linux kernel. However, you can also use tcpd, access control facility for internet services.
Use iptables to Restrict ssh access
Following is simple rule that block all incoming ssh access at port 22
iptables -A INPUT -p tcp -s 0/0 --sport 513:65535 -d 195.55.55.78 --dport 22 -m state --state NEW,ESTABLISHED -j DROP
However in real life you need to use something as follows. Let us assume that your ssh server IP address is 195.55.55.78, remember ssh server use TCP port 22 for all incoming connection. With iptables you can block all incoming connection at port 22 with following two rules:
iptables -A INPUT -p tcp -s 0/0 --sport 513:65535 -d 195.55.55.78 --dport 22 -m state --state NEW,ESTABLISHED -j DROP
iptables -A OUTPUT -p tcp -s 195.55.55.78 --sport 22 -d 0/0 --dport 513:65535 -m state --state ESTABLISHED -j DROP
If you just want to deny access to group of IPS then you need to add following rules to your script:
IPS="202.54.1.20 64.66.44.22 64.66.44.25"
for i in $IPS
do
iptables -A INPUT -p tcp -s 0/0 -s $i --sport 513:65535 -d 195.55.55.78 --dport 22 -m state --state NEW,ESTABLISHED -j DROP
iptables -A OUTPUT -p tcp -s 195.55.55.78 --sport 22 -d $i --dport 513:65535 -m state --state ESTABLISHED -j DROP
done
Add all of above rules to your iptables firewall shell script (do not type @ shell prompt)
See also: