CentOS 7关闭防火墙 SElinux 配ip
iptables -t filter -A OUTPUT --dst 192.168.0.191/32 -j DROP
iptables -t filter -A OUTPUT --dst 192.168.0.192/32 -j DROP
iptables -t filter -A OUTPUT --dst 192.168.0.193/32 -j DROP
#!/bin/sh
# reset :
iptables -t filter -F
iptables -t filter -X
# Block all :
iptables -t filter -P INPUT DROP
iptables -t filter -P FORWARD DROP
iptables -t filter -P OUTPUT DROP
# Authorize already established connections :
iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
# Authorize backloop :
iptables -t filter -A INPUT -i lo -j ACCEPT
iptables -t filter -A OUTPUT -o lo -j ACCEPT
# Authorize ssh :
iptables -t filter -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 22 -j ACCEPT
# Authorize HTTP :
iptables -t filter -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 80 -j ACCEPT
# Authorize HTTPS :
iptables -t filter -A INPUT -p tcp --dport 443 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 443 -j ACCEPT
# Authorize DNS :
iptables -t filter -A INPUT -p tcp --dport 53 -j ACCEPT
iptables -t filter -A OUTPUT -p udp --dport 53 -j ACCEPT
iptables -t filter -A INPUT -p udp --dport 53 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 53 -j ACCEPT
# Ping :
iptables -t filter -A INPUT -p icmp -j ACCEPT
iptables -t filter -A OUTPUT -p icmp -j ACCEPT
# Authorize FTP :
iptables -t filter -A INPUT -p tcp --dport 20 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 20 -j ACCEPT
iptables -t filter -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 21 -j ACCEPT
# # Authorize NTP :
# iptables -t filter -A INPUT -p udp --dport 123 -j ACCEPT
# iptables -t filter -A OUTPUT -p udp --dport 123 -j ACCEPT
# Authorize IRC :
iptables -t filter -A INPUT -p tcp --dport 6667 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 6667 -j ACCEPT
# Authorize port 10000 (for Node.JS server) :
iptables -t filter -A INPUT -p tcp --dport 10000 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 10000 -j ACCEPT
# Authorize port 631 (Cups server) :
iptables -t filter -A INPUT -p tcp --dport 631 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 631 -j ACCEPT
# Authorize port 9418 (git) :
iptables -t filter -A INPUT -p tcp --dport 9418 -j ACCEPT
iptables -t filter -A OUTPUT -p tcp --dport 9418 -j ACCEPT
# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
#定义白名单群组
-N whitelist
#设置白名单IP,开放ip可以访问设备,白名单就按类似规则增加就可以
-A whitelist -s 192.168.1.100 -j ACCEPT
-A whitelist -s 100.20.30.40 -j ACCEPT
-A whitelist -s 1.2.3.4 -j ACCEPT
-A whitelist -s 25.36.47.58 -j ACCEPT
#开放所有设备主动访问的服务器,处在RELATED,ESTABLISHED状态可以通信,这样设备需要主动访问的服务器就不用一个一个添加到白名单了
-A INPUT -m state --state RELATED,ESTABLISHED -j whitelist
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
#白名单端口
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j whitelist
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j whitelist
-A INPUT -m state --state NEW -m tcp -p tcp --dport 9000 -j whitelist
#也可以这样写
#-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306,80,9000 -j whitelist
#拒绝白名单以外IP访问指定端口
-A INPUT -p tcp -m multiport --dports 3306,80,9000 -j DROP
COMMIT
对指定ip开放1024——65535之间的端口
-A INPUT -s 61.135.125.14 -p tcp --dport 1024:65535 -m comment --comment "仅允许公司ip连" -j ACCEPT
————
转发 SSH 端口 参考
iptables -t nat -A PREROUTING -d 1.1.1.1 -p tcp -m tcp --dport 22 -j DNAT --to-destination 10.0.0.2:22
iptables -t nat -A POSTROUTING -d 10.0.0.2 -p tcp -m tcp --dport 22 -j MASQUERADE
service iptables save
转发端口——————————————————————————————
|
2
3
4
|
iptables -t nat -A PREROUTING -p tcp --dport [端口号] -j DNAT --to-destination [目标IP]
iptables -t nat -A PREROUTING -p udp --dport [端口号] -j DNAT --to-destination [目标IP]
iptables -t nat -A POSTROUTING -p tcp -d [目标IP] --dport [端口号] -j SNAT --to-source [本地服务器IP]
iptables -t nat -A POSTROUTING -p udp -d [目标IP] --dport [端口号] -j SNAT --to-source [本地服务器IP]
|
为新的iptables规则添加注释的语法为 : comment --comment “要添加的注释文字”
具体的例子:下面添加一条允许ssh流量通过的规则,并且给这条规则添加注释:
$ sud iptables -A INPUT -p tcp -m tcp --dport 22 -m comment --comment "allow SSH to this host from anywhere" -j ACCEPT
CentOS 7关闭防火墙 SElinux 配ip (2016/6/2 9:34:10)
systemctl stop firewalld.service && systemctl disable firewalld.service && sed -i '/SELINUX/s/enforcing/disabled/g' /etc/selinux/config && source /etc/selinux/config && setenforce 0
sed -i '/匹配字符串/s/源字符串/目标字符串/g' ab.txt
IP='192.168.5.21'
sed '3a IPADDR="192.168.1.23"' -i /etc/sysconfig/network-scripts/ifcfg-em2
sed '4a NETMASK="255.255.225.0"' -i /etc/sysconfig/network-scripts/ifcfg-em2
sed -i '/BOOTPROTO/s/dhcp/static/' /etc/sysconfig/network-scripts/ifcfg-em2
sed -i '/ONBOOT/s/no/yes/' /etc/sysconfig/network-scripts/ifcfg-em2
sed '5a GATEWAY="192.168.5.1"' -i /etc/sysconfig/network-scripts/ifcfg-em2
sed '6a DNS1="114.114.114.114"' -i /etc/sysconfig/network-scripts/ifcfg-em2
sed '2 ittt' -i a.txt # 在第2行前插入ttt,并且将结果更新到a.txt(
CentOS 7.0默认使用的是firewall作为防火墙,这里改为iptables防火墙。
firewall:
systemctl start firewalld.service#启动firewall
systemctl stop firewalld.service#停止firewall
systemctl disable firewalld.service#禁止firewall开机启动
改成iptables
firewall:
systemctl start iptables.service
屏蔽端口 屏蔽3306端口
iptables -A OUTPUT -p tcp --dport 3306 -j DROP
iptables -A INPUT -p tcp --dport 3306 -j DROP
关闭centos7自带防火墙启用iptables
systemctl mask firewalld
systemctl stop firewalld
yum install iptables-services
systemctl enable iptables
systemctl start iptables
centos7防火墙添加开放端口
实际命令如下:
firewall-cmd --permanent --add-port=3389/tcp
执行可以成功 用该命令查询firewall-cmd --permanent --query-port=1000/tcp
#firewall-cmd --reload
查看当前默认区域
firewall-cmd --get-default-zone
改变网卡接口区域 em2是网卡名
firewall-cmd --zone=trusted --change-interface=em2
查看网卡所在区域
firewall-cmd --get-zone-of-interface=em2
service iptables start
iptables -A INPUT -p tcp --dport 你的vps端口号 -j ACCEPT
iptables -A OUTPUT -p tcp --sport 你的vps端口号 -j ACCEPT
service iptables save
————————————————————
启动失败时 Assertion failed for IPv4 firewall with iptables
service iptables save
systemctl stop firewalld
systemctl disable firewalld
systemctl start iptables
systemctl status iptables
systemctl enable iptables
CentOS系统中使用iptables设置端口转发 - 高明松博客 - Mozilla Firefox (2016/8/5 18:52:51)
CentOS系统中使用iptables设置端口转发
之前写过一篇Haproxy下的转发,但Haproxy无法转发udp数据,所以这次使用iptables来转发tcp和udp的数据,首先我们来看一下数据包的走向
- +--------+ +--------+ +--------+
- | | <--D-- | | <--C-- | |
- | 用户 | | 中转机 | | 目标 |
- | | --A--> | | --B--> | |
- +--------+ +--------+ +--------+
A: 用户发出加密请求到SSS服务器
B: SSS服务器解密请求后转发到目标服务器
C: 目标服务器回应SSS服务器
D: SSS服务器加密回应返回给用户然后解密后使用
清空相关规则
加载相关的内核模块
- /sbin/modprobe ip_tables
- /sbin/modprobe ip_nat_ftp
- /sbin/modprobe ip_conntrack_ftp
清除预设表 filter 中,所有规则链中的规则
- /sbin/iptables -F
清除nat表中,所有规则链中的规则
- /sbin/iptables -F -t nat
清除预设表 filter 中,使用者自订链中的规则
- /sbin/iptables -X
将封包计数器归零。封包计数器是用来计算同一封包出现次数,是过滤阻断式攻击不可或缺的工具
- /sbin/iptables -Z
清除mangle表中,所有规则链中的规则
- iptables -F -t mangle
清除mangle表中,使用者自订链中的规则
- iptables -t mangle -X
清除nat表中,使用者自订链中的规则
- iptables -t nat -X
定义链的规则(设定预设规则)
- /sbin/iptables -P INPUT ACCEPT
- /sbin/iptables -P FORWARD DROP
- /sbin/iptables -P OUTPUT ACCEPT
打开 forward 功能 (或在/etc/sysconfig/network 中添加 FORWARD_IPV4=yes 打开转发功能,实现各网段互访)
- echo "1"> /proc/sys/net/ipv4/ip_forward
配置iptables转发
- iptables -t nat -A POSTROUTING -j MASQUERADE
- iptables -A FORWARD -s 1.1.1.1 -j ACCEPT
- iptables -t nat -A PREROUTING -p tcp --dport 10000:20000 -j DNAT --to-destination 1.1.1.1:10000-20000
- iptables -t nat -A PREROUTING -p udp --dport 10000:20000 -j DNAT --to-destination 1.1.1.1:10000-20000
- iptables -t nat -A POSTROUTING -p tcp -d 1.1.1.1 --dport 10000:20000 -j SNAT --to-source 2.2.2.2
- iptables -t nat -A POSTROUTING -p udp -d 1.1.1.1 --dport 10000:20000 -j SNAT --to-source 2.2.2.2
- iptables -A INPUT -p tcp --dport 22 -j ACCEPT
- iptables -A OUTPUT -p tcp --sport 22 -j ACCEPT
然后继续下面的操作
- ###重要说明###
- 1.1.1.1 为目标服务器的IP地址
- 10000:20000 需要转发的端口范围
- 2.2.2.2 本机服务器的IP(也就是中转机)
- 最后面两条是ssh的端口,根据你自己使用的ssh端口进行添加
- ---------------------------------------------------
- 然后保存和重启iptables以及添加开机启动
- 保存:service iptables save
- 重启:service iptables restart
- 开机启动:chkconfig iptables on
iptables转发的配置也就这么多,写这些步骤的目的只是为了让大家明白原理,下面贴出脚本下载地址:
- wget --no-check-certificate https://soft.jiasu.cloud/iptables/iptables.sh
此脚本并非是一键脚本,下载后对照上面的说明,使用vim修改里面的IP地址以及端口,修改完以后保存,然后执行:bash iptables.sh
附件列表
CentOS 7关闭防火墙 SElinux 配ip的更多相关文章
- CentOS关闭防火墙&SELinux
须知: 防火墙配置文件:/etc/sysconfig/iptables 查看防火墙状态:service iptables status 关闭防火墙:service iptables stop 关闭ip ...
- CentOS 7 关闭防火墙
CentOS 7.0默认使用的是firewall作为防火墙 直接关闭防火墙 systemctl stop firewalld.service #停止firewall systemctl disable ...
- hadoop学习;安装jdk,workstation虚拟机v2v迁移;虚拟机之间和跨物理机之间ping网络通信;virtualbox的centos中关闭防火墙和检查服务启动
JDK 在Ubuntu下的安装 与 环境变量的配置 前期准备工作: 找到 JDK 和 配置TXT文件 并拷贝到桌面下 不是目录 而是文件拷贝到桌面下 以下的命令部分就直接复制粘贴就能够了 1.配 ...
- 利用CentOS系统IPtables防火墙添加网站IP白名单
参考博文: 利用CentOS系统IPtables防火墙添加360网站卫士节点IP白名单 centos6.5添加白名单如下: 在防火墙 配置文件中加入白名单 ip -A INPUT -s 183.13 ...
- CentOS虚拟机关闭防火墙
关闭防火墙 systemctl stop firewalld 关闭防火墙开机自启动 systemctl disable firewalld 关闭安全机制,将selinux设置为disabled vi ...
- centos 如何关闭防火墙?
1 查看防火墙状态: 命令: /etc/init.d/iptables status 如果是开着显示内容类是截图 2 临时关闭防火墙: 命令:/etc/init.d/iptables stop ...
- CentOS 7 关闭防火墙和SELinux
[修改机器名] # vi /etc/hostname [关SELinux] # vi /etc/selinux/config设置SELINUX=disabled [关防火墙] # systemctl ...
- CentOS 系统开启防火墙,屏蔽IP,解决DDOS攻击
刚才发现网站特别慢,然后看了一下服务器状态 CPU 负载100%. 然后看了下网络,发现一个IP一直在请求本服务器的 443 端口,就是本站. 然后在终端通过 iftop 命令(一个流量健康软件,如果 ...
- Linux CentOS 下关闭防火墙
永久关闭(重启后生效) 开启: chkconfig iptables on 关闭: chkconfig iptables off 临时关闭(重启后失效) 开启: service iptables st ...
- CentOS 8 关闭防火墙
SELINUX=disabled vim /etc/selinux/config systemctl disable firewalld.service
随机推荐
- MRS_下载相关问题汇总
解决问题如下: MRS下载编译时,更改生成文件是HEX文件还是BIN文件 关于MounRiver下载时如何选择配置部分擦除 关于MounRiver下载起始地址配置问题 MRS下载编译时,更改生成文件是 ...
- Blazor入门100天 : 身份验证和授权 (6) - 使用 FreeSql orm 管理ids数据
目录 建立默认带身份验证 Blazor 程序 角色/组件/特性/过程逻辑 DB 改 Sqlite 将自定义字段添加到用户表 脚手架拉取IDS文件,本地化资源 freesql 生成实体类,freesql ...
- Jenkins CLI命令行
Jenkins CLI命令行 jenkins不光可以UI操作还提供了命令行接口 位置 首页->系统管理->工具和动作->Jenkins 命令行接口 在这个界面下载一个jenkins- ...
- 洛谷p1423
1 #include<bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5 double n;//n:要游的距离 6 cin&g ...
- 本地python环境安装kylin项目依赖时报认证错误信息
问题描述:项目需要连接kylin数据库查询数据,本地安装kylin项目的依赖环境后报认证错误 python版本3.7 32位 pycharm版本 2022版 成功方法: 更换解释器选择无解释器,创建虚 ...
- .NET Core 项目启动时运行定时任务
1.任务需求 在每次服务启动时定时(如24小时)清理一次缓存文件 2.代码实现 1)新建文件清理类 .NET Core 提供了BackgroundService的抽象类,在 ExecuteAsync ...
- 基于Kali Linux的渗透测试工具-Discover脚本
简介 这篇文章主要介绍了基于Kali Linux的渗透测试工具-Discover脚本以及相关的经验技巧,文章约5629字,浏览量510,点赞数9,值得参考! 如果你正在使用Kali Linux,那么 ...
- STL中的智能指针(Smart Pointer)及其源码剖析: std::unique_ptr
STL中的智能指针(Smart Pointer)及其源码剖析: std::unique_ptr 和 std::auto_ptr一样,std::unique_ptr也是一种智能指针,它也是通过指针的方式 ...
- Vue框架:9,Vue3的用法,setup函数,ref和reactive,计算属性和监听属性,生命周期,toRefs,script setup的作用和lang,Vue后台管理模板
目录 前端开发之Vue框架 一.Vue3 1.Vue3创建项目 2.setup函数 3.ref和reactive 4.计算属性和监听属性 5.生命周期 6.toRefs 7.script setup的 ...
- C#/JS 压缩到指定大小的图片 (内存不足问题修改)
//因为浏览器安全问题,无法获取上传图片地址,需要先存一遍然后再获取地址作参数上传 var des = CompressImage(@"C:\Users\PC\Pictures\测试\165 ...