Skip to content

Eternal Center

  • Single Node (单节点)
    • System (系统)
    • Service (服务)
    • Database (数据库)
    • Container (容器)
    • Virtualization (虚拟化)
  • Multi Node (多节点)
    • Cluster (集群)
    • Big Data (大数据)
    • Cloud Computing (云计算)
    • Batch Processing (批量处理)
  • Other (其它)
    • Ideas (思路)
    • Language (语言)
    • Project (项目)
  • Eternity (永恒)
    • Creations (创作)
    • Classics (经典)
    • Chronicle (编年史)
    • News (消息)
Posted on July 15, 2020July 6, 2022 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 (中文), Language (语言), Shell, Shell Deployment (部署), Shell Network (网络), Shell Tools (工具), System (系统), System Firewall (系统防火墙), System Login Security (系统登录安全), System Network (系统网络), System Network & System Security & System Log (系统网络 & 系统安全 & 系统日志), System Port Security (系统端口安全), System Security (系统安全)

Post navigation

Previous PostPrevious [内容] 静态路由表的添加(CentOS Linux & 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