分享好友 系统运维首页 频道列表

centos7.2 开启防火墙

Centos  2023-02-10 03:020

开启防火墙

当我们修改了某些配置之后(尤其是配置文件的修改),firewall并不会立即生效。可以通过两种方式来激活最新配置 systemctl restart firewalld 和 firewall-cmd --reload 两种方式,前一种是重启firewalld服务,建议使用后一种“重载配置文件”。重载配置文件之后不会断掉正在连接的tcp会话,而重启服务则会断开tcp会话。

 

在CentOS7.0中默认使用firewall代替了iptables service。虽然继续保留了iptables命令,但已经仅是名称相同而已。除非手动删除firewall,再安装iptables,否则不能继续使用以前的iptables配置方法。以下介绍的是firewall配置方法: 
#cd /usr/lib/firewalld/services   //该目录中存放的是定义好的网络服务和端口参数,只用于参考,不能修改。
这个目录中只定义了一部分通用网络服务。在该目录中没有定义的网络服务,也不必再增加相关xml定义,后续通过管理命令可以直接增加。 
#cd /etc/firewalld/services/   //从上面目录中将需要使用的服务的xml文件拷至 这个目录中,如果端口有变化则可以修改文件中的数值。

在 CentOS 7
暫時開放 ftp 服務
# firewall-cmd --add-service=ftp

永久開放 ftp 服務
# firewall-cmd --add-service=ftp --permanent
永久關閉
# firewall-cmd --remove-service=ftp --permanent
success

讓設定生效
# systemctl restart firewalld

檢視設定是否生效
# iptables -L -n | grep 21
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:21 ctstate NEW
檢查防火牆狀態
# firewall-cmd --state
running

# systemctl stop firewalld
# firewall-cmd --state
not running


# firewall-cmd --list-all
public (default)
  interfaces:
  sources:
  services: dhcpv6-client ftp ssh
  ports:
  masquerade: no
  forward-ports:
  icmp-blocks:
  rich rules:

在 FirewallD 的服務名稱
# firewall-cmd --get-service
amanda-client bacula bacula-client dhcp dhcpv6 dhcpv6-client dns ftp high-availability http https imaps ipp ipp-client ipsec kerberos kpasswd ldap ldaps libvirt libvirt-tls mdns mountd ms-wbt mySQL nfs ntp open*** pmcd pmproxy pmwebapi pmwebapis pop3s PostgreSQL proxy-dhcp radius rpc-bind samba samba-client smtp ssh telnet tftp tftp-client transmission-client vnc-server wbem-https

查詢服務的啟用狀態
# firewall-cmd --query-service ftp
yes
# firewall-cmd --query-service ssh
yes
# firewall-cmd --query-service samba
no
# firewall-cmd --query-service http
no

自行加入要開放的 Port
# firewall-cmd --add-port=3128/tcp
# firewall-cmd --list-all
public (default)
  interfaces:
  sources:
  services: dhcpv6-client ftp ssh
  ports: 3128/tcp
  masquerade: no
  forward-ports:
  icmp-blocks:
  rich rules:

查看更多关于【Centos】的文章

展开全文
相关推荐
反对 0
举报 0
评论 0
图文资讯
热门推荐
优选好物
更多热点专题
更多推荐文章
centos6下同时安装python2和python3
#build-essential compile packagesyum groupinstall "Development Tools"yum install openssl-develyum install zlib-develyum install make gcc gcc-c++ kernel-develhttp://unix.stackexchange.com/questions/291737/zipimport-zipimporterror-cant-decomp

0评论2023-02-10677

CentOS下查看文件和文件夹大小 linux查看文件夹大小
当磁盘大小超过标准时会有报警提示,这时如果掌握df和du命令是非常明智的选择。  df可以查看一级文件夹大小、使用比例、档案系统及其挂入点,但对文件却无能为力。当磁盘大小超过标准时会有报警提示,这时如果掌握df和du命令是非常明智的选择。  df可以查

0评论2023-02-10731

centos7 rc.local脚本执行不成功
腾讯云 centos7   配置文件/etc/rc.local的内容如下:#!/bin/sh#secu_agent init monitor, install at Thu Aug 3 11:19:41 CST 2017/usr/local/sa/agent/init_check.sh/dev/null 21/usr/sbin/ntpdate ntpupdate.tencentyun.com /dev/null 21 /usr/local/qclo

0评论2023-02-10442

如何在centos7启动时自动挂载硬盘
在/etc/rc.local中加入如下的语句,这样就不用每次重启后手动挂载了(后面挂载的目录根据自己的需求而定):mount  /dev/sdb1 /usr/sharedfiles/sdbmount  /dev/sdc1 /usr/sharedfiles/sdcmount  /dev/sdb1 /root/sdbmount  /dev/sdc1 /root/sdc注意:可以

0评论2023-02-10535

CentOS7 安装 Python3.8后 pip 安装报错
[root@localhost Python-3.8.0]# pip install bs4Collecting bs4Using cached https://files.pythonhosted.org/packages/10/ed/7e8b97591f6f456174139ec089c769f89a94a1a4025fe967691de971f314/bs4-0.0.1.tar.gzERROR: Command errored out with exit status

0评论2023-02-10961

[转]How to install PHP 5.3 on CentOS
在DIAHosting买了一个VPS,自带PHP5.1.6.我想安装wordpress,但是由于版本比较新,要求PHP也要是5.2以上的,于是我就安装了PHP5.3.20--------------------------------------------------------------------------------------------------------------------

0评论2023-02-10997

外部访问docker内部容器centos的http服务
1.创建容器docker run -d -it -h dd -p 5000 --name bbbbb centosdd 是用户名 --name 后面是容器名字2.在我们开始安装Nginx及其他所需软件之前先安装一些前提软yum install python-setuptools yum -y install epel-release yum install python-pip pip instal

0评论2023-02-10480

Centos7安装yum命令 centos8如何安装yum
步骤如下http://mirrors.163.com/centos/7/os/x86_64/Packages/到上面这个网站去下载如下RPM包(为版本号,根据最新的自己替换即可)python-iniparse-.noarch.rpmyum-metadata-parser-.x86_64.rpmyum-.centos.noarch.rpmyum-plugin-fastestmirror-*.noarch.rp

0评论2023-02-10760

CentOS 7 - 安装Python 3
Enable Software Collections (SCL)Software Collections, also known as SCL is a community project that allows you to build, install, and use multiple versions of software on the same system, without affecting system default packages. By enabl

0评论2023-02-10592

centos清除历史命令
1、rm -f /root/.bash_profile  历史命令记录在此文件2、history -c   清除缓存会话退出后重新连接输入history可以看到历史命令清空了。两条命令的顺序不能乱

0评论2023-02-09473

更多推荐