How to configure iptables and ssh in Linux

Source: Internet
Author: User
Resource: 10 centos servers, ip address: 192.168.1.11-192.168.1.20 requirement: ssh can be accessed by 10 servers, and 10.0.60.0/24 and 192.168.1.200; others reject 1, node1 write the following script iptables. shiptables-Fiptables-Xiptables-IINPUT-pTCP -- d resources: 10 CentosServer, ip: 192.168.1.11-192.168.1.20
Requirement: ssh can be accessed by 10 hosts, and 10.0.60.0/24 and 192.168.1.200; other requests are rejected.

1. write the following script on node1. Iptables. Sh
Iptables-F
Iptables-X
Iptables-I INPUT-p TCP -- dport 22-j REJECT
Iptables-I INPUT-pTCP -- dport 22-s 10.0.60.0/24-j ACCEPT
Iptables-I INPUT-pTCP -- dport 22-s 192.168.1.200-j ACCEPT
For I in {11 .. 20}
Do
Iptables-I input-p TCP -- dport 22-s 192.168.1. $ I-j ACCEPT
Done

2. run the command on node1.
# Chmod + x iptables. sh
# For I in {11 .. 20}; do scp iptables. sh node $ I:/root; done
# For I in {11 .. 20}; do ssh node $ I '/root/iptables. sh'; done
# For I in {11 .. 20}; do ssh node $ I '/etc/init. d/iptablessave'; done
# View iptables-L-n

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.