linux 防火墙的常用方法

关闭SELinux的方法

修改/etc/selinux/config文件中的SELINUX=”” 为 disabled ,然后重启。
如果不想重启系统,使用命令setenforce 0
注:
setenforce 1 设置SELinux 成为enforcing模式
setenforce 0 设置SELinux 成为permissive模式
在lilo或者grub的启动参数中增加:selinux=0,也可以关闭selinux

—————————————————————

查看selinux状态:
/usr/bin/setstatus -v
如下:
SELinux status: enabled
SELinuxfs mount: /selinux
Current mode: permissive
Mode from config file: enforcing
Policy version: 21
Policy from config file: targeted

getenforce/setenforce查看和设置SELinux的当前工作模式

firewall防火墙操作

如果你的系统上没有安装使用命令安装
yum install firewalld //安装firewalld 防火墙
开启服务
systemctl start firewalld.service
关闭防火墙
systemctl stop firewalld.service
开机自动启动
systemctl enable firewalld.service
关闭开机制动启动
systemctl disable firewalld.service
查看状态
systemctl status firewalld

用户可以通过修改配置文件的方式添加端口,也可以通过命令的方式添加端口,注意,修改的内容会在/etc/firewalld/ 目录下的配置文件中还体现。

3.1、命令的方式添加端口
firewall-cmd –permanent –add-port=9527/tcp

参数介绍:
1、firewall-cmd:是Linux提供的操作firewall的一个工具;
2、–permanent:表示设置为持久;
3、–add-port:标识添加的端口;

另外,firewall中有Zone的概念,可以将具体的端口制定到具体的zone配置文件中。

例如:添加8010端口
firewall-cmd –zone=public –permanent –add-port=8010/tcp

–zone=public:指定的zone为public;

iptable防火墙操作

查询防火墙状态 : [root@localhost ~]# service iptables status
停止防火墙 : [root@localhost ~]# service iptables stop
启动防火墙 : [root@localhost ~]# service iptables start
重启防火墙 : [root@localhost ~]# service iptables restart
永久关闭防火墙 : [root@localhost ~]# chkconfig iptables off
永久关闭后启用 : [root@localhost ~]# chkconfig iptables on

1.查看当前所有的iptables配置

iptables -L -n

2.添加允许INPUT访问规则,以下时常见服务的端口设置,如果需要拒绝访问,则将ACCEPT改为DROP即可

#SSH
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
#HTTP
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 8080 -j ACCEPT
#HTTPS
iptables -A INPUT -p tcp --dport 443 -j ACCEPT
#POP3
iptables -A INPUT -p tcp --dport 110 -j ACCEPT
#SMTP
iptables -A INPUT -p tcp --dport 25 -j ACCEPT
#FTP
iptables -A INPUT -p tcp --dport 21 -j ACCEPT
iptables -A INPUT -p tcp --dport 20 -j ACCEPT
#DNS
iptables -A INPUT -p tcp --dport 53 -j ACCEPT

3.添加使用IP限制INPUT访问规则,这里拿SSH为例,192.168.0.100为允许的IP

#DELETE
iptables -D INPUT -p tcp --dport 22 -j ACCEPT
#ADD
iptables -A INPUT -s 192.168.0.100 -p tcp --dport 22 -j ACCEPT

4.保存iptables的设置,修改完规则后记得保存

 /etc/rc.d/init.d/iptables save

5 .打开iptables的配置文件:

vi /etc/sysconfig/iptables

通过/etc/init.d/iptables status命令查询是否有打开80端口,如果没有可通过两种方式处理:

6.修改vi /etc/sysconfig/iptables命令添加使防火墙开放80端口

-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT

切换到iptables首先应该关掉默认的firewalld,然后安装iptables服务。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值