Skip to content
Eternal Center

Eternal Center

  • System (系统)
  • Services (服务)
  • Databases (数据库)
  • Clusters (集群)
  • Big Data (大数据)
  • Cloud Computing (云计算)
  • Languages (语言)
  • Project (项目)
  • Writings (写作)
  • Eternity (永恒)
  • News (消息)
  • Chronicle (编年史)
  • Words (言)
Posted on 15/07/202026/12/2021 by Mingyu Zhu

[工具] Shell 只对某一个 IP 地址开放 TCP 22 端口 (iptables 版)

介绍:

名称:只对某一个 IP 地址开放 TCP 22 端口
作用:只对某一个 IP 地址开放 TCP 22 端口

使用方法:
1. 给此脚本添加执行权限
2. 执行此脚本

脚本分割线里的变量:
ipaddress=192.168.1.1 #要开放 TCP 22 端口的 IP 地址

脚本:

#!/bin/bash

####################### Separator ########################
ipaddress=192.168.1.1
####################### Separator ########################

systemctl stop firewalld
systemctl disable firewalld

yum -y install iptables-services
zypper -n install iptables

systemctl enable iptables
systemctl start iptables

sysctl -w net.ipv4.ip_forward=1
iptables -t filter -F
iptables -t nat -F

iptables -P OUTPUT ACCEPT
#iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT

iptables -A INPUT -i lo -j ACCEPT
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A INPUT -s 127.0.0.1 -d 127.0.0.1 -j ACCEPT

iptables -t filter -A INPUT -j ACCEPT -s $ipaddress -p tcp --destination-port 22
iptables -t filter -A INPUT -j DROP -p tcp --destination-port 22

service iptables save
systemctl restart iptables
CategoriesChinese (中文), Languages (语言), Shell, Shell Deployment (部署), Shell Network (网络), Shell Tool (工具), System (系统), System Firewall (系统防火墙), System Login Security (系统登录安全), System Network (系统网络), System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志), System Port Security (系统端口安全), System Security (系统安全)

Post navigation

Previous PostPrevious [内容] CentOS&RHEL 静态路由表的添加
Next PostNext [步骤] Linux 光纤号的查看

Aspiration (愿景):

Everyone can achieve self achievement and self happiness fairly

每个人都能公平地实现自我成就和自我幸福

Position (位置):

Running on Evolution Host and DigitalOcean

正在 Evolution Host 和 DigitalOcean 上运行

Logo (徽标):

Additional Information (其他信息):

About Manual Clone Contact Disclaimer Donation Friendly Links 关于 说明书 克隆 联系 免责申明 捐赠 友情链接

Standby IP Address (备用 IP 地址):

152.69.204.95  150.230.63.10  Please configure before use / 请先配置再使用

Search Outside Website (站外搜索):

Google Wikipedia Bing
Proudly powered by LNMP Proudly powered by WordPress