Skip to content
Eternal Center

Eternal Center

  • Single-Node (单节点)
    • System (系统)
    • Service (服务)
    • Database (数据库)
    • Container (容器)
    • Virtualization (虚拟化)
  • Multi-Node (多节点)
    • Cluster (集群)
    • Big Data (大数据)
    • Cloud Computing (云计算)
    • Batch Processing (批量处理)
  • Approach (方式方法)
    • Languages (语言)
    • Ideas (思路)
    • Programing (编程)
    • Project (项目)
  • Eternity (永恒)
    • News (消息)
    • Creations (创作)
    • Classics (经典)
    • Legends (传说)
    • Chronicle (编年史)
    • FNIOS (宇宙公民开源学院)
Posted on July 15, 2020October 19, 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 Post (中文帖子), iptables, Programming (编程), 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

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

Logo (徽标):

Additional Information (其他信息):

About     Manual     Clone     Contact
Disclaimer     Friendly Links     Donation

关于     手册     克隆     联系
免责声明     友情链接     捐赠

Search Inside Website (站内搜索)

Search Outside Website (站外搜索):

Google         Wikipedia         Bing

Eternal URL (永恒网址):

https://eternity.eternalcenter.com Will be last access method / 将是最后的访问方式

Proudly powered by LNMP Proudly powered by WordPress