iptables in redhat

i have installed redhat 5.5 enterprise server on two pc. one is having ip & another is having ip. to enable ssh service on from i am runing this command.

iptables  -A  INPUT  -s -p tcp --dport 22 -j ACCEPT

after then i am runing command "service iptables save". but i am unable to take ssh connection on, how to block & allow services by iptables. i am runing correct command or not.

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kerem ERSOYPresidentCommented:

To add the command  to the default Input chain on RedHAT you should use:
iptables  -A  RH-Firewall-1-INPUT  -s -m tcp -p tcp --dport 22 -j ACCEPT
instead of INPUT.

Since ordering is also important for firewalls (your command will probably be installed after the final reject and will not be executed because of ordering) . I'll suggest you to insert this line into:


file and before :

-A RH-Firewall-1-INPUT -j REJECT --reject-with icmp-host-prohibited


then issue:

service iptables restart


Kerem ERSOYPresidentCommented:
as you will see when you input the command as you've proposed:

# iptables  -A  INPUT  -s -p tcp --dport 22 -j ACCEPT

# iptables -L
Chain INPUT (policy ACCEPT)
target     prot opt source               destination        
ACCEPT     udp  --  anywhere             anywhere            udp dpt:domain
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:domain
ACCEPT     udp  --  anywhere             anywhere            udp dpt:bootps
ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:bootps
RH-Firewall-1-INPUT  all  --  anywhere             anywhere            
ACCEPT     tcp  --          anywhere            tcp dpt:ssh

as you see you' command has been inserted after the IPTables jump to the RH-Firewall-1-INPUT chain. So it will never be executed.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux Distributions

From novice to tech pro — start learning today.